Move category tab widgets to separate widget and hide history category when there is no history

This commit is contained in:
Janek Bevendorff 2017-02-22 01:05:24 +01:00
parent 851c7b891e
commit cee297b218
No known key found for this signature in database
GPG Key ID: CFEC2F6850BFFA53
11 changed files with 412 additions and 212 deletions

View File

@ -70,6 +70,7 @@ set(keepassx_SOURCES
format/KeePass2XmlWriter.cpp
gui/AboutDialog.cpp
gui/Application.cpp
gui/CategoryListWidget.cpp
gui/ChangeMasterKeyWidget.cpp
gui/Clipboard.cpp
gui/DatabaseOpenWidget.cpp
@ -132,6 +133,7 @@ set(keepassx_FORMS
gui/ChangeMasterKeyWidget.ui
gui/DatabaseOpenWidget.ui
gui/DatabaseSettingsWidget.ui
gui/CategoryListWidget.ui
gui/EditWidget.ui
gui/EditWidgetIcons.ui
gui/EditWidgetProperties.ui

View File

@ -0,0 +1,173 @@
/*
* Copyright (C) 2017 KeePassXC Team
*
* 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 2 or (at your option)
* version 3 of the License.
*
* 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 "CategoryListWidget.h"
#include "ui_CategoryListWidget.h"
#include <QListWidget>
#include <QScrollBar>
#include <QSize>
#include <QStyledItemDelegate>
#include <QPainter>
CategoryListWidget::CategoryListWidget(QWidget* parent)
: QWidget(parent),
m_ui(new Ui::CategoryListWidget())
{
m_ui->setupUi(this);
m_ui->categoryList->setItemDelegate(new CategoryListWidgetDelegate(this));
connect(m_ui->categoryList, SIGNAL(currentRowChanged(int)), SLOT(emitCategoryChanged(int)));
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()));
}
CategoryListWidget::~CategoryListWidget()
{
}
QSize CategoryListWidget::sizeHint() const
{
QSize sizeHint = QWidget::sizeHint();
int width = m_ui->categoryList->sizeHintForColumn(0) + m_ui->categoryList->frameWidth() * 2;
if (m_ui->categoryList->verticalScrollBar()->isVisible()) {
width += m_ui->categoryList->verticalScrollBar()->width();
}
sizeHint.setWidth(width);
return sizeHint;
}
QSize CategoryListWidget::minimumSizeHint() const
{
return QSize(sizeHint().width(), m_ui->categoryList->sizeHintForRow(0) * 2);
}
int CategoryListWidget::addCategory(const QString& labelText, const QIcon& icon)
{
QListWidgetItem* item = new QListWidgetItem(m_ui->categoryList);
item->setText(labelText);
item->setIcon(icon);
m_ui->categoryList->addItem(item);
return m_ui->categoryList->count() - 1;
}
void CategoryListWidget::removeCategory(int index)
{
m_ui->categoryList->removeItemWidget(m_ui->categoryList->item(index));
}
int CategoryListWidget::currentCategory()
{
return m_ui->categoryList->currentRow();
}
void CategoryListWidget::setCurrentCategory(int index)
{
m_ui->categoryList->setCurrentRow(index);
}
void CategoryListWidget::setCategoryHidden(int index, bool hidden)
{
m_ui->categoryList->item(index)->setHidden(hidden);
}
bool CategoryListWidget::isCategoryHidden(int index)
{
return m_ui->categoryList->item(index)->isHidden();
}
void CategoryListWidget::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);
updateCategoryScrollButtons();
}
void CategoryListWidget::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 CategoryListWidget::scrollCategoriesUp()
{
m_ui->categoryList->verticalScrollBar()->setValue(
m_ui->categoryList->verticalScrollBar()->value() - m_ui->categoryList->verticalScrollBar()->pageStep()
);
}
void CategoryListWidget::scrollCategoriesDown()
{
m_ui->categoryList->verticalScrollBar()->setValue(
m_ui->categoryList->verticalScrollBar()->value() + m_ui->categoryList->verticalScrollBar()->pageStep()
);
}
void CategoryListWidget::emitCategoryChanged(int index)
{
emit categoryChanged(index);
}
/* =============================================================================================== */
CategoryListWidgetDelegate::CategoryListWidgetDelegate(QWidget* parent)
: QStyledItemDelegate(parent),
m_size(96, 96)
{}
void CategoryListWidgetDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
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 CategoryListWidgetDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(option);
Q_UNUSED(index);
return m_size;
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2017 KeePassXC Team
*
* 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 2 or (at your option)
* version 3 of the License.
*
* 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 <QWidget>
#include <QStyledItemDelegate>
namespace Ui {
class CategoryListWidget;
}
class CategoryListWidget : public QWidget
{
Q_OBJECT
public:
CategoryListWidget(QWidget* parent = 0);
~CategoryListWidget();
int currentCategory();
void setCurrentCategory(int index);
int addCategory(const QString& labelText, const QIcon& icon);
void setCategoryHidden(int index, bool hidden);
bool isCategoryHidden(int index);
void removeCategory(int index);
signals:
void categoryChanged(int index);
protected:
void showEvent(QShowEvent* event) override;
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
protected slots:
void updateCategoryScrollButtons();
void scrollCategoriesDown();
void scrollCategoriesUp();
void emitCategoryChanged(int index);
private:
const QScopedPointer<Ui::CategoryListWidget> m_ui;
Q_DISABLE_COPY(CategoryListWidget)
};
/* =============================================================================================== */
class CategoryListWidgetDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit CategoryListWidgetDelegate(QWidget* parent = nullptr);
protected:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
private:
QSize m_size;
Q_DISABLE_COPY(CategoryListWidgetDelegate)
};

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CategoryListWidget</class>
<widget class="QWidget" name="CategoryListWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>182</width>
<height>418</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<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="QListWidget" name="categoryList">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</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="flow">
<enum>QListView::TopToBottom</enum>
</property>
<property name="isWrapping" stdset="0">
<bool>false</bool>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</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>
</widget>
<tabstops>
<tabstop>categoryList</tabstop>
<tabstop>scrollUp</tabstop>
<tabstop>scrollDown</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -34,41 +34,43 @@ EditWidget::EditWidget(QWidget* parent)
headerLabelFont.setPointSize(headerLabelFont.pointSize() + 2);
headlineLabel()->setFont(headerLabelFont);
connect(m_ui->categoryList, SIGNAL(currentRowChanged(int)),
connect(m_ui->categoryList, SIGNAL(categoryChanged(int)),
m_ui->stackedWidget, SLOT(setCurrentIndex(int)));
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()
{
}
void EditWidget::add(const QString& labelText, QWidget* widget)
void EditWidget::addPage(const QString& labelText, const QIcon& icon, 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);
m_ui->categoryList->addCategory(labelText, icon);
}
void EditWidget::setRowHidden(QWidget* widget, bool hide)
void EditWidget::setPageHidden(QWidget* widget, bool hidden)
{
int row = m_ui->stackedWidget->indexOf(widget);
if (row != -1) {
m_ui->categoryList->item(row)->setHidden(hide);
int index = m_ui->stackedWidget->indexOf(widget);
if (index != -1) {
m_ui->categoryList->setCategoryHidden(index, hidden);
}
if (index == m_ui->stackedWidget->currentIndex()) {
int newIndex = m_ui->stackedWidget->currentIndex() - 1;
if (newIndex < 0) {
newIndex = m_ui->stackedWidget->count() - 1;
}
m_ui->stackedWidget->setCurrentIndex(newIndex);
}
}
void EditWidget::setCurrentRow(int index)
void EditWidget::setCurrentPage(int index)
{
m_ui->categoryList->setCurrentRow(index);
m_ui->categoryList->setCurrentCategory(index);
m_ui->stackedWidget->setCurrentIndex(index);
}
void EditWidget::setHeadline(const QString& text)
@ -109,33 +111,3 @@ 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

@ -39,25 +39,19 @@ public:
explicit EditWidget(QWidget* parent = nullptr);
~EditWidget();
void add(const QString& labelText, QWidget* widget);
void setRowHidden(QWidget* widget, bool hide);
void setCurrentRow(int index);
void addPage(const QString& labelText, const QIcon& icon, QWidget* widget);
void setPageHidden(QWidget* widget, bool hidden);
void setCurrentPage(int index);
void setHeadline(const QString& text);
QLabel* headlineLabel();
void setReadOnly(bool readOnly);
bool readOnly() const;
protected:
void showEvent(QShowEvent* event) override;
signals:
void accepted();
void rejected();
protected slots:
void updateCategoryScrollButtons();
void scrollCategoriesDown();
void scrollCategoriesUp();
void showMessage(const QString& text, MessageWidget::MessageType type);
void hideMessage();

View File

@ -39,60 +39,9 @@
</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">
@ -128,14 +77,9 @@
<customwidget>
<class>CategoryListWidget</class>
<extends>QListWidget</extends>
<header>gui/entry/EditEntryWidget_p.h</header>
<header>gui/CategoryListWidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>categoryList</tabstop>
<tabstop>scrollUp</tabstop>
<tabstop>scrollDown</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -22,6 +22,7 @@
#include "autotype/AutoType.h"
#include "core/Config.h"
#include "core/Translator.h"
#include "core/FilePath.h"
class SettingsWidget::ExtraPage
{
@ -57,8 +58,8 @@ SettingsWidget::SettingsWidget(QWidget* parent)
m_secUi->setupUi(m_secWidget);
m_generalUi->setupUi(m_generalWidget);
add(tr("General"), m_generalWidget);
add(tr("Security"), m_secWidget);
addPage(tr("General"), FilePath::instance()->icon("apps", "keepassxc"), m_generalWidget);
addPage(tr("Security"), FilePath::instance()->icon("apps", "keepassxc"), m_secWidget);
m_generalUi->autoTypeShortcutWidget->setVisible(autoType()->isAvailable());
m_generalUi->autoTypeShortcutLabel->setVisible(autoType()->isAvailable());
@ -92,7 +93,7 @@ void SettingsWidget::addSettingsPage(ISettingsPage *page)
QWidget * widget = page->createWidget();
widget->setParent(this);
m_extraPages.append(ExtraPage(page, widget));
add(page->name(), widget);
addPage(page->name(), FilePath::instance()->icon("apps", "keepassxc"), widget);
}
void SettingsWidget::loadSettings()
@ -146,7 +147,7 @@ void SettingsWidget::loadSettings()
Q_FOREACH (const ExtraPage& page, m_extraPages)
page.loadSettings();
setCurrentRow(0);
setCurrentPage(0);
}
void SettingsWidget::saveSettings()

View File

@ -90,7 +90,7 @@ EditEntryWidget::~EditEntryWidget()
void EditEntryWidget::setupMain()
{
m_mainUi->setupUi(m_mainWidget);
add(tr("Entry"), m_mainWidget);
addPage(tr("Entry"), FilePath::instance()->icon("apps", "keepassxc"), m_mainWidget);
m_mainUi->togglePasswordButton->setIcon(filePath()->onOffIcon("actions", "password-show"));
m_mainUi->togglePasswordGeneratorButton->setIcon(filePath()->icon("actions", "password-generator", false));
@ -115,7 +115,7 @@ void EditEntryWidget::setupMain()
void EditEntryWidget::setupAdvanced()
{
m_advancedUi->setupUi(m_advancedWidget);
add(tr("Advanced"), m_advancedWidget);
addPage(tr("Advanced"), FilePath::instance()->icon("apps", "keepassxc"), m_advancedWidget);
m_attachmentsModel->setEntryAttachments(m_entryAttachments);
m_advancedUi->attachmentsView->setModel(m_attachmentsModel);
@ -139,13 +139,13 @@ void EditEntryWidget::setupAdvanced()
void EditEntryWidget::setupIcon()
{
add(tr("Icon"), m_iconsWidget);
addPage(tr("Icon"), FilePath::instance()->icon("apps", "keepassxc"), m_iconsWidget);
}
void EditEntryWidget::setupAutoType()
{
m_autoTypeUi->setupUi(m_autoTypeWidget);
add(tr("Auto-Type"), m_autoTypeWidget);
addPage(tr("Auto-Type"), FilePath::instance()->icon("apps", "keepassxc"), m_autoTypeWidget);
m_autoTypeDefaultSequenceGroup->addButton(m_autoTypeUi->inheritSequenceButton);
m_autoTypeDefaultSequenceGroup->addButton(m_autoTypeUi->customSequenceButton);
@ -177,13 +177,13 @@ void EditEntryWidget::setupAutoType()
void EditEntryWidget::setupProperties()
{
add(tr("Properties"), m_editWidgetProperties);
addPage(tr("Properties"), FilePath::instance()->icon("apps", "keepassxc"), m_editWidgetProperties);
}
void EditEntryWidget::setupHistory()
{
m_historyUi->setupUi(m_historyWidget);
add(tr("History"), m_historyWidget);
addPage(tr("History"), FilePath::instance()->icon("apps", "keepassxc"), m_historyWidget);
m_sortModel->setSourceModel(m_historyModel);
m_sortModel->setDynamicSortFilter(true);
@ -291,8 +291,8 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, bool history, const Q
setForms(entry);
setReadOnly(m_history);
setCurrentRow(0);
setRowHidden(m_historyWidget, m_history);
setCurrentPage(0);
setPageHidden(m_historyWidget, m_history || m_entry->historyItems().count() < 1);
}
void EditEntryWidget::setForms(const Entry* entry, bool restore)

View File

@ -18,90 +18,8 @@
#ifndef KEEPASSX_EDITENTRYWIDGET_P_H
#define KEEPASSX_EDITENTRYWIDGET_P_H
#include <QListWidget>
#include <QListView>
#include <QScrollBar>
#include <QSize>
#include <QStyledItemDelegate>
#include <QPainter>
class CategoryListViewDelegate : public QStyledItemDelegate
{
public:
explicit CategoryListViewDelegate(QListView* parent = nullptr)
: QStyledItemDelegate(parent), m_size(96, 96)
{}
protected:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override
{
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)
{
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
setItemDelegate(new CategoryListViewDelegate(this));
setMovement(QListView::Static);
setViewMode(QListWidget::IconMode);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setWordWrap(true);
}
protected:
QSize sizeHint() const override
{
QSize sizeHint = QListWidget::sizeHint();
int width = sizeHintForColumn(0) + frameWidth() * 2;
if (verticalScrollBar()->isVisible()) {
width += verticalScrollBar()->width();
}
sizeHint.setWidth(width);
return sizeHint;
}
QSize minimumSizeHint() const override
{
return QSize(sizeHint().width(), sizeHintForRow(0) * 2);
}
};
class AttributesListView : public QListView
{

View File

@ -19,6 +19,7 @@
#include "ui_EditGroupWidgetMain.h"
#include "core/Metadata.h"
#include "core/FilePath.h"
#include "gui/EditWidgetIcons.h"
#include "gui/EditWidgetProperties.h"
@ -33,9 +34,9 @@ EditGroupWidget::EditGroupWidget(QWidget* parent)
{
m_mainUi->setupUi(m_editGroupWidgetMain);
add(tr("Group"), m_editGroupWidgetMain);
add(tr("Icon"), m_editGroupWidgetIcons);
add(tr("Properties"), m_editWidgetProperties);
addPage(tr("Group"), FilePath::instance()->icon("apps", "keepassxc"), m_editGroupWidgetMain);
addPage(tr("Icon"), FilePath::instance()->icon("apps", "keepassxc"), m_editGroupWidgetIcons);
addPage(tr("Properties"), FilePath::instance()->icon("apps", "keepassxc"), m_editWidgetProperties);
connect(m_mainUi->expireCheck, SIGNAL(toggled(bool)), m_mainUi->expireDatePicker, SLOT(setEnabled(bool)));
connect(m_mainUi->autoTypeSequenceCustomRadio, SIGNAL(toggled(bool)),
@ -94,7 +95,7 @@ void EditGroupWidget::loadGroup(Group* group, bool create, Database* database)
m_editWidgetProperties->setFields(group->timeInfo(), group->uuid());
setCurrentRow(0);
setCurrentPage(0);
m_mainUi->editName->setFocus();
}