From: Lukas Hrazky Date: Sun, 25 Jul 2010 12:55:49 +0000 (+0200) Subject: display buttons in overwrite dialog in 2 columns X-Git-Tag: v0.1.2~2 X-Git-Url: http://vcs.maemo.org/git/?p=case;a=commitdiff_plain;h=f8090904258961a9f9c3810214de48f65134ba16 display buttons in overwrite dialog in 2 columns By implementing a custom dialog class. Signed-off-by: Lukas Hrazky --- diff --git a/case.pro b/case.pro index 26bd047..2a3833a 100644 --- a/case.pro +++ b/case.pro @@ -20,11 +20,13 @@ HEADERS += src/addressbar.h \ src/case.h \ src/filelist.h \ src/fileoperator.h \ - src/pane.h + src/pane.h \ + src/dialog.h SOURCES += src/addressbar.cpp \ src/button.cpp \ src/case.cpp \ src/filelist.cpp \ src/fileoperator.cpp \ src/main.cpp \ - src/pane.cpp + src/pane.cpp \ + src/dialog.cpp diff --git a/src/dialog.cpp b/src/dialog.cpp new file mode 100644 index 0000000..8af4fba --- /dev/null +++ b/src/dialog.cpp @@ -0,0 +1,81 @@ +// case - file manager for N900 +// Copyright (C) 2010 Lukas Hrazky +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + + +#include "dialog.h" + +#include + + +Dialog::Dialog(QWidget *parent) : + QDialog(parent), + text(new QLabel()), + buttons1(new QDialogButtonBox(Qt::Vertical)), + buttons2(new QDialogButtonBox(Qt::Vertical)) +{ + text->setWordWrap(true); + text->setAlignment(Qt::AlignTop | Qt::AlignLeft); + + QHBoxLayout *layout = new QHBoxLayout(); + setLayout(layout); + layout->addWidget(text); + + connect(buttons1, SIGNAL(clicked(QAbstractButton*)), this, SLOT(finishUp(QAbstractButton*))); + connect(buttons2, SIGNAL(clicked(QAbstractButton*)), this, SLOT(finishUp(QAbstractButton*))); +} + + +QPushButton *Dialog::addButtonFirst(const QString &text, QDialogButtonBox::ButtonRole role) { + return buttons1->addButton(text, role); +} + + +QPushButton *Dialog::addButtonFirst(const QDialogButtonBox::StandardButton button) { + return buttons1->addButton(button); +} + + +QPushButton *Dialog::addButtonSecond(const QString &text, QDialogButtonBox::ButtonRole role) { + return buttons2->addButton(text, role); +} + + +QPushButton *Dialog::addButtonSecond(const QDialogButtonBox::StandardButton button) { + return buttons2->addButton(button); +} + + +void Dialog::setText(const QString &t) { + text->setText(t); +} + + +void Dialog::finishUp(QAbstractButton *button) { + clickedButton = button; + done(0); +} + + +int Dialog::exec() { + QHBoxLayout *l = qobject_cast(layout()); + if (buttons1->buttons().size()) { + l->addWidget(buttons1, 0, Qt::AlignTop); + } + if (buttons2->buttons().size()) { + l->addWidget(buttons2, 0, Qt::AlignTop); + } + return QDialog::exec(); +} diff --git a/src/dialog.h b/src/dialog.h new file mode 100644 index 0000000..bc383d6 --- /dev/null +++ b/src/dialog.h @@ -0,0 +1,48 @@ +// case - file manager for N900 +// Copyright (C) 2010 Lukas Hrazky +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + + +#ifndef DIALOG_H +#define DIALOG_H + +#include +#include +#include + + +class Dialog : public QDialog { + Q_OBJECT + +public: + explicit Dialog(QWidget *parent = 0); + QPushButton *addButtonFirst(const QString &text, QDialogButtonBox::ButtonRole role); + QPushButton *addButtonFirst(const QDialogButtonBox::StandardButton button); + QPushButton *addButtonSecond(const QString &text, QDialogButtonBox::ButtonRole role); + QPushButton *addButtonSecond(const QDialogButtonBox::StandardButton button); + + QAbstractButton *clickedButton; + +public slots: + void finishUp(QAbstractButton *button); + void setText(const QString &t); + int exec(); + +protected: + QLabel *text; + QDialogButtonBox *buttons1, *buttons2; +}; + +#endif // DIALOG_H diff --git a/src/fileoperator.cpp b/src/fileoperator.cpp index 67c5204..fc826b9 100644 --- a/src/fileoperator.cpp +++ b/src/fileoperator.cpp @@ -23,6 +23,8 @@ #include #include +#include "dialog.h" + #include #include #include @@ -218,40 +220,40 @@ void FileOperator::showOverwritePrompt( const QString &fileName, const bool dirOverDir) { - QMessageBox msgBox; - msgBox.addButton(QMessageBox::Cancel); - QAbstractButton *yesButton = msgBox.addButton(QMessageBox::Yes); - QAbstractButton *yesToAllButton = msgBox.addButton(QMessageBox::YesToAll); - QAbstractButton *noButton = msgBox.addButton(QMessageBox::No); - QAbstractButton *noToAllButton = msgBox.addButton(QMessageBox::NoToAll); - QAbstractButton *abortButton = msgBox.addButton(tr("Abort"), QMessageBox::DestructiveRole); + Dialog msgBox; + msgBox.addButtonFirst(QDialogButtonBox::Cancel); + QAbstractButton *yesButton = msgBox.addButtonFirst(QDialogButtonBox::Yes); + QAbstractButton *yesToAllButton = msgBox.addButtonFirst(QDialogButtonBox::YesToAll); + QAbstractButton *noButton = msgBox.addButtonSecond(QDialogButtonBox::No); + QAbstractButton *noToAllButton = msgBox.addButtonSecond(QDialogButtonBox::NoToAll); + QAbstractButton *abortButton = msgBox.addButtonSecond(tr("Abort"), QDialogButtonBox::DestructiveRole); QAbstractButton *askButton = 0; QAbstractButton *skipDirButton = 0; if (dirOverDir) { msgBox.setText(tr("Directory %1 already exists. Overwrite the files inside?") .arg(FileOperator::shortenPath(fileName))); - askButton = msgBox.addButton(tr("Ask"), QMessageBox::AcceptRole); - skipDirButton = msgBox.addButton(tr("Skip"), QMessageBox::NoRole); + askButton = msgBox.addButtonFirst(tr("Ask"), QDialogButtonBox::AcceptRole); + skipDirButton = msgBox.addButtonSecond(tr("Skip"), QDialogButtonBox::NoRole); } else { msgBox.setText(tr("File %1 already exists. Overwrite?").arg(FileOperator::shortenPath(fileName))); } msgBox.exec(); - if (msgBox.clickedButton() == abortButton) { + if (msgBox.clickedButton == abortButton) { manipulator->setResponse(ABORT); - } else if (msgBox.clickedButton() == yesButton) { + } else if (msgBox.clickedButton == yesButton) { manipulator->setResponse(OVERWRITE); - } else if (msgBox.clickedButton() == yesToAllButton) { + } else if (msgBox.clickedButton == yesToAllButton) { manipulator->setResponse(OVERWRITE, true); - } else if (msgBox.clickedButton() == noButton) { + } else if (msgBox.clickedButton == noButton) { manipulator->setResponse(KEEP); - } else if (msgBox.clickedButton() == noToAllButton) { + } else if (msgBox.clickedButton == noToAllButton) { manipulator->setResponse(KEEP, true); - } else if (msgBox.clickedButton() == askButton) { + } else if (msgBox.clickedButton == askButton) { manipulator->setResponse(NONE, true); - } else if (msgBox.clickedButton() == skipDirButton) { + } else if (msgBox.clickedButton == skipDirButton) { manipulator->setResponse(SKIP_DIR); } } @@ -327,7 +329,7 @@ FileManipulatorThread::FileManipulatorThread(const QFileInfoList files, QDir des FileManipulatorThread::~FileManipulatorThread() { - if (progressBar->value() < progressBar->maximum()) { + if (!abort && progressBar->value() < progressBar->maximum()) { std::cout << "WARNING: deleting a progressbar which's value " << progressBar->value() << " has not reached maximum of " << progressBar->maximum() << std::endl; }