1 /***************************************************************************
2 copyright : (C) 1999 by Judin Max
3 email : novaprint@mtu-net.ru
4 ***************************************************************************/
6 /***************************************************************************
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. *
13 ***************************************************************************/
15 #include "kdockwidgettest.h"
17 #include <QtGui/QPushButton>
19 #include <QtGui/QPixmap>
20 #include <kcmdlineargs.h>
21 #include <kaboutdata.h>
22 #include <kapplication.h>
23 #include <kiconloader.h>
24 #include <kstatusbar.h>
27 #include <Qt3Support/Q3PopupMenu>
29 static const char*folder
[]={
58 DockApplication::DockApplication( const char* name
)
59 : K3DockMainWindow( 0L, name
)
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
);
75 l
->setMinimumSize(100,100);
77 /*****************************************************/
78 dock1
= createDockWidget( "Blue Widget", p
);
79 dock1
->setWindowTitle("Blue");
80 dock1
->setGeometry( 150, 150, 100, 100);
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);
110 QPalette p3
= l
->palette();
111 p3
.setColor(l
->backgroundRole(), Qt::white
);
113 l
->setMinimumSize(100,100);
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);
123 QPalette p4
= l
->palette();
124 p4
.setColor(l
->backgroundRole(), Qt::white
);
126 l
->setMinimumSize(100,100);
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");
165 DockApplication::~DockApplication()
167 qDebug("Close & store config");
171 void DockApplication::rConfig()
176 void DockApplication::wConfig()
181 void DockApplication::initMenuBar()
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()
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");
218 dock
->setWindowTitle("Another Caption");
221 void DockApplication::greenMain()
223 setMainDockWidget( dock
);
227 void DockApplication::blueMain()
229 setMainDockWidget( dock1
);
233 void DockApplication::nullMain()
235 setMainDockWidget( 0L );
239 void DockApplication::updateButton()
241 if ( getMainDockWidget() )
242 m_bname
->setText(QString("MainDockWidget is %1").arg(getMainDockWidget()->objectName()));
244 m_bname
->setText("MainDockWidget is NULL");
247 void DockApplication::gSetPix1() {
248 dock
->setPixmap(SmallIcon("agent"));
252 void DockApplication::gSetPix2() {
257 int main(int argc
, char* argv
[]) {
258 KAboutData
about("kdockdemoapp1", 0, ki18n("kdockdemoapp1"), "version");
259 KCmdLineArgs::init(argc
, argv
, &about
);
263 DockApplication
* ap
= new DockApplication("DockWidget demo");
264 ap
->setCaption("DockWidget demo");
270 #include "kdockwidgettest.moc"