diff options
| author | Tannin <devnull@localhost> | 2013-03-27 21:04:27 +0100 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2013-03-27 21:04:27 +0100 |
| commit | b4220cf2f4e1998299517490244a48f7ec2b0235 (patch) | |
| tree | 251c975507250eabd6c8a541b6c345cbf72288a7 /src/messagedialog.cpp | |
| parent | 10485e15e4de3e1a6c30733ad2d4850591d31509 (diff) | |
| parent | e0eb97922d5ef4a1448e76f13374ebfda7fda403 (diff) | |
Merge with branch1.0
Diffstat (limited to 'src/messagedialog.cpp')
| -rw-r--r-- | src/messagedialog.cpp | 121 |
1 files changed, 70 insertions, 51 deletions
diff --git a/src/messagedialog.cpp b/src/messagedialog.cpp index af89ee8d..4a1ef0d6 100644 --- a/src/messagedialog.cpp +++ b/src/messagedialog.cpp @@ -17,54 +17,73 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. */ -#include "messagedialog.h"
-#include "ui_messagedialog.h"
-#include <QTimer>
-#include <QResizeEvent>
-#include <Windows.h>
-
-MessageDialog::MessageDialog(const QString &text, QWidget *reference) :
- QDialog(reference),
- ui(new Ui::MessageDialog)
-{
- ui->setupUi(this);
- findChild<QLabel*>("message")->setText(text);
- this->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
- this->setFocusPolicy(Qt::NoFocus);
- this->setAttribute(Qt::WA_ShowWithoutActivating);
- QTimer::singleShot(1000 + (text.length() * 40), this, SLOT(hide()));
- if (reference != NULL) {
- QPoint position = reference->mapToGlobal(QPoint(reference->width() / 2, reference->height()));
- position.rx() -= this->width() / 2;
- position.ry() -= this->height() + 5;
- move(position);
- }
-}
-
-
-MessageDialog::~MessageDialog()
-{
- delete ui;
-}
-
-
-void MessageDialog::resizeEvent(QResizeEvent *event)
-{
- QWidget *par = parentWidget();
- if (par != NULL) {
- QPoint position = par->mapToGlobal(QPoint(par->width() / 2, par->height()));
- position.rx() -= event->size().width() / 2;
- position.ry() -= event->size().height() + 5;
- move(position);
- }
-}
-
-
-void MessageDialog::showMessage(const QString &text, QWidget *reference)
-{
- if (reference != NULL) {
- MessageDialog *dialog = new MessageDialog(text, reference);
- dialog->show();
- reference->activateWindow();
- }
-}
+#include "messagedialog.h" +#include "ui_messagedialog.h" +#include <QTimer> +#include <QResizeEvent> +#include <Windows.h> + +MessageDialog::MessageDialog(const QString &text, QWidget *reference) : + QDialog(reference), + ui(new Ui::MessageDialog) +{ + ui->setupUi(this); + + // very crude way to ensure no single word in the test is wider than the message window. ellide in the center if necessary + QFontMetrics metrics(ui->message->font()); + QString restrictedText; + QStringList lines = text.split("\n"); + foreach (const QString &line, lines) { + QString newLine; + QStringList words = line.split(" "); + foreach (const QString &word, words) { + if (word.length() > 10) { + newLine += "<span style=\"nobreak\">" + metrics.elidedText(word, Qt::ElideMiddle, ui->message->maximumWidth()) + "</span>"; + } else { + newLine += word; + } + newLine += " "; + } + restrictedText += newLine + "\n"; + } + + ui->message->setText(restrictedText); + this->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + this->setFocusPolicy(Qt::NoFocus); + this->setAttribute(Qt::WA_ShowWithoutActivating); + QTimer::singleShot(1000 + (text.length() * 40), this, SLOT(hide())); + if (reference != NULL) { + QPoint position = reference->mapToGlobal(QPoint(reference->width() / 2, reference->height())); + position.rx() -= this->width() / 2; + position.ry() -= this->height() + 5; + move(position); + } +} + + +MessageDialog::~MessageDialog() +{ + delete ui; +} + + +void MessageDialog::resizeEvent(QResizeEvent *event) +{ + QWidget *par = parentWidget(); + if (par != NULL) { + QPoint position = par->mapToGlobal(QPoint(par->width() / 2, par->height())); + position.rx() -= event->size().width() / 2; + position.ry() -= event->size().height() + 5; + move(position); + } +} + + +void MessageDialog::showMessage(const QString &text, QWidget *reference) +{ + if (reference != NULL) { + MessageDialog *dialog = new MessageDialog(text, reference); + dialog->show(); + reference->activateWindow(); + } +} |
