mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
[SiteInfo] Improved setting height of section widget.
This commit is contained in:
parent
9a99509faf
commit
bea5f72ad7
|
@ -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 \
|
||||
|
|
62
src/lib/tools/horizontallistwidget.cpp
Normal file
62
src/lib/tools/horizontallistwidget.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "horizontallistwidget.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
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)
|
||||
}
|
37
src/lib/tools/horizontallistwidget.h
Normal file
37
src/lib/tools/horizontallistwidget.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef HORIZONTALLISTWIDGET_H
|
||||
#define HORIZONTALLISTWIDGET_H
|
||||
|
||||
#include <QListWidget>
|
||||
|
||||
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
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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<QWidget*>(parent());
|
||||
if (p && m_updateParentHeight) {
|
||||
p->setFixedHeight(m_itemHeight);
|
||||
}
|
||||
}
|
||||
|
||||
int width = 2 * m_padding + option.fontMetrics.width(index.data(Qt::DisplayRole).toString());
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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;
|
||||
|
|
|
@ -15,28 +15,10 @@
|
|||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QListWidget" name="listWidget">
|
||||
<widget class="HorizontalListWidget" name="listWidget">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="movement">
|
||||
<enum>QListView::Static</enum>
|
||||
</property>
|
||||
<property name="resizeMode">
|
||||
<enum>QListView::Adjust</enum>
|
||||
</property>
|
||||
<property name="viewMode">
|
||||
<enum>QListView::IconMode</enum>
|
||||
</property>
|
||||
<property name="selectionRectVisible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>General</string>
|
||||
|
@ -489,6 +471,11 @@
|
|||
<extends>QLabel</extends>
|
||||
<header>squeezelabelv2.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>HorizontalListWidget</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>horizontallistwidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
|
Loading…
Reference in New Issue
Block a user