diff --git a/src/gui/EditWidget.cpp b/src/gui/EditWidget.cpp index b3d9842b..c2f9551c 100644 --- a/src/gui/EditWidget.cpp +++ b/src/gui/EditWidget.cpp @@ -25,6 +25,8 @@ EditWidget::EditWidget(QWidget* parent) m_ui->setupUi(this); setReadOnly(false); + m_ui->messageWidget->setHidden(true); + QFont headerLabelFont = m_ui->headerLabel->font(); headerLabelFont.setBold(true); headerLabelFont.setPointSize(headerLabelFont.pointSize() + 2); @@ -86,3 +88,25 @@ bool EditWidget::readOnly() const { return m_readOnly; } + +void EditWidget::showMessageError(const QString& text) +{ + m_ui->messageWidget->showMessageError(text); +} + +void EditWidget::showMessageWarning(const QString& text) +{ + m_ui->messageWidget->showMessageWarning(text); +} + +void EditWidget::showMessageInformation(const QString& text) +{ + m_ui->messageWidget->showMessageInformation(text); +} + +void EditWidget::hideMessage() +{ + if (m_ui->messageWidget->isVisible()) { + m_ui->messageWidget->animatedHide(); + } +} diff --git a/src/gui/EditWidget.h b/src/gui/EditWidget.h index c5f507ac..97dfda88 100644 --- a/src/gui/EditWidget.h +++ b/src/gui/EditWidget.h @@ -48,6 +48,12 @@ Q_SIGNALS: void accepted(); void rejected(); +protected: + void showMessageError(const QString& text); + void showMessageWarning(const QString& text); + void showMessageInformation(const QString& text); + void hideMessage(); + private: const QScopedPointer m_ui; bool m_readOnly; diff --git a/src/gui/EditWidget.ui b/src/gui/EditWidget.ui index 3891007a..05b06b90 100644 --- a/src/gui/EditWidget.ui +++ b/src/gui/EditWidget.ui @@ -11,6 +11,9 @@ + + + @@ -58,6 +61,12 @@ + + MessageWidget + QWidget +
gui/MessageWidget.h
+ 1 +
CategoryListWidget QListWidget diff --git a/src/gui/MessageWidget.cpp b/src/gui/MessageWidget.cpp index 1e6d0604..19badfea 100644 --- a/src/gui/MessageWidget.cpp +++ b/src/gui/MessageWidget.cpp @@ -33,6 +33,11 @@ void MessageWidget::showMessageWarning(const QString& text) showMessage(text, MessageType::Warning); } +void MessageWidget::showMessageInformation(const QString& text) +{ + showMessage(text, MessageType::Information); +} + void MessageWidget::showMessagePositive(const QString& text) { showMessage(text, MessageType::Positive); diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index f2372a0d..c56f7023 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -395,12 +395,13 @@ void EditEntryWidget::saveEntry() { if (m_history) { clear(); + hideMessage(); Q_EMIT editFinished(false); return; } if (!passwordsEqual()) { - MessageBox::warning(this, tr("Error"), tr("Different passwords supplied.")); + showMessageError(tr("Different passwords supplied.")); return; } @@ -474,6 +475,7 @@ void EditEntryWidget::cancel() { if (m_history) { clear(); + hideMessage(); Q_EMIT editFinished(false); return; } @@ -497,6 +499,7 @@ void EditEntryWidget::clear() m_autoTypeAssoc->clear(); m_historyModel->clear(); m_iconsWidget->reset(); + hideMessage(); } bool EditEntryWidget::hasBeenModified() const @@ -630,15 +633,13 @@ void EditEntryWidget::insertAttachment() QFile file(filename); if (!file.open(QIODevice::ReadOnly)) { - MessageBox::warning(this, tr("Error"), - tr("Unable to open file").append(":\n").append(file.errorString())); + showMessageError(tr("Unable to open file").append(":\n").append(file.errorString())); return; } QByteArray data; if (!Tools::readAllFromDevice(&file, data)) { - MessageBox::warning(this, tr("Error"), - tr("Unable to open file").append(":\n").append(file.errorString())); + showMessageError(tr("Unable to open file").append(":\n").append(file.errorString())); return; } @@ -665,13 +666,11 @@ void EditEntryWidget::saveCurrentAttachment() QFile file(savePath); if (!file.open(QIODevice::WriteOnly)) { - MessageBox::warning(this, tr("Error"), - tr("Unable to save the attachment:\n").append(file.errorString())); + showMessageError(tr("Unable to save the attachment:\n").append(file.errorString())); return; } if (file.write(attachmentData) != attachmentData.size()) { - MessageBox::warning(this, tr("Error"), - tr("Unable to save the attachment:\n").append(file.errorString())); + showMessageError(tr("Unable to save the attachment:\n").append(file.errorString())); return; } } @@ -692,14 +691,12 @@ void EditEntryWidget::openAttachment(const QModelIndex& index) QTemporaryFile* file = new QTemporaryFile(tmpFileTemplate, this); if (!file->open()) { - MessageBox::warning(this, tr("Error"), - tr("Unable to save the attachment:\n").append(file->errorString())); + showMessageError(tr("Unable to save the attachment:\n").append(file->errorString())); return; } if (file->write(attachmentData) != attachmentData.size()) { - MessageBox::warning(this, tr("Error"), - tr("Unable to save the attachment:\n").append(file->errorString())); + showMessageError(tr("Unable to save the attachment:\n").append(file->errorString())); return; }