Show icons in vertical tab bar

TODO: use the correct icons, move vertical tab bar into separate widget
This commit is contained in:
Janek Bevendorff 2017-02-21 21:34:13 +01:00
parent 0064f5dcfd
commit 851c7b891e
6 changed files with 162 additions and 19 deletions

View File

@ -18,6 +18,8 @@
#include "EditWidget.h"
#include "ui_EditWidget.h"
#include "core/FilePath.h"
EditWidget::EditWidget(QWidget* parent)
: DialogyWidget(parent)
, m_ui(new Ui::EditWidget())
@ -37,6 +39,11 @@ EditWidget::EditWidget(QWidget* parent)
connect(m_ui->buttonBox, SIGNAL(accepted()), SIGNAL(accepted()));
connect(m_ui->buttonBox, SIGNAL(rejected()), SIGNAL(rejected()));
connect(m_ui->scrollUp, SIGNAL(clicked()), SLOT(scrollCategoriesUp()));
connect(m_ui->scrollDown, SIGNAL(clicked()), SLOT(scrollCategoriesDown()));
connect(m_ui->categoryList->verticalScrollBar(), SIGNAL(valueChanged(int)), SLOT(updateCategoryScrollButtons()));
connect(m_ui->categoryList->verticalScrollBar(), SIGNAL(rangeChanged(int, int)), SLOT(updateCategoryScrollButtons()));
}
EditWidget::~EditWidget()
@ -46,6 +53,8 @@ EditWidget::~EditWidget()
void EditWidget::add(const QString& labelText, QWidget* widget)
{
m_ui->categoryList->addItem(labelText);
QListWidgetItem* item = m_ui->categoryList->item(m_ui->categoryList->count() - 1);
item->setIcon(FilePath::instance()->icon("apps", "keepassxc"));
m_ui->stackedWidget->addWidget(widget);
}
@ -100,3 +109,33 @@ void EditWidget::hideMessage()
m_ui->messageWidget->animatedHide();
}
}
void EditWidget::updateCategoryScrollButtons()
{
m_ui->scrollUp->setEnabled(m_ui->categoryList->verticalScrollBar()->value() != 0);
m_ui->scrollDown->setEnabled(m_ui->categoryList->verticalScrollBar()->value()
!= m_ui->categoryList->verticalScrollBar()->maximum());
m_ui->scrollUp->setVisible(m_ui->categoryList->verticalScrollBar()->maximum() > 0);
m_ui->scrollDown->setVisible(m_ui->scrollUp->isVisible());
}
void EditWidget::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);
updateCategoryScrollButtons();
}
void EditWidget::scrollCategoriesUp()
{
m_ui->categoryList->verticalScrollBar()->setValue(
m_ui->categoryList->verticalScrollBar()->value() - m_ui->categoryList->verticalScrollBar()->pageStep()
);
}
void EditWidget::scrollCategoriesDown()
{
m_ui->categoryList->verticalScrollBar()->setValue(
m_ui->categoryList->verticalScrollBar()->value() + m_ui->categoryList->verticalScrollBar()->pageStep()
);
}

View File

@ -19,6 +19,8 @@
#define KEEPASSX_EDITWIDGET_H
#include <QScopedPointer>
#include <QtWidgets/QStyledItemDelegate>
#include <QStyledItemDelegate>
#include "gui/DialogyWidget.h"
#include "gui/MessageWidget.h"
@ -45,11 +47,17 @@ public:
void setReadOnly(bool readOnly);
bool readOnly() const;
Q_SIGNALS:
protected:
void showEvent(QShowEvent* event) override;
signals:
void accepted();
void rejected();
protected Q_SLOTS:
protected slots:
void updateCategoryScrollButtons();
void scrollCategoriesDown();
void scrollCategoriesUp();
void showMessage(const QString& text, MessageWidget::MessageType type);
void hideMessage();

View File

@ -39,9 +39,60 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="scrollUp">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>15</height>
</size>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="arrowType">
<enum>Qt::UpArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="CategoryListWidget" name="categoryList"/>
</item>
<item>
<widget class="QToolButton" name="scrollDown">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>15</height>
</size>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="arrowType">
<enum>Qt::DownArrow</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
@ -52,7 +103,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>5</number>
</property>
@ -82,6 +133,8 @@
</customwidgets>
<tabstops>
<tabstop>categoryList</tabstop>
<tabstop>scrollUp</tabstop>
<tabstop>scrollDown</tabstop>
</tabstops>
<resources/>
<connections/>

View File

@ -62,7 +62,7 @@ class HttpPlugin: public ISettingsPage
//delete m_service;
}
virtual QString name() {
return QObject::tr("Http");
return QObject::tr("Browser Integration");
}
virtual QWidget * createWidget() {
OptionDialog * dlg = new OptionDialog();

View File

@ -22,34 +22,73 @@
#include <QScrollBar>
#include <QSize>
#include <QStyledItemDelegate>
#include <QPainter>
class CategoryListViewDelegate : public QStyledItemDelegate
{
public:
explicit CategoryListViewDelegate(QObject* parent) : QStyledItemDelegate(parent) {}
explicit CategoryListViewDelegate(QListView* parent = nullptr)
: QStyledItemDelegate(parent), m_size(96, 96)
{}
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
protected:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override
{
QSize size = QStyledItemDelegate::sizeHint(option, index);
size.setHeight(qMax(size.height(), 22));
return size;
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
painter->save();
QIcon icon = opt.icon;
QSize iconSize = opt.icon.actualSize(QSize(32, 32));
opt.icon = QIcon();
opt.decorationAlignment = Qt::AlignHCenter | Qt::AlignVCenter;
opt.decorationPosition = QStyleOptionViewItem::Top;
QStyle* style = opt.widget ? opt.widget->style() : QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
QRect fontRect = painter->fontMetrics().boundingRect(
QRect(0, 0, m_size.width(), m_size.height()), Qt::AlignHCenter | Qt::AlignBottom | Qt::TextWordWrap, opt.text);
int paddingTop = fontRect.height() < 30 ? 15 : 10;
int left = opt.rect.left() + opt.rect.width() / 2 - iconSize.width() / 2;
painter->drawPixmap(left, opt.rect.top() + paddingTop, icon.pixmap(iconSize));
painter->restore();
}
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
{
Q_UNUSED(option);
Q_UNUSED(index);
return m_size;
}
private:
QSize m_size;
};
class CategoryListWidget : public QListWidget
{
public:
explicit CategoryListWidget(QWidget* parent = 0) : QListWidget(parent)
explicit CategoryListWidget(QWidget* parent = 0)
: QListWidget(parent)
{
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
setItemDelegate(new CategoryListViewDelegate(this));
setMovement(QListView::Static);
setViewMode(QListWidget::IconMode);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setWordWrap(true);
}
virtual QSize sizeHint() const
protected:
QSize sizeHint() const override
{
QSize sizeHint = QListWidget::sizeHint();
int width = sizeHintForColumn(0) + frameWidth() * 2 + 5;
int width = sizeHintForColumn(0) + frameWidth() * 2;
if (verticalScrollBar()->isVisible()) {
width += verticalScrollBar()->width();
}
@ -57,6 +96,11 @@ public:
return sizeHint;
}
QSize minimumSizeHint() const override
{
return QSize(sizeHint().width(), sizeHintForRow(0) * 2);
}
};
class AttributesListView : public QListView
@ -65,14 +109,13 @@ public:
explicit AttributesListView(QWidget* parent = 0) : QListView(parent)
{
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
setItemDelegate(new CategoryListViewDelegate(this));
}
virtual QSize sizeHint() const
QSize sizeHint() const override
{
QSize sizeHint = QListView::sizeHint();
int width = sizeHintForColumn(0) + frameWidth() * 2 + 5;
int width = sizeHintForColumn(0) + frameWidth() * 2;
if (verticalScrollBar()->isVisible()) {
width += verticalScrollBar()->width();
}

View File

@ -148,7 +148,7 @@ Only entries with the same scheme (http://, https://, ftp://, ...) are returned<
<string notr="true">color: rgb(255, 0, 0);</string>
</property>
<property name="text">
<string>Activate the following only, if you know what you are doing!</string>
<string>Activate the following only if you know what you are doing!</string>
</property>
</widget>
</item>