diff --git a/src/lib/lib.pro b/src/lib/lib.pro index deabae9b0..56e5ab688 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -213,7 +213,8 @@ SOURCES += \ autofill/autofillicon.cpp \ autofill/autofillwidget.cpp \ tools/menubar.cpp \ - navigation/navigationcontainer.cpp + navigation/navigationcontainer.cpp \ + tools/horizontallistwidget.cpp HEADERS += \ webview/tabpreview.h \ @@ -381,7 +382,8 @@ HEADERS += \ autofill/autofillicon.h \ autofill/autofillwidget.h \ tools/menubar.h \ - navigation/navigationcontainer.h + navigation/navigationcontainer.h \ + tools/horizontallistwidget.h FORMS += \ preferences/autofillmanager.ui \ diff --git a/src/lib/tools/horizontallistwidget.cpp b/src/lib/tools/horizontallistwidget.cpp new file mode 100644 index 000000000..6aafae4f6 --- /dev/null +++ b/src/lib/tools/horizontallistwidget.cpp @@ -0,0 +1,62 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2013 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#include "horizontallistwidget.h" + +#include + +HorizontalListWidget::HorizontalListWidget(QWidget* parent) + : QListWidget(parent) + , m_mouseDown(false) +{ + setFocusPolicy(Qt::NoFocus); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setMovement(QListView::Static); + setResizeMode(QListView::Adjust); + setViewMode(QListView::IconMode); + setSelectionRectVisible(false); +} + +void HorizontalListWidget::mousePressEvent(QMouseEvent* event) +{ + m_mouseDown = true; + + QListWidget::mousePressEvent(event); +} + +void HorizontalListWidget::mouseMoveEvent(QMouseEvent* event) +{ + if (!itemAt(event->pos())) { + // Don't unselect item so it ends up with no item selected + return; + } + + QListWidget::mouseMoveEvent(event); +} + +void HorizontalListWidget::mouseReleaseEvent(QMouseEvent* event) +{ + m_mouseDown = false; + + QListWidget::mouseReleaseEvent(event); +} + +void HorizontalListWidget::wheelEvent(QWheelEvent* event) +{ + // As this is just Horizontal ListWidget, disable wheel scrolling completely + Q_UNUSED(event) +} diff --git a/src/lib/tools/horizontallistwidget.h b/src/lib/tools/horizontallistwidget.h new file mode 100644 index 000000000..05ba64522 --- /dev/null +++ b/src/lib/tools/horizontallistwidget.h @@ -0,0 +1,37 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2013 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#ifndef HORIZONTALLISTWIDGET_H +#define HORIZONTALLISTWIDGET_H + +#include + +class HorizontalListWidget : public QListWidget +{ +public: + explicit HorizontalListWidget(QWidget* parent = 0); + +private: + void mousePressEvent(QMouseEvent* event); + void mouseMoveEvent(QMouseEvent* event); + void mouseReleaseEvent(QMouseEvent* event); + void wheelEvent(QWheelEvent* event); + + bool m_mouseDown; +}; + +#endif // HORIZONTALLISTWIDGET_H diff --git a/src/lib/tools/listitemdelegate.cpp b/src/lib/tools/listitemdelegate.cpp index 80c069532..c3be8df66 100644 --- a/src/lib/tools/listitemdelegate.cpp +++ b/src/lib/tools/listitemdelegate.cpp @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2012 David Rosca +* Copyright (C) 2010-2013 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,11 +23,17 @@ ListItemDelegate::ListItemDelegate(int iconSize, QWidget* parent) : QStyledItemDelegate(parent) , m_iconSize(iconSize) + , m_updateParentHeight(false) , m_itemHeight(0) , m_padding(0) { } +void ListItemDelegate::setUpdateParentHeight(bool update) +{ + m_updateParentHeight = update; +} + int ListItemDelegate::itemHeight() const { return m_itemHeight; @@ -81,6 +87,12 @@ QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMode m_padding = padding > 5 ? padding : 5; m_itemHeight = 3 * m_padding + opt.fontMetrics.height() + m_iconSize; + + // Update height of parent widget + QWidget* p = qobject_cast(parent()); + if (p && m_updateParentHeight) { + p->setFixedHeight(m_itemHeight); + } } int width = 2 * m_padding + option.fontMetrics.width(index.data(Qt::DisplayRole).toString()); diff --git a/src/lib/tools/listitemdelegate.h b/src/lib/tools/listitemdelegate.h index 7add3305f..e3a777010 100644 --- a/src/lib/tools/listitemdelegate.h +++ b/src/lib/tools/listitemdelegate.h @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2012 David Rosca +* Copyright (C) 2010-2013 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ class QT_QUPZILLA_EXPORT ListItemDelegate : public QStyledItemDelegate public: explicit ListItemDelegate(int iconSize, QWidget* parent); + void setUpdateParentHeight(bool update); int itemHeight() const; void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; @@ -34,6 +35,8 @@ public: private: int m_iconSize; + bool m_updateParentHeight; + mutable int m_itemHeight; mutable int m_padding; }; diff --git a/src/lib/webview/siteinfo.cpp b/src/lib/webview/siteinfo.cpp index 3a1eca1e7..c9210aecd 100644 --- a/src/lib/webview/siteinfo.cpp +++ b/src/lib/webview/siteinfo.cpp @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2012 David Rosca +* Copyright (C) 2010-2013 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -51,13 +51,13 @@ SiteInfo::SiteInfo(WebView* view, QWidget* parent) , ui(new Ui::SiteInfo) , m_certWidget(0) , m_view(view) - , m_delegate(0) { setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(this); - m_delegate = new ListItemDelegate(24, ui->listWidget); - ui->listWidget->setItemDelegate(m_delegate); + ListItemDelegate* delegate = new ListItemDelegate(24, ui->listWidget); + delegate->setUpdateParentHeight(true); + ui->listWidget->setItemDelegate(delegate); ui->listWidget->item(0)->setIcon(QIcon::fromTheme("document-properties", QIcon(":/icons/preferences/document-properties.png"))); ui->listWidget->item(1)->setIcon(QIcon::fromTheme("applications-graphics", QIcon(":/icons/preferences/applications-graphics.png"))); @@ -175,8 +175,6 @@ SiteInfo::SiteInfo(WebView* view, QWidget* parent) ui->treeImages->sortByColumn(-1); ui->treeTags->sortByColumn(-1); - - QTimer::singleShot(0, this, SLOT(heightChange())); } void SiteInfo::imagesCustomContextMenuRequested(const QPoint &p) @@ -247,13 +245,6 @@ void SiteInfo::downloadImage() } } -void SiteInfo::heightChange() -{ - if (m_delegate) { - ui->listWidget->setFixedHeight(m_delegate->itemHeight()); - } -} - void SiteInfo::showImagePreview(QTreeWidgetItem* item) { if (!item) { diff --git a/src/lib/webview/siteinfo.h b/src/lib/webview/siteinfo.h index a55fea0a2..2d18531a1 100644 --- a/src/lib/webview/siteinfo.h +++ b/src/lib/webview/siteinfo.h @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2012 David Rosca +* Copyright (C) 2010-2013 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -53,7 +53,6 @@ private slots: void imagesCustomContextMenuRequested(const QPoint &p); void copyActionData(); void downloadImage(); - void heightChange(); private: Ui::SiteInfo* ui; diff --git a/src/lib/webview/siteinfo.ui b/src/lib/webview/siteinfo.ui index 4f55dcc25..77ac70d85 100644 --- a/src/lib/webview/siteinfo.ui +++ b/src/lib/webview/siteinfo.ui @@ -15,28 +15,10 @@ - + Qt::NoFocus - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QListView::Static - - - QListView::Adjust - - - QListView::IconMode - - - false - General @@ -489,6 +471,11 @@ QLabel
squeezelabelv2.h
+ + HorizontalListWidget + QListWidget +
horizontallistwidget.h
+