Skip to content

Commit

Permalink
Refactor attachment widget: remove rename functionality and reorder b…
Browse files Browse the repository at this point in the history
…uttons on the widget
  • Loading branch information
w15dev committed Jan 11, 2025
1 parent 23c567e commit 207a15f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 34 deletions.
22 changes: 13 additions & 9 deletions src/gui/entry/EntryAttachmentsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ EntryAttachmentsWidget::EntryAttachmentsWidget(QWidget* parent)
connect(m_ui->newAttachmentButton, SIGNAL(clicked()), SLOT(newAttachments()));
connect(m_ui->previewAttachmentButton, SIGNAL(clicked()), SLOT(previewSelectedAttachment()));
connect(m_ui->removeAttachmentButton, SIGNAL(clicked()), SLOT(removeSelectedAttachments()));
connect(m_ui->renameAttachmentButton, SIGNAL(clicked()), SLOT(renameSelectedAttachments()));

updateButtonsVisible();
updateButtonsEnabled();
Expand Down Expand Up @@ -248,12 +247,6 @@ void EntryAttachmentsWidget::removeSelectedAttachments()
}
}

void EntryAttachmentsWidget::renameSelectedAttachments()
{
Q_ASSERT(m_entryAttachments);
m_ui->attachmentsView->edit(m_ui->attachmentsView->selectionModel()->selectedIndexes().first());
}

void EntryAttachmentsWidget::saveSelectedAttachments()
{
Q_ASSERT(m_entryAttachments);
Expand Down Expand Up @@ -358,19 +351,30 @@ void EntryAttachmentsWidget::updateButtonsEnabled()
m_ui->addAttachmentButton->setEnabled(!m_readOnly);
m_ui->newAttachmentButton->setEnabled(!m_readOnly);
m_ui->removeAttachmentButton->setEnabled(hasSelection && !m_readOnly);
m_ui->renameAttachmentButton->setEnabled(hasSelection && !m_readOnly);

m_ui->saveAttachmentButton->setEnabled(hasSelection);
m_ui->previewAttachmentButton->setEnabled(hasSelection);
m_ui->openAttachmentButton->setEnabled(hasSelection);

updateSpacers();
}

void EntryAttachmentsWidget::updateSpacers()
{
if (m_buttonsVisible && !m_readOnly) {
m_ui->previewVSpacer->changeSize(20, 40, QSizePolicy::Fixed, QSizePolicy::Expanding);
} else {
m_ui->previewVSpacer->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
}
}

void EntryAttachmentsWidget::updateButtonsVisible()
{
m_ui->addAttachmentButton->setVisible(m_buttonsVisible && !m_readOnly);
m_ui->newAttachmentButton->setVisible(m_buttonsVisible && !m_readOnly);
m_ui->removeAttachmentButton->setVisible(m_buttonsVisible && !m_readOnly);
m_ui->renameAttachmentButton->setVisible(m_buttonsVisible && !m_readOnly);

updateSpacers();
}

bool EntryAttachmentsWidget::insertAttachments(const QStringList& filenames, QString& errorMessage)
Expand Down
3 changes: 2 additions & 1 deletion src/gui/entry/EntryAttachmentsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ private slots:
void newAttachments();
void previewSelectedAttachment();
void removeSelectedAttachments();
void renameSelectedAttachments();
void saveSelectedAttachments();
void openAttachment(const QModelIndex& index);
void openSelectedAttachments();
Expand All @@ -69,6 +68,8 @@ private slots:
void attachmentModifiedExternally(const QString& key, const QString& filePath);

private:
void updateSpacers();

bool insertAttachments(const QStringList& fileNames, QString& errorMessage);

QStringList confirmAttachmentSelection(const QStringList& filenames);
Expand Down
64 changes: 40 additions & 24 deletions src/gui/entry/EntryAttachmentsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>337</width>
<height>294</height>
<height>258</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -38,7 +38,7 @@
</item>
<item>
<widget class="QWidget" name="actionsWidget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1,0,0,0,1,0,0">
<property name="leftMargin">
<number>0</number>
</property>
Expand Down Expand Up @@ -75,30 +75,17 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="removeAttachmentButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="accessibleName">
<string>Remove selected attachment</string>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="renameAttachmentButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="accessibleName">
<string>Rename selected attachment</string>
<spacer name="previewVSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="text">
<string>Rename</string>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</widget>
</spacer>
</item>
<item>
<widget class="QPushButton" name="previewAttachmentButton">
Expand Down Expand Up @@ -149,6 +136,35 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="removeAttachmentButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="accessibleName">
<string>Remove selected attachment</string>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 207a15f

Please sign in to comment.