Works on message boxes.

This commit is contained in:
Martin Rotter 2014-01-22 16:59:39 +01:00
parent 5ae43964cc
commit 56dd8c66d5
13 changed files with 131 additions and 70 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View file

@ -13,7 +13,6 @@
#include <QTextEdit> #include <QTextEdit>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QToolButton> #include <QToolButton>
#include "QComboBox"
FormCategoryDetails::FormCategoryDetails(FeedsModel *model, QWidget *parent) FormCategoryDetails::FormCategoryDetails(FeedsModel *model, QWidget *parent)
@ -24,16 +23,23 @@ FormCategoryDetails::FormCategoryDetails(FeedsModel *model, QWidget *parent)
loadCategories(model->allCategories().values(), loadCategories(model->allCategories().values(),
model->rootItem()); model->rootItem());
connect(m_ui->m_buttonBox, SIGNAL(accepted()), createConnections();
this, SLOT(apply()));
connect(m_ui->m_txtTitle->lineEdit(), SIGNAL(textChanged(QString)), // Initialize text boxes.
this, SLOT(onTitleChanged(QString))); onTitleChanged(QString());
} }
FormCategoryDetails::~FormCategoryDetails() { FormCategoryDetails::~FormCategoryDetails() {
qDebug("Destroying FormCategoryDetails instance."); qDebug("Destroying FormCategoryDetails instance.");
} }
void FormCategoryDetails::createConnections() {
connect(m_ui->m_buttonBox, SIGNAL(accepted()),
this, SLOT(apply()));
connect(m_ui->m_txtTitle->lineEdit(), SIGNAL(textChanged(QString)),
this, SLOT(onTitleChanged(QString)));
}
void FormCategoryDetails::setEditableCategory(FeedsModelCategory *editable_category) { void FormCategoryDetails::setEditableCategory(FeedsModelCategory *editable_category) {
m_editableCategory = editable_category; m_editableCategory = editable_category;
@ -86,7 +92,7 @@ void FormCategoryDetails::apply() {
} }
void FormCategoryDetails::onTitleChanged(const QString &new_title){ void FormCategoryDetails::onTitleChanged(const QString &new_title){
if (m_ui->m_txtTitle->lineEdit()->text().size() >= MIN_CATEGORY_NAME_LENGTH) { if (new_title.size() >= MIN_CATEGORY_NAME_LENGTH) {
m_ui->m_txtTitle->setStatus(LineEditWithStatus::Ok, tr("This category name is ok.")); m_ui->m_txtTitle->setStatus(LineEditWithStatus::Ok, tr("This category name is ok."));
} }
else { else {

View file

@ -32,6 +32,9 @@ class FormCategoryDetails : public QDialog {
// Destructor. // Destructor.
virtual ~FormCategoryDetails(); virtual ~FormCategoryDetails();
// Creates needed connections.
void createConnections();
public slots: public slots:
// Start dialog execution. If result is QDialog::Accepted, // Start dialog execution. If result is QDialog::Accepted,
// then output_item contains added or edited category // then output_item contains added or edited category

View file

@ -199,6 +199,10 @@ bool FormSettings::doSaveCheck() {
resulting_information.replaceInStrings(QRegExp("^"), resulting_information.replaceInStrings(QRegExp("^"),
QString::fromUtf8("")); QString::fromUtf8(""));
// TODO: dedit qmessagebox
// MessageBox a tam pretizit setIcon
// a setStandardButtons atp
// Some critical errors occurred, display warnings. // Some critical errors occurred, display warnings.
QPointer<QMessageBox> msg_error = new QMessageBox(this); QPointer<QMessageBox> msg_error = new QMessageBox(this);
msg_error.data()->setText(tr("Some critical settings are not set. You must fix these settings in order confirm new settings.")); msg_error.data()->setText(tr("Some critical settings are not set. You must fix these settings in order confirm new settings."));

View file

@ -15,9 +15,9 @@ LineEditWithStatus::LineEditWithStatus(QWidget *parent)
// TODO: nastavit korektni ikony // TODO: nastavit korektni ikony
m_iconInformation = IconThemeFactory::instance()->fromTheme("help-about"); m_iconInformation = IconThemeFactory::instance()->fromTheme("help-about");
m_iconWarning = IconThemeFactory::instance()->fromTheme("application-exit"); m_iconWarning = IconThemeFactory::instance()->fromTheme("dialog-warning");
m_iconError = IconThemeFactory::instance()->fromTheme("application-exit"); m_iconError = IconThemeFactory::instance()->fromTheme("dialog-error");
m_iconOk = IconThemeFactory::instance()->fromTheme("application-exit"); m_iconOk = IconThemeFactory::instance()->fromTheme("dialog-yes");
// Set correct size for the tool button. // Set correct size for the tool button.
int txt_input_height = m_txtInput->sizeHint().height(); int txt_input_height = m_txtInput->sizeHint().height();

View file

@ -1,49 +1,89 @@
#include "gui/messagebox.h" #include "gui/messagebox.h"
#include "gui/iconthemefactory.h"
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QtGlobal> #include <QtGlobal>
#include <QPushButton> #include <QPushButton>
#include <QDialogButtonBox>
#include <QStyle>
#include <QApplication>
MessageBox::MessageBox() { MessageBox::MessageBox() {
} }
QMessageBox::StandardButton MessageBox:: showMessageBox(QWidget *parent, void MessageBox::iconify(QDialogButtonBox *button_box) {
QMessageBox::Icon icon, foreach (QAbstractButton *button, button_box->buttons()) {
const QString &title, button->setIcon(iconForRole(button_box->standardButton(button)));
const QString &text, }
QMessageBox::StandardButtons buttons, }
QMessageBox::StandardButton defaultButton) {
QMessageBox msgBox(icon, title, text, QMessageBox::NoButton, parent); QIcon MessageBox::iconForRole(QDialogButtonBox::StandardButton button) {
QDialogButtonBox *buttonBox = msgBox.findChild<QDialogButtonBox*>(); switch (button) {
case QMessageBox::Ok:
uint mask = QMessageBox::FirstButton; return IconThemeFactory::instance()->fromTheme("dialog-ok");
while (mask <= QMessageBox::LastButton) {
uint sb = buttons & mask; case QMessageBox::Yes:
mask <<= 1; case QMessageBox::YesToAll:
if (!sb) return IconThemeFactory::instance()->fromTheme("dialog-yes");
continue;
case QMessageBox::No:
// TODO: tady podle hodnoty masky switchnout prave pridanej button a podle toho mu dat ikonu. case QMessageBox::NoToAll:
// neco jako return IconThemeFactory::instance()->fromTheme("dialog-no");
switch (mask) {
case QMessageBox::Ok: default:
// TODO: nastav ikonu "ok" return QIcon();
break; }
default: }
break;
} QIcon MessageBox::iconForStatus(QMessageBox::Icon status) {
switch (status) {
QPushButton *button = msgBox.addButton((QMessageBox::StandardButton)sb); case QMessageBox::Information:
return IconThemeFactory::instance()->fromTheme("help-about");
// Choose the first accept role as the default
if (msgBox.defaultButton()) case QMessageBox::Warning:
continue; return IconThemeFactory::instance()->fromTheme("dialog-warning");
if ((defaultButton == QMessageBox::NoButton && buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
|| (defaultButton != QMessageBox::NoButton && sb == uint(defaultButton))) case QMessageBox::Critical:
msgBox.setDefaultButton(button); return IconThemeFactory::instance()->fromTheme("dialog-error");
case QMessageBox::Question:
return IconThemeFactory::instance()->fromTheme("dialog-question");
case QMessageBox::NoIcon:
default:
return QIcon();
}
}
QMessageBox::StandardButton MessageBox::show(QWidget *parent,
QMessageBox::Icon icon,
const QString &title,
const QString &text,
QMessageBox::StandardButtons buttons,
QMessageBox::StandardButton defaultButton) {
// Create and find needed components.
QMessageBox msg_box(parent);
QDialogButtonBox *button_box = msg_box.findChild<QDialogButtonBox*>();
// Initialize message box properties.
msg_box.setWindowTitle(title);
msg_box.setText(text);
msg_box.setStandardButtons(buttons);
msg_box.setDefaultButton(defaultButton);
iconify(button_box);
// Setup status icon.
int icon_size = qApp->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, &msg_box);
msg_box.setIconPixmap(iconForStatus(icon).pixmap(icon_size,
icon_size));
// Display it.
if (msg_box.exec() == -1) {
return QMessageBox::Cancel;
}
else {
return msg_box.standardButton(msg_box.clickedButton());
} }
if (msgBox.exec() == -1)
return QMessageBox::Cancel;
return msgBox.standardButton(msgBox.clickedButton());
} }

View file

@ -2,6 +2,7 @@
#define MESSAGEBOX_H #define MESSAGEBOX_H
#include <QMessageBox> #include <QMessageBox>
#include <QDialogButtonBox>
class MessageBox { class MessageBox {
@ -15,11 +16,19 @@ class MessageBox {
// se spravnejma parametrama // se spravnejma parametrama
// a napsat taky metodu iconifyMessageButtonBox(qmessabebuttonbox) // a napsat taky metodu iconifyMessageButtonBox(qmessabebuttonbox)
// ktera nahraje do daneho boxu aktualni ikony // ktera nahraje do daneho boxu aktualni ikony
static QMessageBox::StandardButton showMessageBox(QWidget *parent,
QMessageBox::Icon icon, // Performs icon replacements for given button box.
const QString& title, const QString& text, static void iconify(QDialogButtonBox *button_box);
QMessageBox::StandardButtons buttons,
QMessageBox::StandardButton defaultButton); // Returns icons for standard roles/statuses.
static QIcon iconForRole(QDialogButtonBox::StandardButton button);
static QIcon iconForStatus(QMessageBox::Icon status);
static QMessageBox::StandardButton show(QWidget *parent,
QMessageBox::Icon icon,
const QString& title, const QString& text,
QMessageBox::StandardButtons buttons,
QMessageBox::StandardButton defaultButton);
}; };
#endif // MESSAGEBOX_H #endif // MESSAGEBOX_H

View file

@ -9,7 +9,6 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QScrollBar> #include <QScrollBar>
#include <QMenu> #include <QMenu>
#include <QMessageBox>
#include <QProcess> #include <QProcess>
#include <QDesktopServices> #include <QDesktopServices>
@ -222,28 +221,25 @@ void MessagesView::openSelectedSourceArticlesExternally() {
"%1").toString(); "%1").toString();
if (browser.isEmpty() || arguments.isEmpty()) { if (browser.isEmpty() || arguments.isEmpty()) {
MessageBox::showMessageBox(this, QMessageBox::Information, MessageBox::show(this,
"aa", "bb", QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Critical,
tr("External browser not set"),
tr("External browser is not set, head to application settings and set it up to use this feature."),
QMessageBox::Ok, QMessageBox::Ok);
QMessageBox::critical(this,
tr("External browser not set"),
tr("External browser is not set, head to application settings and set it up to use this feature."),
QMessageBox::Ok);
return; return;
} }
foreach (const QModelIndex &index, selectionModel()->selectedRows()) { foreach (const QModelIndex &index, selectionModel()->selectedRows()) {
QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()).m_url; QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()).m_url;
#if defined(Q_OS_LINUX)
if (!QProcess::startDetached(browser + ' ' + arguments.arg(link))) {
#else
if (!QProcess::startDetached('\"' + browser + "\" \"" + arguments.arg(link) + "\"")) { if (!QProcess::startDetached('\"' + browser + "\" \"" + arguments.arg(link) + "\"")) {
#endif MessageBox::show(this,
QMessageBox::critical(this, QMessageBox::Critical,
tr("Problem with starting external web browser"), tr("Problem with starting external web browser"),
tr("External web browser could not be started."), tr("External web browser could not be started."),
QMessageBox::Ok); QMessageBox::Ok,
QMessageBox::Ok);
return; return;
} }
} }
@ -254,9 +250,12 @@ void MessagesView::openSelectedSourceMessagesInternally() {
Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()); Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row());
if (message.m_url.isEmpty()) { if (message.m_url.isEmpty()) {
QMessageBox::warning(this, MessageBox::show(this,
tr("Meesage without URL"), QMessageBox::Warning,
tr("Message '%s' does not contain URL.").arg(message.m_title)); tr("Meesage without URL"),
tr("Message '%s' does not contain URL.").arg(message.m_title),
QMessageBox::Ok,
QMessageBox::Ok);
} }
else { else {
emit openLinkNewTab(message.m_url); emit openLinkNewTab(message.m_url);