~dani.behzi/saghar/trunk

« back to all changes in this revision

Viewing changes to src/pQjWidgets/QTextBrowserDialog/qtextbrowserdialog.cpp

  • Committer: Danial Behzadi
  • Date: 2015-02-05 21:45:44 UTC
  • Revision ID: dani.behzi@gmail.com-20150205214544-6e80ydwmb9ekzwl6
UploadĀ Source

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *  This file is part of QTextBrowserDialog, a custom Qt widget            *
 
3
 *                                                                         *
 
4
 *  Copyright (C) 2012-2014 by S. Razi Alavizadeh                          *
 
5
 *  E-Mail: <s.r.alavizadeh@gmail.com>, WWW: <http://pozh.org>             *
 
6
 *                                                                         *
 
7
 *  The initial idea is from a custom lineEdit from qt labs................*
 
8
 *                                                                         *
 
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                                     *
 
13
 *                                                                         *
 
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                            *
 
18
 *                                                                         *
 
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/      *
 
21
 *                                                                         *
 
22
 ***************************************************************************/
 
23
 
 
24
#include "qtextbrowserdialog.h"
 
25
 
 
26
#include <QTextBrowser>
 
27
#include <QDialogButtonBox>
 
28
#include <QVBoxLayout>
 
29
#include <QGridLayout>
 
30
#include <QSpacerItem>
 
31
#include <QApplication>
 
32
 
 
33
QTextBrowserDialog::QTextBrowserDialog(QWidget* parent, const QString &title, const QString &text, const QPixmap &pixmapIcon, Qt::WindowFlags f)
 
34
    : QTextBrowser()
 
35
{
 
36
    containerDialog = new QDialog(parent, f);
 
37
    containerDialog->setObjectName(QString::fromUtf8("containerDialog"));
 
38
 
 
39
    QPalette p(containerDialog->palette());
 
40
    p.setColor(QPalette::Window, palette().color(QPalette::Base));
 
41
    containerDialog->setPalette(p);
 
42
 
 
43
    this->setFrameStyle(QFrame::NoFrame);
 
44
 
 
45
    this->setParent(containerDialog);
 
46
    setupui();
 
47
 
 
48
    this->setText(text);
 
49
    this->setIconPixmap(pixmapIcon);
 
50
    containerDialog->setWindowTitle(title);
 
51
}
 
52
 
 
53
void QTextBrowserDialog::setIconPixmap(const QPixmap &pixmap)
 
54
{
 
55
    if (pixmap.isNull()) {
 
56
        labelIcon->hide();
 
57
        verticalLayout->removeItem(verticalSpacer);
 
58
    }
 
59
    else {
 
60
        verticalLayout->addItem(verticalSpacer);
 
61
        labelIcon->setPixmap(pixmap);
 
62
        labelIcon->show();
 
63
    }
 
64
}
 
65
 
 
66
void QTextBrowserDialog::setupui()
 
67
{
 
68
    if (this->objectName().isEmpty()) {
 
69
        this->setObjectName(QString::fromUtf8("QTextBrowserDialog"));
 
70
    }
 
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);
 
76
 
 
77
    gridLayout->addWidget(this, 0, 1, 1, 1);
 
78
 
 
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);
 
84
 
 
85
    gridLayout->addWidget(buttonBox, 1, 0, 1, 2);
 
86
 
 
87
    verticalLayout = new QVBoxLayout();
 
88
    verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
 
89
    verticalLayout->setContentsMargins(0, 0, 0, 0);
 
90
    verticalLayout->setSpacing(0);
 
91
 
 
92
    labelIcon = new QLabel(containerDialog);
 
93
    labelIcon->setObjectName(QString::fromUtf8("labelIcon"));
 
94
    labelIcon->setText(QString());
 
95
    labelIcon->hide();
 
96
 
 
97
    verticalLayout->addWidget(labelIcon);
 
98
 
 
99
    verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
 
100
 
 
101
    gridLayout->addLayout(verticalLayout, 0, 0, 2, 1);
 
102
 
 
103
    retranslateUi();
 
104
    QObject::connect(buttonBox, SIGNAL(accepted()), containerDialog, SLOT(accept()));
 
105
    QObject::connect(buttonBox, SIGNAL(rejected()), containerDialog, SLOT(reject()));
 
106
 
 
107
    QMetaObject::connectSlotsByName(containerDialog);
 
108
}
 
109
 
 
110
void QTextBrowserDialog::retranslateUi()
 
111
{
 
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>"));
 
118
}