fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kde3support / tests / kdockwidgettest.cpp
blob54f6531212bd3b0f4477754a84b921f871be3877
1 /***************************************************************************
2 copyright : (C) 1999 by Judin Max
3 email : novaprint@mtu-net.ru
4 ***************************************************************************/
6 /***************************************************************************
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 ***************************************************************************/
15 #include "kdockwidgettest.h"
17 #include <QtGui/QPushButton>
18 //Added by qt3to4:
19 #include <QtGui/QPixmap>
20 #include <kcmdlineargs.h>
21 #include <kaboutdata.h>
22 #include <kapplication.h>
23 #include <kiconloader.h>
24 #include <kstatusbar.h>
25 #include <kmenubar.h>
26 #include <ktoolbar.h>
27 #include <Qt3Support/Q3PopupMenu>
29 static const char*folder[]={
30 "16 16 9 1",
31 "g c #808080",
32 "b c #ffa858",
33 "e c #c0c0c0",
34 "# c #000000",
35 "c c #ffdca8",
36 ". c None",
37 "a c #585858",
38 "f c #a0a0a4",
39 "d c #ffffff",
40 "..#a#...........",
41 ".#abc##.........",
42 ".#daabc#####....",
43 ".#ddeaabcccb#...",
44 ".#dedeeabccca...",
45 ".#edeeeeaaaab#..",
46 ".#deeeeeeefe#ba.",
47 ".#eeeeeeefef#ba.",
48 ".#eeeeeefeff#ba.",
49 ".#eeeeefefff#ba.",
50 ".##geefeffff#ba.",
51 "...##gefffff#ba.",
52 ".....##fffff#ba.",
53 ".......##fff#b##",
54 ".........##f#b##",
55 "...........####."};
58 DockApplication::DockApplication( const char* name )
59 : K3DockMainWindow( 0L, name )
61 QPixmap p(folder);
63 initMenuBar();
64 initToolBars();
65 initStatusBar();
67 /*****************************************************/
68 dock = createDockWidget( "Green Widget", p );
69 dock->setWindowTitle("Green");
70 dock->setGeometry(50, 50, 100, 100);
71 l = new QWidget(dock);
72 QPalette p1 = l->palette();
73 p1.setColor(l->backgroundRole(), Qt::green);
74 l->setPalette(p1);
75 l->setMinimumSize(100,100);
76 dock->setWidget(l);
77 /*****************************************************/
78 dock1 = createDockWidget( "Blue Widget", p );
79 dock1->setWindowTitle("Blue");
80 dock1->setGeometry( 150, 150, 100, 100);
81 setView( dock1 );
82 setMainDockWidget( dock1 );
84 mainW = new QWidget( dock1 );
85 mainW->setObjectName( "createdOnBlueDock" );
86 QPalette p2 = mainW->palette();
87 p2.setColor(mainW->backgroundRole(), Qt::blue);
88 mainW->setPalette(p2);
89 mainW->setMinimumSize(300,150);
90 dock1->setWidget( mainW );
91 /*****************************************************/
93 K3DockWidget* dock2 = createDockWidget( "Yellow Widget", p );
94 dock2->setGeometry(300, 300, 100, 100);
95 dock2->setWindowTitle("Yellow");
97 /* test set new header widget...*/
98 // dock2->setHeader( new K3DockWidgetHeader(dock2) );
100 QWidget* l2 = new QWidget(dock2);
101 l2->setBackgroundColor(Qt::yellow);
102 dock2->setWidget( l2 );
103 /*****************************************************/
105 /*****************************************************/
106 dock5 = createDockWidget( "Container Widget", p );
107 dock5->setWindowTitle("Container");
108 dock5->setGeometry(50, 50, 100, 100);
109 l = new CTW(dock5);
110 QPalette p3 = l->palette();
111 p3.setColor(l->backgroundRole(), Qt::white);
112 l->setPalette(p3);
113 l->setMinimumSize(100,100);
114 dock5->setWidget(l);
115 if (dynamic_cast<K3DockContainer*>(l)) qDebug("K3DockContainer created for dock 5");
116 /*****************************************************/
118 /*****************************************************/
119 dock6 = createDockWidget( "Container Widget2", p );
120 dock6->setWindowTitle("Container2");
121 dock6->setGeometry(50, 50, 100, 100);
122 l = new CTW(dock6);
123 QPalette p4 = l->palette();
124 p4.setColor(l->backgroundRole(), Qt::white);
125 l->setPalette(p4);
126 l->setMinimumSize(100,100);
127 dock6->setWidget(l);
128 if (dynamic_cast<K3DockContainer*>(l)) qDebug("K3DockContainer created for dock 6");
129 /*****************************************************/
133 QPushButton* b1 = new QPushButton(mainW);
134 b1->setGeometry(10, 10, 250, 25);
135 b1->setText("write dock config");
136 connect(b1, SIGNAL(clicked()), SLOT(wConfig()));
138 QPushButton* b2 = new QPushButton(mainW);
139 b2->setGeometry(10, 35, 250, 25);
140 b2->setText("read dock config");
141 connect(b2, SIGNAL(clicked()), SLOT(rConfig()));
143 m_bname = new QPushButton(mainW);
144 m_bname->setGeometry(10, 60, 250, 25);
145 m_bname->setEnabled( false );
147 QPushButton *b3 = new QPushButton(mainW);
148 b3->setGeometry(10,95,250,25);
149 b3->setText("change the icon of the green widget");
150 connect(b3,SIGNAL(clicked()), SLOT(gSetPix1()));
152 QPushButton *b4 = new QPushButton(mainW);
153 b4->setGeometry(10,130,250,25);
154 b4->setText("remove icon ");
155 connect(b4,SIGNAL(clicked()), SLOT(gSetPix2()));
157 setGeometry(200, 100, 500, 300);
159 qDebug("load config");
160 readDockConfig();
162 updateButton();
165 DockApplication::~DockApplication()
167 qDebug("Close & store config");
168 writeDockConfig();
171 void DockApplication::rConfig()
173 readDockConfig();
176 void DockApplication::wConfig()
178 writeDockConfig();
181 void DockApplication::initMenuBar()
183 QPixmap p(folder);
184 Q3PopupMenu *file_menu = new Q3PopupMenu();
186 file_menu->insertItem(p, "Change Green Widget Caption", this, SLOT(cap()) );
187 file_menu->addSeparator();
188 file_menu->insertItem(p, "Set Green Widget as MainDockWidget", this, SLOT(greenMain()) );
189 file_menu->insertItem(p, "Set Blue Widget as MainDockWidget", this, SLOT(blueMain()) );
190 file_menu->insertItem(p, "Set NULL as MainDockWidget", this, SLOT(nullMain()) );
192 KMenuBar* menu_bar = menuBar();
193 menu_bar->insertItem( "&Test", file_menu );
194 menu_bar->insertItem( "&Docking Windows", dockHideShowMenu() );
197 void DockApplication::initToolBars()
199 QPixmap p(folder);
200 QIcon i(p);
201 KToolBar* tool_bar_0 = toolBar(0);
202 tool_bar_0->addAction(i, "Action1");
203 tool_bar_0->addAction(i, "Action2");
204 insertToolBarBreak( tool_bar_0 );
207 void DockApplication::initStatusBar()
209 KStatusBar* status_bar = statusBar();
210 status_bar->insertItem("Welcome to KDockWidget test...", 1);
213 void DockApplication::cap()
215 if ( dock->windowTitle() != "Test Caption1" )
216 dock->setWindowTitle("Test Caption1");
217 else
218 dock->setWindowTitle("Another Caption");
221 void DockApplication::greenMain()
223 setMainDockWidget( dock );
224 updateButton();
227 void DockApplication::blueMain()
229 setMainDockWidget( dock1 );
230 updateButton();
233 void DockApplication::nullMain()
235 setMainDockWidget( 0L );
236 updateButton();
239 void DockApplication::updateButton()
241 if ( getMainDockWidget() )
242 m_bname->setText(QString("MainDockWidget is %1").arg(getMainDockWidget()->objectName()));
243 else
244 m_bname->setText("MainDockWidget is NULL");
247 void DockApplication::gSetPix1() {
248 dock->setPixmap(SmallIcon("agent"));
252 void DockApplication::gSetPix2() {
253 dock->setPixmap();
257 int main(int argc, char* argv[]) {
258 KAboutData about("kdockdemoapp1", 0, ki18n("kdockdemoapp1"), "version");
259 KCmdLineArgs::init(argc, argv, &about);
261 KApplication a;
263 DockApplication* ap = new DockApplication("DockWidget demo");
264 ap->setCaption("DockWidget demo");
265 ap->show();
266 return a.exec();
270 #include "kdockwidgettest.moc"