Replace MessageBox Dialog with inline MessageWidget in

EditWidget and in UnlockDatabaseWidget.
Add missing method to show Information Message.
This commit is contained in:
Pedro Alves 2015-01-20 01:27:56 +00:00 committed by Janek Bevendorff
parent 8fa070f01c
commit c2826bb1af
No known key found for this signature in database
GPG Key ID: CFEC2F6850BFFA53
5 changed files with 54 additions and 13 deletions

View File

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

View File

@ -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<Ui::EditWidget> m_ui;
bool m_readOnly;

View File

@ -11,6 +11,9 @@
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="MessageWidget" name="messageWidget" native="true"/>
</item>
<item>
<widget class="QLabel" name="headerLabel">
<property name="text">
@ -58,6 +61,12 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>MessageWidget</class>
<extends>QWidget</extends>
<header>gui/MessageWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>CategoryListWidget</class>
<extends>QListWidget</extends>

View File

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

View File

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