mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Bookmarks: Add option to show only text in bookmarks bar
This commit is contained in:
parent
4a8d8fde59
commit
30d2980d86
@ -49,6 +49,7 @@ void Bookmarks::loadSettings()
|
||||
Settings settings;
|
||||
settings.beginGroup("Bookmarks");
|
||||
m_showOnlyIconsInToolbar = settings.value("showOnlyIconsInToolbar", false).toBool();
|
||||
m_showOnlyTextInToolbar = settings.value("showOnlyTextInToolbar", false).toBool();
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
@ -57,6 +58,11 @@ bool Bookmarks::showOnlyIconsInToolbar() const
|
||||
return m_showOnlyIconsInToolbar;
|
||||
}
|
||||
|
||||
bool Bookmarks::showOnlyTextInToolbar() const
|
||||
{
|
||||
return m_showOnlyTextInToolbar;
|
||||
}
|
||||
|
||||
BookmarkItem* Bookmarks::rootItem() const
|
||||
{
|
||||
return m_root;
|
||||
@ -174,11 +180,18 @@ void Bookmarks::setShowOnlyIconsInToolbar(bool state)
|
||||
emit showOnlyIconsInToolbarChanged(state);
|
||||
}
|
||||
|
||||
void Bookmarks::setShowOnlyTextInToolbar(bool state)
|
||||
{
|
||||
m_showOnlyTextInToolbar = state;
|
||||
emit showOnlyTextInToolbarChanged(state);
|
||||
}
|
||||
|
||||
void Bookmarks::saveSettings()
|
||||
{
|
||||
Settings settings;
|
||||
settings.beginGroup("Bookmarks");
|
||||
settings.setValue("showOnlyIconsInToolbar", m_showOnlyIconsInToolbar);
|
||||
settings.setValue("showOnlyTextInToolbar", m_showOnlyTextInToolbar);
|
||||
settings.endGroup();
|
||||
|
||||
saveBookmarks();
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
void loadSettings();
|
||||
|
||||
bool showOnlyIconsInToolbar() const;
|
||||
bool showOnlyTextInToolbar() const;
|
||||
|
||||
BookmarkItem* rootItem() const;
|
||||
BookmarkItem* toolbarFolder() const;
|
||||
@ -65,6 +66,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void setShowOnlyIconsInToolbar(bool state);
|
||||
void setShowOnlyTextInToolbar(bool state);
|
||||
|
||||
signals:
|
||||
// Item was added to bookmarks
|
||||
@ -75,6 +77,7 @@ signals:
|
||||
void bookmarkChanged(BookmarkItem* item);
|
||||
|
||||
void showOnlyIconsInToolbarChanged(bool show);
|
||||
void showOnlyTextInToolbarChanged(bool show);
|
||||
|
||||
private slots:
|
||||
void saveSettings();
|
||||
@ -102,6 +105,7 @@ private:
|
||||
AutoSaver* m_autoSaver;
|
||||
|
||||
bool m_showOnlyIconsInToolbar;
|
||||
bool m_showOnlyTextInToolbar;
|
||||
};
|
||||
|
||||
#endif // BOOKMARKS_H
|
||||
|
@ -56,6 +56,7 @@ BookmarksToolbar::BookmarksToolbar(BrowserWindow* window, QWidget* parent)
|
||||
connect(m_bookmarks, SIGNAL(bookmarkRemoved(BookmarkItem*)), this, SLOT(bookmarksChanged()));
|
||||
connect(m_bookmarks, SIGNAL(bookmarkChanged(BookmarkItem*)), this, SLOT(bookmarksChanged()));
|
||||
connect(m_bookmarks, SIGNAL(showOnlyIconsInToolbarChanged(bool)), this, SLOT(showOnlyIconsChanged(bool)));
|
||||
connect(m_bookmarks, SIGNAL(showOnlyTextInToolbarChanged(bool)), this, SLOT(showOnlyTextChanged(bool)));
|
||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
|
||||
|
||||
refresh();
|
||||
@ -72,10 +73,14 @@ void BookmarksToolbar::contextMenuRequested(const QPoint &pos)
|
||||
menu.addSeparator();
|
||||
QAction* actDelete = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
|
||||
menu.addSeparator();
|
||||
QAction* act = menu.addAction(tr("Show Only Icons"));
|
||||
act->setCheckable(true);
|
||||
act->setChecked(m_bookmarks->showOnlyIconsInToolbar());
|
||||
connect(act, SIGNAL(toggled(bool)), m_bookmarks, SLOT(setShowOnlyIconsInToolbar(bool)));
|
||||
m_actShowOnlyIcons = menu.addAction(tr("Show Only Icons"));
|
||||
m_actShowOnlyIcons->setCheckable(true);
|
||||
m_actShowOnlyIcons->setChecked(m_bookmarks->showOnlyIconsInToolbar());
|
||||
connect(m_actShowOnlyIcons, SIGNAL(toggled(bool)), m_bookmarks, SLOT(setShowOnlyIconsInToolbar(bool)));
|
||||
m_actShowOnlyText = menu.addAction(tr("Show Only Text"));
|
||||
m_actShowOnlyText->setCheckable(true);
|
||||
m_actShowOnlyText->setChecked(m_bookmarks->showOnlyTextInToolbar());
|
||||
connect(m_actShowOnlyText, SIGNAL(toggled(bool)), m_bookmarks, SLOT(setShowOnlyTextInToolbar(bool)));
|
||||
|
||||
connect(actNewTab, SIGNAL(triggered()), this, SLOT(openBookmarkInNewTab()));
|
||||
connect(actNewWindow, SIGNAL(triggered()), this, SLOT(openBookmarkInNewWindow()));
|
||||
@ -93,6 +98,8 @@ void BookmarksToolbar::contextMenuRequested(const QPoint &pos)
|
||||
}
|
||||
|
||||
m_clickedBookmark = 0;
|
||||
m_actShowOnlyIcons = 0;
|
||||
m_actShowOnlyText = 0;
|
||||
}
|
||||
|
||||
void BookmarksToolbar::refresh()
|
||||
@ -115,6 +122,10 @@ void BookmarksToolbar::bookmarksChanged()
|
||||
|
||||
void BookmarksToolbar::showOnlyIconsChanged(bool state)
|
||||
{
|
||||
if (state && m_actShowOnlyText) {
|
||||
m_actShowOnlyText->setChecked(false);
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_layout->count(); ++i) {
|
||||
BookmarksToolbarButton* b = qobject_cast<BookmarksToolbarButton*>(m_layout->itemAt(i)->widget());
|
||||
if (b) {
|
||||
@ -123,6 +134,20 @@ void BookmarksToolbar::showOnlyIconsChanged(bool state)
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksToolbar::showOnlyTextChanged(bool state)
|
||||
{
|
||||
if (state && m_actShowOnlyIcons) {
|
||||
m_actShowOnlyIcons->setChecked(false);
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_layout->count(); ++i) {
|
||||
BookmarksToolbarButton* b = qobject_cast<BookmarksToolbarButton*>(m_layout->itemAt(i)->widget());
|
||||
if (b) {
|
||||
b->setShowOnlyText(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksToolbar::openBookmarkInNewTab()
|
||||
{
|
||||
if (m_clickedBookmark) {
|
||||
@ -164,6 +189,7 @@ void BookmarksToolbar::addItem(BookmarkItem* item)
|
||||
BookmarksToolbarButton* button = new BookmarksToolbarButton(item, this);
|
||||
button->setMainWindow(m_window);
|
||||
button->setShowOnlyIcon(m_bookmarks->showOnlyIconsInToolbar());
|
||||
button->setShowOnlyIcon(m_bookmarks->showOnlyTextInToolbar());
|
||||
m_layout->addWidget(button);
|
||||
|
||||
setFixedHeight(m_layout->spacing() * 2 + button->preferredHeight());
|
||||
|
@ -42,6 +42,7 @@ private slots:
|
||||
void refresh();
|
||||
void bookmarksChanged();
|
||||
void showOnlyIconsChanged(bool state);
|
||||
void showOnlyTextChanged(bool state);
|
||||
|
||||
void openBookmarkInNewTab();
|
||||
void openBookmarkInNewWindow();
|
||||
@ -60,6 +61,8 @@ private:
|
||||
BookmarkItem* m_clickedBookmark;
|
||||
QHBoxLayout* m_layout;
|
||||
QTimer* m_updateTimer;
|
||||
QAction* m_actShowOnlyIcons;
|
||||
QAction* m_actShowOnlyText;
|
||||
};
|
||||
|
||||
#endif // BOOKMARKSTOOLBAR_H
|
||||
|
@ -59,11 +59,27 @@ void BookmarksToolbarButton::setShowOnlyIcon(bool show)
|
||||
{
|
||||
m_showOnlyIcon = show;
|
||||
updateGeometry();
|
||||
update();
|
||||
}
|
||||
|
||||
bool BookmarksToolbarButton::showOnlyText() const
|
||||
{
|
||||
return m_showOnlyText;
|
||||
}
|
||||
|
||||
void BookmarksToolbarButton::setShowOnlyText(bool show)
|
||||
{
|
||||
m_showOnlyText = show;
|
||||
updateGeometry();
|
||||
update();
|
||||
}
|
||||
|
||||
QSize BookmarksToolbarButton::sizeHint() const
|
||||
{
|
||||
int width = PADDING * 2 + 16;
|
||||
int width = PADDING * 2;
|
||||
if (!m_showOnlyText) {
|
||||
width += 16;
|
||||
}
|
||||
|
||||
if (m_bookmark->isSeparator()) {
|
||||
width = SEPARATOR_WIDTH;
|
||||
@ -81,7 +97,10 @@ QSize BookmarksToolbarButton::sizeHint() const
|
||||
|
||||
QSize BookmarksToolbarButton::minimumSizeHint() const
|
||||
{
|
||||
int width = PADDING * 2 + 16;
|
||||
int width = PADDING * 2;
|
||||
if (!m_showOnlyText) {
|
||||
width += 16;
|
||||
}
|
||||
|
||||
if (m_bookmark->isSeparator()) {
|
||||
width = SEPARATOR_WIDTH;
|
||||
@ -310,9 +329,11 @@ void BookmarksToolbarButton::paintEvent(QPaintEvent* event)
|
||||
int rightPosition = option.rect.right() - PADDING;
|
||||
|
||||
// Draw icon
|
||||
if (!m_showOnlyText) {
|
||||
QRect iconRect(leftPosition, iconYPos, iconSize, iconSize);
|
||||
p.drawPixmap(iconRect, m_bookmark->icon().pixmap(iconSize));
|
||||
leftPosition = iconRect.right() + PADDING;
|
||||
}
|
||||
|
||||
// Draw menu arrow
|
||||
if (!m_showOnlyIcon && menu()) {
|
||||
|
@ -39,6 +39,9 @@ public:
|
||||
bool showOnlyIcon() const;
|
||||
void setShowOnlyIcon(bool show);
|
||||
|
||||
bool showOnlyText() const;
|
||||
void setShowOnlyText(bool show);
|
||||
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
int preferredHeight() const;
|
||||
@ -70,6 +73,7 @@ private:
|
||||
BrowserWindow* m_window;
|
||||
|
||||
bool m_showOnlyIcon;
|
||||
bool m_showOnlyText;
|
||||
};
|
||||
|
||||
#endif // BOOKMARKSTOOLBARBUTTON_H
|
||||
|
Loading…
Reference in New Issue
Block a user