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

@ -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()
);
}