mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
[Bookmarks] Improved drawing of separator
Instead of QFrame::Line, use actual ToolbarSeparator. Also add separator into toolbar for default bookmarks.json
This commit is contained in:
parent
2105b48ca4
commit
d4d31d2daa
@ -20,7 +20,7 @@
|
||||
#include "bookmarksmodel.h"
|
||||
#include "bookmarkitem.h"
|
||||
|
||||
#include <QStyleOptionFrameV3>
|
||||
#include <QStyleOption>
|
||||
#include <QApplication>
|
||||
#include <QStyle>
|
||||
|
||||
@ -35,9 +35,8 @@ void BookmarksItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
if (index.data(BookmarksModel::TypeRole).toInt() == BookmarkItem::Separator) {
|
||||
QStyleOptionFrameV3 opt;
|
||||
opt.frameShape = QFrame::HLine;
|
||||
opt.rect = option.rect;
|
||||
QStyleOption opt = option;
|
||||
opt.state &= ~QStyle::State_Horizontal;
|
||||
|
||||
// We need to fake continuous line over 2 columns
|
||||
if (m_tree->viewType() == BookmarksTreeView::BookmarksManagerViewType) {
|
||||
@ -50,6 +49,6 @@ void BookmarksItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem
|
||||
}
|
||||
}
|
||||
|
||||
QApplication::style()->drawControl(QStyle::CE_ShapedFrame, &opt, painter);
|
||||
QApplication::style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &opt, painter);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ void BookmarksToolbar::contextMenuRequested(const QPoint &pos)
|
||||
connect(actNewWindow, SIGNAL(triggered()), this, SLOT(openBookmarkInNewWindow()));
|
||||
connect(actDelete, SIGNAL(triggered()), this, SLOT(deleteBookmark()));
|
||||
|
||||
actDelete->setEnabled(m_clickedBookmark && (m_clickedBookmark->isUrl() || m_clickedBookmark->isFolder()));
|
||||
actDelete->setEnabled(m_clickedBookmark && m_bookmarks->canBeModified(m_clickedBookmark));
|
||||
actNewTab->setEnabled(m_clickedBookmark && m_clickedBookmark->isUrl());
|
||||
actNewWindow->setEnabled(m_clickedBookmark && m_clickedBookmark->isUrl());
|
||||
|
||||
@ -158,26 +158,10 @@ void BookmarksToolbar::addItem(BookmarkItem* item)
|
||||
{
|
||||
Q_ASSERT(item);
|
||||
|
||||
switch (item->type()) {
|
||||
case BookmarkItem::Folder:
|
||||
case BookmarkItem::Url: {
|
||||
BookmarksToolbarButton* button = new BookmarksToolbarButton(item, this);
|
||||
button->setMainWindow(m_window);
|
||||
button->setShowOnlyIcon(m_bookmarks->showOnlyIconsInToolbar());
|
||||
m_layout->addWidget(button);
|
||||
break;
|
||||
}
|
||||
|
||||
case BookmarkItem::Separator: {
|
||||
QFrame* separator = new QFrame(this);
|
||||
separator->setFrameShape(QFrame::VLine);
|
||||
m_layout->addWidget(separator);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BookmarksToolbarButton* BookmarksToolbar::buttonAt(const QPoint &pos)
|
||||
|
@ -27,6 +27,10 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QStyleOptionButton>
|
||||
|
||||
#define MAX_WIDTH 150
|
||||
#define SEPARATOR_WIDTH 8
|
||||
#define PADDING 5
|
||||
|
||||
BookmarksToolbarButton::BookmarksToolbarButton(BookmarkItem* bookmark, QWidget* parent)
|
||||
: QPushButton(parent)
|
||||
, m_bookmark(bookmark)
|
||||
@ -34,7 +38,6 @@ BookmarksToolbarButton::BookmarksToolbarButton(BookmarkItem* bookmark, QWidget*
|
||||
, m_buttons(Qt::NoButton)
|
||||
, m_modifiers(Qt::NoModifier)
|
||||
, m_showOnlyIcon(false)
|
||||
, m_padding(5)
|
||||
{
|
||||
init();
|
||||
}
|
||||
@ -62,29 +65,33 @@ void BookmarksToolbarButton::setShowOnlyIcon(bool show)
|
||||
|
||||
QSize BookmarksToolbarButton::sizeHint() const
|
||||
{
|
||||
const int maxWidth = 150;
|
||||
int width = PADDING * 2 + 16;
|
||||
|
||||
int width = m_padding * 2 + 16;
|
||||
|
||||
if (!m_showOnlyIcon) {
|
||||
width += m_padding * 2 + fontMetrics().width(m_bookmark->title());
|
||||
if (m_bookmark->isSeparator()) {
|
||||
width = SEPARATOR_WIDTH;
|
||||
}
|
||||
else if (!m_showOnlyIcon) {
|
||||
width += PADDING * 2 + fontMetrics().width(m_bookmark->title());
|
||||
|
||||
if (menu()) {
|
||||
width += m_padding + 8;
|
||||
width += PADDING + 8;
|
||||
}
|
||||
}
|
||||
|
||||
QSize s = QPushButton::sizeHint();
|
||||
s.setWidth(qMin(width, maxWidth));
|
||||
s.setWidth(qMin(width, MAX_WIDTH));
|
||||
return s;
|
||||
}
|
||||
|
||||
QSize BookmarksToolbarButton::minimumSizeHint() const
|
||||
{
|
||||
int width = m_padding * 2 + 16;
|
||||
int width = PADDING * 2 + 16;
|
||||
|
||||
if (!m_showOnlyIcon && menu()) {
|
||||
width += m_padding + 8;
|
||||
if (m_bookmark->isSeparator()) {
|
||||
width = SEPARATOR_WIDTH;
|
||||
}
|
||||
else if (!m_showOnlyIcon && menu()) {
|
||||
width += PADDING + 8;
|
||||
}
|
||||
|
||||
QSize s = QPushButton::minimumSizeHint();
|
||||
@ -184,7 +191,6 @@ void BookmarksToolbarButton::openBookmarkInNewWindow(BookmarkItem* item)
|
||||
void BookmarksToolbarButton::init()
|
||||
{
|
||||
Q_ASSERT(m_bookmark);
|
||||
Q_ASSERT(m_bookmark->type() == BookmarkItem::Url || m_bookmark->type() == BookmarkItem::Folder);
|
||||
|
||||
setFlat(true);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
@ -262,30 +268,38 @@ void BookmarksToolbarButton::paintEvent(QPaintEvent* event)
|
||||
Q_UNUSED(event)
|
||||
|
||||
QPainter p(this);
|
||||
QStyleOptionButton opt;
|
||||
initStyleOption(&opt);
|
||||
QStyleOptionButton option;
|
||||
initStyleOption(&option);
|
||||
|
||||
// Just draw separator
|
||||
if (m_bookmark->isSeparator()) {
|
||||
QStyleOption opt = option;
|
||||
opt.state |= QStyle::State_Horizontal;
|
||||
style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &opt, &p);
|
||||
return;
|
||||
}
|
||||
|
||||
// This ensures correct rendering of Down state with Oxygen
|
||||
if (isDown()) {
|
||||
opt.state &= ~QStyle::State_MouseOver;
|
||||
option.state &= ~QStyle::State_MouseOver;
|
||||
}
|
||||
|
||||
// Draw button base
|
||||
style()->drawControl(QStyle::CE_PushButtonBevel, &opt, &p, this);
|
||||
style()->drawControl(QStyle::CE_PushButtonBevel, &option, &p, this);
|
||||
|
||||
const int height = opt.rect.height();
|
||||
const int center = height / 2 + opt.rect.top();
|
||||
const int height = option.rect.height();
|
||||
const int center = height / 2 + option.rect.top();
|
||||
|
||||
const int iconSize = 16;
|
||||
const int iconYPos = center - iconSize / 2;
|
||||
|
||||
int leftPosition = m_padding;
|
||||
int rightPosition = opt.rect.right() - m_padding;
|
||||
int leftPosition = PADDING;
|
||||
int rightPosition = option.rect.right() - PADDING;
|
||||
|
||||
// Draw icon
|
||||
QRect iconRect(leftPosition, iconYPos, iconSize, iconSize);
|
||||
p.drawPixmap(iconRect, m_bookmark->icon().pixmap(iconSize));
|
||||
leftPosition = iconRect.right() + m_padding;
|
||||
leftPosition = iconRect.right() + PADDING;
|
||||
|
||||
// Draw menu arrow
|
||||
if (!m_showOnlyIcon && menu()) {
|
||||
@ -295,7 +309,7 @@ void BookmarksToolbarButton::paintEvent(QPaintEvent* event)
|
||||
opt.rect = QRect(rightPosition - 8, center - arrowSize / 2, arrowSize, arrowSize);
|
||||
opt.state &= QStyle::State_MouseOver;
|
||||
style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &opt, &p, this);
|
||||
rightPosition = opt.rect.left() - m_padding;
|
||||
rightPosition = opt.rect.left() - PADDING;
|
||||
}
|
||||
|
||||
// Draw text
|
||||
@ -304,6 +318,6 @@ void BookmarksToolbarButton::paintEvent(QPaintEvent* event)
|
||||
const int textYPos = center - fontMetrics().height() / 2;
|
||||
const QString txt = fontMetrics().elidedText(m_bookmark->title(), Qt::ElideRight, textWidth);
|
||||
QRect textRect(leftPosition, textYPos, textWidth, fontMetrics().height());
|
||||
style()->drawItemText(&p, textRect, Qt::TextSingleLine | Qt::AlignCenter, opt.palette, true, txt);
|
||||
style()->drawItemText(&p, textRect, Qt::TextSingleLine | Qt::AlignCenter, option.palette, true, txt);
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,6 @@ private:
|
||||
Qt::MouseButtons m_buttons;
|
||||
Qt::KeyboardModifiers m_modifiers;
|
||||
bool m_showOnlyIcon;
|
||||
int m_padding;
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,74 +1,73 @@
|
||||
{
|
||||
"roots" : {
|
||||
"bookmark_bar" : {
|
||||
"children" : [
|
||||
"roots": {
|
||||
"bookmark_bar": {
|
||||
"children": [
|
||||
{
|
||||
"description" : "Source code of QupZilla",
|
||||
"keyword" : "qz-git",
|
||||
"name" : "QupZilla Git",
|
||||
"type" : "url",
|
||||
"url" : "https://github.com/QupZilla/qupzilla",
|
||||
"visit_count" : 0
|
||||
"description": "Source code of QupZilla",
|
||||
"keyword": "qz-git",
|
||||
"name": "QupZilla Git",
|
||||
"type": "url",
|
||||
"url": "https://github.com/QupZilla/qupzilla",
|
||||
"visit_count": 0
|
||||
},
|
||||
{
|
||||
"description" : "GitHub Issue Tracker for QupZilla",
|
||||
"keyword" : "qz-issues",
|
||||
"name" : "QupZilla Issues",
|
||||
"type" : "url",
|
||||
"url" : "https://github.com/QupZilla/qupzilla/issues",
|
||||
"visit_count" : 0
|
||||
"description": "",
|
||||
"keyword": "qz-wiki",
|
||||
"name": "QupZilla Wiki",
|
||||
"type": "url",
|
||||
"url": "https://github.com/QupZilla/qupzilla/wiki",
|
||||
"visit_count": 0
|
||||
},
|
||||
{
|
||||
"description" : "",
|
||||
"keyword" : "qz-wiki",
|
||||
"name" : "QupZilla Wiki",
|
||||
"type" : "url",
|
||||
"url" : "https://github.com/QupZilla/qupzilla/wiki",
|
||||
"visit_count" : 0
|
||||
"description": "GitHub Issue Tracker for QupZilla",
|
||||
"keyword": "qz-issues",
|
||||
"name": "QupZilla Issues",
|
||||
"type": "url",
|
||||
"url": "https://github.com/QupZilla/qupzilla/issues",
|
||||
"visit_count": 0
|
||||
},
|
||||
{
|
||||
"description" : "Blog with development updates",
|
||||
"keyword" : "qz-blog",
|
||||
"name" : "QupZilla Blog",
|
||||
"type" : "url",
|
||||
"url" : "http://blog.qupzilla.com/",
|
||||
"visit_count" : 0
|
||||
"type": "separator"
|
||||
},
|
||||
{
|
||||
"description" : "QupZilla Homepage",
|
||||
"keyword" : "qz-home",
|
||||
"name" : "QupZilla Home",
|
||||
"type" : "url",
|
||||
"url" : "http://www.qupzilla.com/",
|
||||
"visit_count" : 0
|
||||
"description": "Blog with development updates",
|
||||
"keyword": "qz-blog",
|
||||
"name": "QupZilla Blog",
|
||||
"type": "url",
|
||||
"url": "http://blog.qupzilla.com/",
|
||||
"visit_count": 0
|
||||
},
|
||||
{
|
||||
"description": "QupZilla Homepage",
|
||||
"keyword": "qz-home",
|
||||
"name": "QupZilla Home",
|
||||
"type": "url",
|
||||
"url": "http://www.qupzilla.com/",
|
||||
"visit_count": 0
|
||||
}
|
||||
],
|
||||
"description" : "Bookmarks located in Bookmarks Toolbar",
|
||||
"expanded" : true,
|
||||
"expanded_sidebar" : true,
|
||||
"name" : "Bookmarks Toolbar",
|
||||
"type" : "folder"
|
||||
"description": "Bookmarks located in Bookmarks Toolbar",
|
||||
"expanded": true,
|
||||
"expanded_sidebar": true,
|
||||
"name": "Bookmarks Toolbar",
|
||||
"type": "folder"
|
||||
},
|
||||
"bookmark_menu" : {
|
||||
"children" : [
|
||||
|
||||
],
|
||||
"description" : "Bookmarks located in Bookmarks Menu",
|
||||
"expanded" : true,
|
||||
"expanded_sidebar" : true,
|
||||
"name" : "Bookmarks Menu",
|
||||
"type" : "folder"
|
||||
"bookmark_menu": {
|
||||
"children": [],
|
||||
"description": "Bookmarks located in Bookmarks Menu",
|
||||
"expanded": true,
|
||||
"expanded_sidebar": true,
|
||||
"name": "Bookmarks Menu",
|
||||
"type": "folder"
|
||||
},
|
||||
"other" : {
|
||||
"children" : [
|
||||
|
||||
],
|
||||
"description" : "All other bookmarks",
|
||||
"expanded" : true,
|
||||
"expanded_sidebar" : true,
|
||||
"name" : "Unsorted Bookmarks",
|
||||
"type" : "folder"
|
||||
"other": {
|
||||
"children": [],
|
||||
"description": "All other bookmarks",
|
||||
"expanded": true,
|
||||
"expanded_sidebar": true,
|
||||
"name": "Unsorted Bookmarks",
|
||||
"type": "folder"
|
||||
}
|
||||
},
|
||||
"version" : 1
|
||||
"version": 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user