1
/***************************************************************************
2
* This file is part of QTextBrowserDialog, a custom Qt widget *
4
* Copyright (C) 2012-2014 by S. Razi Alavizadeh *
5
* E-Mail: <s.r.alavizadeh@gmail.com>, WWW: <http://pozh.org> *
7
* The initial idea is from a custom lineEdit from qt labs................*
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 3 of the License, *
12
* (at your option) any later version *
14
* This program is distributed in the hope that it will be useful, *
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17
* GNU General Public License for more details *
19
* You should have received a copy of the GNU General Public License *
20
* along with this program; if not, see http://www.gnu.org/licenses/ *
22
***************************************************************************/
24
#include "qtextbrowserdialog.h"
26
#include <QTextBrowser>
27
#include <QDialogButtonBox>
28
#include <QVBoxLayout>
29
#include <QGridLayout>
30
#include <QSpacerItem>
31
#include <QApplication>
33
QTextBrowserDialog::QTextBrowserDialog(QWidget* parent, const QString &title, const QString &text, const QPixmap &pixmapIcon, Qt::WindowFlags f)
36
containerDialog = new QDialog(parent, f);
37
containerDialog->setObjectName(QString::fromUtf8("containerDialog"));
39
QPalette p(containerDialog->palette());
40
p.setColor(QPalette::Window, palette().color(QPalette::Base));
41
containerDialog->setPalette(p);
43
this->setFrameStyle(QFrame::NoFrame);
45
this->setParent(containerDialog);
49
this->setIconPixmap(pixmapIcon);
50
containerDialog->setWindowTitle(title);
53
void QTextBrowserDialog::setIconPixmap(const QPixmap &pixmap)
55
if (pixmap.isNull()) {
57
verticalLayout->removeItem(verticalSpacer);
60
verticalLayout->addItem(verticalSpacer);
61
labelIcon->setPixmap(pixmap);
66
void QTextBrowserDialog::setupui()
68
if (this->objectName().isEmpty()) {
69
this->setObjectName(QString::fromUtf8("QTextBrowserDialog"));
71
containerDialog->resize(600, 300);
72
gridLayout = new QGridLayout(containerDialog);
73
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
74
gridLayout->setContentsMargins(0, 0, 0, 0);
75
gridLayout->setSpacing(2);
77
gridLayout->addWidget(this, 0, 1, 1, 1);
79
buttonBox = new QDialogButtonBox(containerDialog);
80
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
81
buttonBox->setOrientation(Qt::Horizontal);
82
buttonBox->setStandardButtons(QDialogButtonBox::Ok);
83
buttonBox->setCenterButtons(true);
85
gridLayout->addWidget(buttonBox, 1, 0, 1, 2);
87
verticalLayout = new QVBoxLayout();
88
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
89
verticalLayout->setContentsMargins(0, 0, 0, 0);
90
verticalLayout->setSpacing(0);
92
labelIcon = new QLabel(containerDialog);
93
labelIcon->setObjectName(QString::fromUtf8("labelIcon"));
94
labelIcon->setText(QString());
97
verticalLayout->addWidget(labelIcon);
99
verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
101
gridLayout->addLayout(verticalLayout, 0, 0, 2, 1);
104
QObject::connect(buttonBox, SIGNAL(accepted()), containerDialog, SLOT(accept()));
105
QObject::connect(buttonBox, SIGNAL(rejected()), containerDialog, SLOT(reject()));
107
QMetaObject::connectSlotsByName(containerDialog);
110
void QTextBrowserDialog::retranslateUi()
112
containerDialog->setWindowTitle(tr("TextBrowser Dialog"));
113
this->setHtml(tr("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
114
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
115
"p, li { white-space: pre-wrap; }\n"
116
"</style></head><body style=\" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
117
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"></p></body></html>"));