1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/* ============================================================
* File : dmessagebox.cpp
* Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
* Date : 2003-02-22
* Description :
*
* Copyright 2003 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
* Update : 09/23/2003 - Gilles Caulier <caulier.gilles@free.fr>
* Center the dialog box on the desktop.
* Improve i18n messages.
* 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 2, 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.
*
* ============================================================ */
// Qt
#include <qapplication.h>
#include <qhbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpixmap.h>
#include <qpushbutton.h>
#include <qtextedit.h>
// KDE
#include <klocale.h>
#include <kapplication.h>
#include <kiconloader.h>
// Local
#include "dmessagebox.h"
namespace KIPIKameraKlientPlugin
{
DMessageBox* DMessageBox::s_instance = 0;
DMessageBox::DMessageBox() : QWidget(0, 0, WShowModal | WStyle_DialogBorder| WDestructiveClose) {
setCaption(i18n("Error"));
s_instance = this;
count_ = 0;
QGridLayout *grid = new QGridLayout(this, 1, 1, 6, 11);
// ----------------------------------------------------
QHBox *hbox = new QHBox(this);
hbox->setSpacing(5);
QPixmap pix = KApplication::kApplication()->iconLoader()->loadIcon("error",
KIcon::NoGroup,
KIcon::SizeMedium,
KIcon::DefaultState,
0, true);
QLabel *pixLabel = new QLabel(hbox);
pixLabel->setPixmap(pix);
pixLabel->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
msgBox_ = new QLabel(hbox);
msgBox_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
grid->addMultiCellWidget(hbox, 0, 0, 0, 2);
// ---------------------------------------------------
extraMsgBox_ = new QTextEdit(this);
extraMsgBox_->setReadOnly(true);
grid->addMultiCellWidget(extraMsgBox_, 1, 1, 0, 2);
extraMsgBox_->hide();
// ---------------------------------------------------
QPushButton *okButton = new QPushButton(i18n("&OK"), this);
grid->addWidget(okButton, 2, 1);
// ---------------------------------------------------
grid->addItem(new QSpacerItem(5, 10, QSizePolicy::Expanding, QSizePolicy::Minimum), 2, 0);
grid->addItem(new QSpacerItem(5, 10, QSizePolicy::Expanding, QSizePolicy::Minimum), 2, 2);
// ---------------------------------------------------
connect(okButton, SIGNAL(clicked()), this, SLOT(slotOkClicked()));
int W=500;
int H=400;
move(QApplication::desktop()->width ()/2-(W/2), QApplication::desktop()->height()/2-(H/2));
}
DMessageBox::~DMessageBox() {
s_instance = 0;
}
void DMessageBox::appendMsg(const QString& msg) {
if (count_ == 0) {
mainMsg_ = msg;
msgBox_->setText(msg);
} else {
QString text(i18n("More errors occurred and are shown below:"));
msgBox_->setText(text);
extraMsgBox_->append(msg);
if (extraMsgBox_->isHidden()) {
extraMsgBox_->show();
}
}
count_++;
}
void DMessageBox::slotOkClicked() {
close();
}
void DMessageBox::showMsg(const QString& msg) {
DMessageBox* msgBox = DMessageBox::s_instance;
if (!msgBox) {
msgBox = new DMessageBox;
}
msgBox->appendMsg(msg);
if (msgBox->isHidden()) {
msgBox->show();
}
}
} // NameSpace KIPIKameraKlientPlugin
#include "dmessagebox.moc"
|