mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-27 16:29:44 -05:00
parent
a25b28ffee
commit
e776de8eeb
@ -138,6 +138,7 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
|
||||
addWidget(m_unlockDatabaseWidget);
|
||||
|
||||
connect(m_splitter, SIGNAL(splitterMoved(int,int)), SIGNAL(splitterSizesChanged()));
|
||||
connect(m_entryView->header(), SIGNAL(sectionResized(int,int,int)), SIGNAL(entryColumnSizesChanged()));
|
||||
connect(m_groupView, SIGNAL(groupChanged(Group*)), this, SLOT(clearLastGroup(Group*)));
|
||||
connect(m_groupView, SIGNAL(groupChanged(Group*)), SIGNAL(groupChanged()));
|
||||
connect(m_groupView, SIGNAL(groupChanged(Group*)), m_entryView, SLOT(setGroup(Group*)));
|
||||
@ -207,6 +208,29 @@ void DatabaseWidget::setSplitterSizes(const QList<int>& sizes)
|
||||
m_splitter->setSizes(sizes);
|
||||
}
|
||||
|
||||
QList<int> DatabaseWidget::entryHeaderViewSizes() const
|
||||
{
|
||||
QList<int> sizes;
|
||||
|
||||
for (int i = 0; i < m_entryView->header()->count(); i++) {
|
||||
sizes.append(m_entryView->header()->sectionSize(i));
|
||||
}
|
||||
|
||||
return sizes;
|
||||
}
|
||||
|
||||
void DatabaseWidget::setEntryViewHeaderSizes(const QList<int>& sizes)
|
||||
{
|
||||
if (sizes.size() != m_entryView->header()->count()) {
|
||||
Q_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < sizes.size(); i++) {
|
||||
m_entryView->header()->resizeSection(i, sizes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWidget::emitCurrentModeChanged()
|
||||
{
|
||||
Q_EMIT currentModeChanged(currentMode());
|
||||
@ -702,6 +726,8 @@ void DatabaseWidget::closeSearch()
|
||||
Q_ASSERT(m_lastGroup);
|
||||
m_groupView->setCurrentGroup(m_lastGroup);
|
||||
m_searchTimer->stop();
|
||||
|
||||
Q_EMIT listModeActivated();
|
||||
}
|
||||
|
||||
void DatabaseWidget::showSearch()
|
||||
@ -739,6 +765,8 @@ void DatabaseWidget::showSearch()
|
||||
m_searchWidget->show();
|
||||
search();
|
||||
m_searchUi->searchEdit->setFocus();
|
||||
|
||||
Q_EMIT searchModeActivated();
|
||||
}
|
||||
|
||||
void DatabaseWidget::search()
|
||||
|
@ -76,6 +76,8 @@ public:
|
||||
bool isInEditMode() const;
|
||||
QList<int> splitterSizes() const;
|
||||
void setSplitterSizes(const QList<int>& sizes);
|
||||
QList<int> entryHeaderViewSizes() const;
|
||||
void setEntryViewHeaderSizes(const QList<int>& sizes);
|
||||
|
||||
Q_SIGNALS:
|
||||
void closeRequest();
|
||||
@ -89,6 +91,7 @@ Q_SIGNALS:
|
||||
void listModeActivated();
|
||||
void searchModeActivated();
|
||||
void splitterSizesChanged();
|
||||
void entryColumnSizesChanged();
|
||||
|
||||
public Q_SLOTS:
|
||||
void createEntry();
|
||||
|
@ -24,28 +24,16 @@ DatabaseWidgetStateSync::DatabaseWidgetStateSync(QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_activeDbWidget(Q_NULLPTR)
|
||||
{
|
||||
QVariantList variantList = config()->get("GUI/SplitterState").toList();
|
||||
Q_FOREACH (const QVariant& var, variantList) {
|
||||
bool ok;
|
||||
int size = var.toInt(&ok);
|
||||
if (ok) {
|
||||
m_splitterSizes.append(size);
|
||||
}
|
||||
else {
|
||||
m_splitterSizes.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_splitterSizes = variantToIntList(config()->get("GUI/SplitterState"));
|
||||
m_columnSizesList = variantToIntList(config()->get("GUI/EntryListColumnSizes"));
|
||||
m_columnSizesSearch = variantToIntList(config()->get("GUI/EntrySearchColumnSizes"));
|
||||
}
|
||||
|
||||
DatabaseWidgetStateSync::~DatabaseWidgetStateSync()
|
||||
{
|
||||
QVariantList variantList;
|
||||
Q_FOREACH (int size, m_splitterSizes) {
|
||||
variantList.append(size);
|
||||
}
|
||||
|
||||
config()->set("GUI/SplitterState", variantList);
|
||||
config()->set("GUI/SplitterState", intListToVariant(m_splitterSizes));
|
||||
config()->set("GUI/EntryListColumnSizes", intListToVariant(m_columnSizesList));
|
||||
config()->set("GUI/EntrySearchColumnSizes", intListToVariant(m_columnSizesSearch));
|
||||
}
|
||||
|
||||
void DatabaseWidgetStateSync::setActive(DatabaseWidget* dbWidget)
|
||||
@ -61,8 +49,35 @@ void DatabaseWidgetStateSync::setActive(DatabaseWidget* dbWidget)
|
||||
m_activeDbWidget->setSplitterSizes(m_splitterSizes);
|
||||
}
|
||||
|
||||
if (m_activeDbWidget->isGroupSelected()) {
|
||||
restoreListView();
|
||||
}
|
||||
else {
|
||||
restoreSearchView();
|
||||
}
|
||||
|
||||
connect(m_activeDbWidget, SIGNAL(splitterSizesChanged()),
|
||||
SLOT(updateSplitterSizes()));
|
||||
connect(m_activeDbWidget, SIGNAL(entryColumnSizesChanged()),
|
||||
SLOT(updateColumnSizes()));
|
||||
connect(m_activeDbWidget, SIGNAL(listModeActivated()),
|
||||
SLOT(restoreListView()));
|
||||
connect(m_activeDbWidget, SIGNAL(searchModeActivated()),
|
||||
SLOT(restoreSearchView()));
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWidgetStateSync::restoreListView()
|
||||
{
|
||||
if (!m_columnSizesList.isEmpty()) {
|
||||
m_activeDbWidget->setEntryViewHeaderSizes(m_columnSizesList);
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWidgetStateSync::restoreSearchView()
|
||||
{
|
||||
if (!m_columnSizesSearch.isEmpty()) {
|
||||
m_activeDbWidget->setEntryViewHeaderSizes(m_columnSizesSearch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,3 +85,44 @@ void DatabaseWidgetStateSync::updateSplitterSizes()
|
||||
{
|
||||
m_splitterSizes = m_activeDbWidget->splitterSizes();
|
||||
}
|
||||
|
||||
void DatabaseWidgetStateSync::updateColumnSizes()
|
||||
{
|
||||
if (m_activeDbWidget->isGroupSelected()) {
|
||||
m_columnSizesList = m_activeDbWidget->entryHeaderViewSizes();
|
||||
}
|
||||
else {
|
||||
m_columnSizesSearch = m_activeDbWidget->entryHeaderViewSizes();
|
||||
}
|
||||
}
|
||||
|
||||
QList<int> DatabaseWidgetStateSync::variantToIntList(const QVariant& variant)
|
||||
{
|
||||
QVariantList list = variant.toList();
|
||||
QList<int> result;
|
||||
|
||||
Q_FOREACH (const QVariant& var, list) {
|
||||
bool ok;
|
||||
int size = var.toInt(&ok);
|
||||
if (ok) {
|
||||
result.append(size);
|
||||
}
|
||||
else {
|
||||
result.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QVariant DatabaseWidgetStateSync::intListToVariant(const QList<int>& list)
|
||||
{
|
||||
QVariantList result;
|
||||
|
||||
Q_FOREACH (int value, list) {
|
||||
result.append(value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -31,14 +31,22 @@ public:
|
||||
|
||||
public Q_SLOTS:
|
||||
void setActive(DatabaseWidget* dbWidget);
|
||||
void restoreListView();
|
||||
void restoreSearchView();
|
||||
|
||||
private Q_SLOTS:
|
||||
void updateSplitterSizes();
|
||||
void updateColumnSizes();
|
||||
|
||||
private:
|
||||
static QList<int> variantToIntList(const QVariant& variant);
|
||||
static QVariant intListToVariant(const QList<int>& list);
|
||||
|
||||
DatabaseWidget* m_activeDbWidget;
|
||||
|
||||
QList<int> m_splitterSizes;
|
||||
QList<int> m_columnSizesList;
|
||||
QList<int> m_columnSizesSearch;
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_HEADERVIEWSYNC_H
|
||||
|
Loading…
Reference in New Issue
Block a user