KVIrc  4.9.2
DeveloperAPIs
KviHtmlDialog.h
Go to the documentation of this file.
1 #ifndef _KVI_HTMLDIALOG_H_
2 #define _KVI_HTMLDIALOG_H_
3 //=============================================================================
4 //
5 // File : KviHtmlDialog.h
6 // Creation date : Wed 03 Jan 2007 03:36:36 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC Client distribution
9 // Copyright (C) 2007-2010 Szymon Stefanek <pragma at kvirc dot net>
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 #include "KviQString.h"
28 #include "kvi_settings.h"
29 
30 #include <QPixmap>
31 #include <QDialog>
32 #include <QUrl>
33 #include <QTextBrowser>
34 #include <QHash>
35 #include <QPixmap>
36 
38 {
39 public:
41  {
42  m_pDoc = new QTextDocument();
43  };
44  ~KviHtmlDialogData() { delete m_pDoc; };
45 
46  void addImageResource(const QString & key, const QPixmap & pix)
47  {
48  if(!m_pDoc)
49  m_pDoc = new QTextDocument();
50  QUrl url;
51  url.setPath(key);
52  m_pDoc->addResource(2, url, pix);
53  }
54 
55  void addHtmlResource(const QString key, const QString value)
56  {
57  htmlResource.insert(key, value);
58  }
59 
60  // input
61 
62  // mandatory fields
63  enum Flags
64  {
66  };
67  int iFlags; // da flags :)
68  int iDefaultButton; // the button to use when Enter is pressed (1,2 or 3)
69  int iCancelButton; // the button to use when Esc is pressed (1,2 or 3)
70  QString szHtmlText; // Shouldn't be empty :D
71 
72  // optional fields
73  QString szCaption; // KVIrc is used when this is empty
74  QString szUpperLabelText; // no label is shown if this is empty
75  QString szLowerLabelText; // no label is shown if this is empty
76  QString szButton1Text; // OK is used if this is empty
77  QString szButton2Text; // no button is shown if this is empty
78  QString szButton3Text; // no button is shown if this is empty
79  QTextDocument * m_pDoc;
80  QHash<QString, QString> htmlResource;
83 
84  QPixmap pixIcon; // may be null
85 
86  // output
87  int iSelectedButton; // returns 1,2 or 3
88 };
89 
90 class KviTextBrowser : public QTextBrowser
91 {
92 public:
93  KviTextBrowser(QWidget * par, KviHtmlDialogData * ht)
94  : QTextBrowser(par), m_pHt(ht){};
96  virtual QVariant loadResource(int type, const QUrl & name)
97  {
98  QString p = m_pHt->htmlResource.value(name.path());
99  qDebug("resource %s type %d and page %s", name.path().toUtf8().data(), type, p.toUtf8().data());
100  if(!p.isEmpty())
101  return QVariant(p);
102  else
103  return QVariant();
104 
105  //return QTextBrowser::loadResource(type,name);
106  }
107 
108 protected:
110 };
111 
112 class KVIRC_API KviHtmlDialog : public QDialog
113 {
114  Q_OBJECT
115 public:
116  // the dialog does NOT delete this structure and assumes that
117  // it remains alive until the dialog closes (i.e. it may access
118  // the structure in the destructor
119  KviHtmlDialog(QWidget * pParent, KviHtmlDialogData * pData);
120  ~KviHtmlDialog();
121 
122 protected:
124 
125 public:
126  // displays the dialog as modal and returns 1,2 or 3
127  static int display(QWidget * pParent, KviHtmlDialogData * pData);
128 protected slots:
129  void button1Pressed();
130  void button2Pressed();
131  void button3Pressed();
132 
133 protected:
134  virtual void reject();
135 };
136 
137 #endif
QTextDocument * m_pDoc
Definition: KviHtmlDialog.h:79
KviTextBrowser(QWidget *par, KviHtmlDialogData *ht)
Definition: KviHtmlDialog.h:93
#define KVIRC_API
Definition: kvi_settings.h:128
int iMinimumHeight
Definition: KviHtmlDialog.h:82
virtual QVariant loadResource(int type, const QUrl &name)
Definition: KviHtmlDialog.h:96
int iSelectedButton
Definition: KviHtmlDialog.h:87
int iDefaultButton
Definition: KviHtmlDialog.h:68
~KviTextBrowser()
Definition: KviHtmlDialog.h:95
QPixmap pixIcon
Definition: KviHtmlDialog.h:84
QString szCaption
Definition: KviHtmlDialog.h:73
int iMinimumWidth
Definition: KviHtmlDialog.h:81
~KviHtmlDialogData()
Definition: KviHtmlDialog.h:44
QString type()
Definition: KviRuntimeInfo.cpp:646
Definition: KviHtmlDialog.h:37
KviHtmlDialogData * m_pData
Definition: KviHtmlDialog.h:123
QString szButton3Text
Definition: KviHtmlDialog.h:78
int iFlags
Definition: KviHtmlDialog.h:67
QString szButton2Text
Definition: KviHtmlDialog.h:77
QHash< QString, QString > htmlResource
Definition: KviHtmlDialog.h:80
Definition: KviHtmlDialog.h:112
Flags
Definition: KviHtmlDialog.h:63
QString szLowerLabelText
Definition: KviHtmlDialog.h:75
KviHtmlDialogData()
Definition: KviHtmlDialog.h:40
QString szUpperLabelText
Definition: KviHtmlDialog.h:74
Definition: KviHtmlDialog.h:90
Definition: KviHtmlDialog.h:65
void addHtmlResource(const QString key, const QString value)
Definition: KviHtmlDialog.h:55
QString name()
Definition: KviRuntimeInfo.cpp:655
KviHtmlDialogData * m_pHt
Definition: KviHtmlDialog.h:109
int iCancelButton
Definition: KviHtmlDialog.h:69
This file contains compile time settings.
#define p
Definition: detector.cpp:80
Helper functions for the QString class.
void addImageResource(const QString &key, const QPixmap &pix)
Definition: KviHtmlDialog.h:46
QString szHtmlText
Definition: KviHtmlDialog.h:70
QString szButton1Text
Definition: KviHtmlDialog.h:76