mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Fixed rendering issues in ListWidget in SiteInfo
It should now be rendered well with all possible font sizes. Closes #663
This commit is contained in:
parent
8cca4437f1
commit
f27137f8ae
@ -194,7 +194,8 @@ SOURCES += \
|
|||||||
network/schemehandlers/qupzillaschemehandler.cpp \
|
network/schemehandlers/qupzillaschemehandler.cpp \
|
||||||
network/schemehandlers/adblockschemehandler.cpp \
|
network/schemehandlers/adblockschemehandler.cpp \
|
||||||
network/schemehandlers/fileschemehandler.cpp \
|
network/schemehandlers/fileschemehandler.cpp \
|
||||||
other/registerqappassociation.cpp
|
other/registerqappassociation.cpp \
|
||||||
|
tools/listitemdelegate.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
webview/tabpreview.h \
|
webview/tabpreview.h \
|
||||||
@ -351,7 +352,8 @@ HEADERS += \
|
|||||||
network/schemehandlers/qupzillaschemehandler.h \
|
network/schemehandlers/qupzillaschemehandler.h \
|
||||||
network/schemehandlers/adblockschemehandler.h \
|
network/schemehandlers/adblockschemehandler.h \
|
||||||
network/schemehandlers/fileschemehandler.h \
|
network/schemehandlers/fileschemehandler.h \
|
||||||
other/registerqappassociation.h
|
other/registerqappassociation.h \
|
||||||
|
tools/listitemdelegate.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
preferences/autofillmanager.ui \
|
preferences/autofillmanager.ui \
|
||||||
|
@ -27,7 +27,7 @@ class QListWidget;
|
|||||||
class QT_QUPZILLA_EXPORT PluginListDelegate : public QStyledItemDelegate
|
class QT_QUPZILLA_EXPORT PluginListDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PluginListDelegate(QListWidget* parent);
|
explicit PluginListDelegate(QListWidget* parent);
|
||||||
|
|
||||||
void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
88
src/lib/tools/listitemdelegate.cpp
Normal file
88
src/lib/tools/listitemdelegate.cpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/* ============================================================
|
||||||
|
* QupZilla - WebKit based browser
|
||||||
|
* Copyright (C) 2010-2012 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 "listitemdelegate.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
ListItemDelegate::ListItemDelegate(int iconSize, QWidget* parent)
|
||||||
|
: QStyledItemDelegate(parent)
|
||||||
|
, m_iconSize(iconSize)
|
||||||
|
, m_itemHeight(0)
|
||||||
|
, m_padding(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int ListItemDelegate::itemHeight() const
|
||||||
|
{
|
||||||
|
return m_itemHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ListItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
QStyleOptionViewItemV4 opt = option;
|
||||||
|
initStyleOption(&opt, index);
|
||||||
|
|
||||||
|
const QWidget* w = opt.widget;
|
||||||
|
const QStyle* style = w ? w->style() : QApplication::style();
|
||||||
|
const Qt::LayoutDirection direction = w ? w->layoutDirection() : QApplication::layoutDirection();
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
const QPalette::ColorRole colorRole = QPalette::Text;
|
||||||
|
#else
|
||||||
|
const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int topPosition = opt.rect.top() + m_padding;
|
||||||
|
|
||||||
|
// Draw background
|
||||||
|
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w);
|
||||||
|
|
||||||
|
// Draw icon
|
||||||
|
QRect iconRect(opt.rect.left() + (opt.rect.width() - m_iconSize) / 2, topPosition, m_iconSize, m_iconSize);
|
||||||
|
QRect visualIconRect = style->visualRect(direction, opt.rect, iconRect);
|
||||||
|
QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(m_iconSize);
|
||||||
|
painter->drawPixmap(visualIconRect, pixmap);
|
||||||
|
topPosition += m_iconSize + m_padding;
|
||||||
|
|
||||||
|
// Draw title
|
||||||
|
const QString &title = index.data(Qt::DisplayRole).toString();
|
||||||
|
const int leftTitleEdge = opt.rect.left() + m_padding;
|
||||||
|
QRect titleRect(leftTitleEdge, topPosition, opt.rect.width() - 2 * m_padding, opt.fontMetrics.height());
|
||||||
|
QRect visualTitleRect = style->visualRect(direction, opt.rect, titleRect);
|
||||||
|
style->drawItemText(painter, visualTitleRect, Qt::AlignCenter, opt.palette, true, title, colorRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (!m_itemHeight) {
|
||||||
|
QStyleOptionViewItemV4 opt(option);
|
||||||
|
initStyleOption(&opt, index);
|
||||||
|
|
||||||
|
const QWidget* w = opt.widget;
|
||||||
|
const QStyle* style = w ? w->style() : QApplication::style();
|
||||||
|
const int padding = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0) + 1;
|
||||||
|
|
||||||
|
m_padding = padding > 5 ? padding : 5;
|
||||||
|
|
||||||
|
m_itemHeight = 3 * m_padding + opt.fontMetrics.height() + m_iconSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
int width = 2 * m_padding + option.fontMetrics.width(index.data(Qt::DisplayRole).toString());
|
||||||
|
return QSize(width > (m_iconSize + 2 * m_padding) ? width : m_iconSize + 2 * m_padding, m_itemHeight);
|
||||||
|
}
|
41
src/lib/tools/listitemdelegate.h
Normal file
41
src/lib/tools/listitemdelegate.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/* ============================================================
|
||||||
|
* QupZilla - WebKit based browser
|
||||||
|
* Copyright (C) 2010-2012 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 LISTITEMDELEGATE_H
|
||||||
|
#define LISTITEMDELEGATE_H
|
||||||
|
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
#include "qz_namespace.h"
|
||||||
|
|
||||||
|
class QT_QUPZILLA_EXPORT ListItemDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ListItemDelegate(int iconSize, QWidget* parent);
|
||||||
|
|
||||||
|
int itemHeight() const;
|
||||||
|
|
||||||
|
void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_iconSize;
|
||||||
|
mutable int m_itemHeight;
|
||||||
|
mutable int m_padding;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LISTITEMDELEGATE_H
|
@ -17,6 +17,7 @@
|
|||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "siteinfo.h"
|
#include "siteinfo.h"
|
||||||
#include "ui_siteinfo.h"
|
#include "ui_siteinfo.h"
|
||||||
|
#include "listitemdelegate.h"
|
||||||
#include "webview.h"
|
#include "webview.h"
|
||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
@ -53,12 +54,17 @@ SiteInfo::SiteInfo(WebView* view, QWidget* parent)
|
|||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
ListItemDelegate* delegate = new ListItemDelegate(24, ui->listWidget);
|
||||||
|
ui->listWidget->setItemDelegate(delegate);
|
||||||
|
|
||||||
ui->listWidget->item(0)->setIcon(QIcon::fromTheme("document-properties", QIcon(":/icons/preferences/document-properties.png")));
|
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")));
|
ui->listWidget->item(1)->setIcon(QIcon::fromTheme("applications-graphics", QIcon(":/icons/preferences/applications-graphics.png")));
|
||||||
ui->listWidget->item(2)->setIcon(QIcon::fromTheme("text-x-sql", QIcon(":/icons/preferences/text-x-sql.png")));
|
ui->listWidget->item(2)->setIcon(QIcon::fromTheme("text-x-sql", QIcon(":/icons/preferences/text-x-sql.png")));
|
||||||
ui->listWidget->item(3)->setIcon(QIcon::fromTheme("dialog-password", QIcon(":/icons/preferences/dialog-password.png")));
|
ui->listWidget->item(3)->setIcon(QIcon::fromTheme("dialog-password", QIcon(":/icons/preferences/dialog-password.png")));
|
||||||
ui->listWidget->item(0)->setSelected(true);
|
ui->listWidget->item(0)->setSelected(true);
|
||||||
|
|
||||||
|
ui->listWidget->setFixedHeight(delegate->itemHeight());
|
||||||
|
|
||||||
WebPage* webPage = view->page();
|
WebPage* webPage = view->page();
|
||||||
QWebFrame* frame = view->page()->mainFrame();
|
QWebFrame* frame = view->page()->mainFrame();
|
||||||
QString title = view->title();
|
QString title = view->title();
|
||||||
|
@ -16,18 +16,6 @@
|
|||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QListWidget" name="listWidget">
|
<widget class="QListWidget" name="listWidget">
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>16777215</width>
|
|
||||||
<height>53</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
<enum>Qt::NoFocus</enum>
|
<enum>Qt::NoFocus</enum>
|
||||||
</property>
|
</property>
|
||||||
@ -40,8 +28,8 @@
|
|||||||
<property name="movement">
|
<property name="movement">
|
||||||
<enum>QListView::Static</enum>
|
<enum>QListView::Static</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="flow">
|
<property name="resizeMode">
|
||||||
<enum>QListView::LeftToRight</enum>
|
<enum>QListView::Adjust</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="viewMode">
|
<property name="viewMode">
|
||||||
<enum>QListView::IconMode</enum>
|
<enum>QListView::IconMode</enum>
|
||||||
|
Loading…
Reference in New Issue
Block a user