27 #include <QHBoxLayout>
29 #include <QPushButton>
30 #include <QCloseEvent>
33 #include <QMessageBox>
36 #include "core/common/WLogger.h"
38 #include "guiElements/WScaleLabel.h"
40 #include "WMainWindow.h"
41 #include "WIconManager.h"
43 #include "WQtMessagePopup.h"
45 #define OUTERMARGIN 10
50 QDialog( parent, Qt::Popup | Qt::FramelessWindowHint ),
59 setWindowRole(
"MessagePopup" );
62 setWindowModality( Qt::NonModal );
64 QString borderColor =
"red";
65 QString titlePrefix =
"";
69 titleLabel->
setText( titlePrefix + title );
70 QFontMetrics fm( titleLabel->fontMetrics() );
71 int textHeight = fm.height();
74 unsigned int w = std::min( parent->width() - ( 2 * OUTERMARGIN ), MAXWIDTH );
75 unsigned int h = textHeight + BORDERWIDTH + BORDERWIDTH;
83 borderColor =
"#f44141";
84 titlePrefix =
"Error: ";
87 borderColor =
"#ffa200";
88 titlePrefix =
"Warning: ";
91 borderColor =
"#40aca0";
92 titlePrefix =
"Info: ";
96 borderColor =
"#7d729c";
97 titlePrefix =
"Debug: ";
103 "QDialog#popupDialog{"
104 "background: #222222;"
105 "border-style: solid;"
106 "border-width: " + QString::number( BORDERWIDTH ) +
"px;"
107 "border-color: " + borderColor +
";"
110 "QWidget#popupDialogTitle{"
111 "background: " + borderColor +
";"
116 "QLabel#popupDialogTitle{"
117 "background: " + borderColor +
";"
122 "QLabel#popupDialogMessage{"
123 "background: #222222;"
127 "QPushButton#popupDialogButton{"
128 "border-style: none;"
129 "background: " + borderColor +
";"
135 setContentsMargins( 0, 0, 0, 0 );
137 QHBoxLayout* topLayout =
new QHBoxLayout(
this );
138 topLayout->setContentsMargins( 0, 0, 0, 0 );
139 topLayout->setSpacing( 0 );
141 QWidget* titleWidget =
new QWidget();
142 titleWidget->setMinimumHeight( textHeight + 3 * BORDERWIDTH );
143 titleWidget->setContentsMargins( BORDERWIDTH, 0, 0, 0 );
144 titleWidget->setLayout( topLayout );
146 titleLabel->setContentsMargins( 0, 0, 0, 0 );
147 topLayout->addWidget( titleLabel );
149 QPushButton* detailsBtn =
new QPushButton(
"",
this );
150 detailsBtn->setContentsMargins( 0, 0, 0, 0 );
152 detailsBtn->setFixedWidth( textHeight );
153 detailsBtn->setFixedHeight( textHeight );
154 detailsBtn->setToolTip(
"Show complete message" );
155 topLayout->addWidget( detailsBtn );
156 connect( detailsBtn, SIGNAL( released() ),
this, SLOT(
showMessage() ) );
163 m_closeBtn->setToolTip(
"Close this message" );
167 QVBoxLayout* popupLayout =
new QVBoxLayout(
this );
168 popupLayout->setSpacing( 0 );
169 popupLayout->setContentsMargins( BORDERWIDTH, 0, BORDERWIDTH, BORDERWIDTH );
172 messageLabel->
setText( message );
173 messageLabel->setContentsMargins( 2 * BORDERWIDTH, 2 * BORDERWIDTH, 2 * BORDERWIDTH, 2 * BORDERWIDTH );
174 popupLayout->addWidget( titleWidget );
175 popupLayout->addWidget( messageLabel );
177 setLayout( popupLayout );
180 setObjectName(
"popupDialog" );
181 titleLabel->setObjectName(
"popupDialogTitle" );
182 titleWidget->setObjectName(
"popupDialogTitle" );
183 messageLabel->setObjectName(
"popupDialogMessage" );
184 m_closeBtn->setObjectName(
"popupDialogButton" );
185 detailsBtn->setObjectName(
"popupDialogButton" );
194 QPoint p = parentWidget()->mapToGlobal( QPoint( parentWidget()->width() / 2, parentWidget()->height() ) );
197 move( p.x() - width() / 2 - OUTERMARGIN / 2, p.y() - 2 * height()- OUTERMARGIN );
200 QDialog::showEvent( event );
233 QTimer::singleShot( 2000,
this, SLOT( close() ) );
243 setWindowFlags( Qt::Popup );
247 setWindowFlags( Qt::Widget );
static WMainWindow * getMainWindow()
Returns the current main window instance or NULL if not existent.
Special Label that can shrink and expand in a layout.
virtual void setText(const QString &text)
reimplemented function to setText