You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
529 lines
15 KiB
529 lines
15 KiB
15 years ago
|
#include <tqmessagebox.h>
|
||
|
#include <tqpopupmenu.h>
|
||
|
#include <tqpixmap.h>
|
||
|
#include <tqkeycode.h>
|
||
|
#include <tqwidget.h>
|
||
|
#include <tqstring.h>
|
||
|
#include <tqcursor.h>
|
||
15 years ago
|
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
#include <kstatusbar.h>
|
||
|
#include <kapplication.h>
|
||
|
#include <kcombobox.h>
|
||
|
#include <khelpmenu.h>
|
||
|
#include <kcmdlineargs.h>
|
||
|
#include <kmenubar.h>
|
||
|
#include <ktoolbarradiogroup.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <kpopupmenu.h>
|
||
15 years ago
|
#include <tqmultilineedit.h>
|
||
13 years ago
|
#include "twindowtest.h"
|
||
15 years ago
|
|
||
|
#include <kglobal.h>
|
||
|
|
||
|
|
||
|
//#include <dclock.h>
|
||
|
|
||
|
/*
|
||
|
Ok this is a constructor of our top widget. It inherits KMainWindow.
|
||
|
In constructor wi will create all of our interface elements:
|
||
|
menubar, toolbar(s), statusbar, and main widget. Non of those
|
||
|
interface is obligatory, i.e. you don't have to use menubar,
|
||
|
toolbars or statusbar if you don't want to. Theoreticly, you
|
||
|
don't need even main widget (but in that case, you'll get blank
|
||
|
KMainWindow).
|
||
|
*/
|
||
|
|
||
|
static int itemId = 0;
|
||
|
|
||
15 years ago
|
testWindow::testWindow (TQWidget *parent, const char *name)
|
||
15 years ago
|
: KMainWindow (parent,name)
|
||
|
{
|
||
|
ena=false;
|
||
|
setCaption("test window");
|
||
|
setAutoSaveSettings();
|
||
|
/******************************/
|
||
|
/* First, we setup setup Menus */
|
||
|
/******************************/
|
||
|
menuBar = new KMenuBar (this);
|
||
|
|
||
|
// First popup...
|
||
14 years ago
|
fileMenu = new TQPopupMenu;
|
||
15 years ago
|
// We insert this popup in menubar with caption "File".
|
||
|
// Prefix "&" means that "F" will be underlined
|
||
|
menuBar->insertItem ("&File", fileMenu);
|
||
|
// We insert item "Exit" with accelerator ALT-Q, and connect
|
||
|
// it to application's exit-slot.
|
||
|
fileMenu->insertItem ("&Exit", KApplication::kApplication(),
|
||
15 years ago
|
TQT_SLOT( quit() ), ALT + Key_Q );
|
||
15 years ago
|
|
||
|
// Another popup...
|
||
14 years ago
|
toolBarMenu = new TQPopupMenu;
|
||
15 years ago
|
menuBar->insertItem ("&Toolbars", toolBarMenu);
|
||
15 years ago
|
toolBarMenu->insertItem ("(Un)Hide tollbar 1", this, TQT_SLOT(slotHide1()));
|
||
|
toolBarMenu->insertItem ("(Un)Hide tollbar 2", this, TQT_SLOT(slotHide2()));
|
||
15 years ago
|
|
||
14 years ago
|
itemsMenu = new TQPopupMenu;
|
||
15 years ago
|
menuBar->insertItem ("&Items", itemsMenu);
|
||
|
|
||
|
exitB = true; // exit button is shown
|
||
|
lineL = true; // Lined is enabled
|
||
|
greenF = false; // Frame not inserted
|
||
|
|
||
15 years ago
|
itemsMenu->insertItem ("delete/insert exit button", this, TQT_SLOT(slotExit()));
|
||
|
itemsMenu->insertItem ("insert/delete green frame!", this, TQT_SLOT(slotFrame()));
|
||
|
itemsMenu->insertItem ("enable/disable Lined", this, TQT_SLOT(slotLined()));
|
||
|
itemsMenu->insertItem ("Toggle fileNew", this, TQT_SLOT(slotNew()));
|
||
|
itemsMenu->insertItem ("Clear comboBox", this, TQT_SLOT(slotClearCombo()));
|
||
|
itemsMenu->insertItem ("Insert List in Combo", this, TQT_SLOT(slotInsertListInCombo()));
|
||
|
itemsMenu->insertItem ("Make item 3 curent", this, TQT_SLOT(slotMakeItem3Current()));
|
||
|
//itemsMenu->insertItem ("Insert clock!", this, TQT_SLOT(slotInsertClock()));
|
||
|
itemsMenu->insertItem ("Important!", this, TQT_SLOT(slotImportant()));
|
||
15 years ago
|
|
||
|
menuBar->insertSeparator();
|
||
|
helpMenu = new KHelpMenu(this, "KWindowTest was programmed by Sven Radej");
|
||
|
menuBar->insertItem( "&Help", helpMenu->menu() );
|
||
|
|
||
|
/**************************************************/
|
||
|
/*Now, we setup statusbar order is not important. */
|
||
|
/**************************************************/
|
||
|
statusBar = new KStatusBar (this);
|
||
|
statusBar->insertItem("Hi there! ", 0);
|
||
|
statusBar->insertItem("Look for tooltips to see functions", 1);
|
||
|
|
||
|
//DigitalClock *clk = new DigitalClock (statusBar);
|
||
15 years ago
|
//clk->setFrameStyle(TQFrame::NoFrame);
|
||
15 years ago
|
//statusBar->insertWidget(clk, 70, 2);
|
||
|
|
||
|
/***********************/
|
||
|
/* And now the toolbar */
|
||
|
/***********************/
|
||
|
|
||
|
// pixmap which we will use
|
||
15 years ago
|
TQPixmap pix;
|
||
15 years ago
|
|
||
|
// Create toolbar...
|
||
|
tb = toolBar();
|
||
|
|
||
|
// and set it to full width
|
||
|
tb->setFullSize(true);
|
||
|
|
||
|
|
||
|
|
||
|
// First four buttons
|
||
|
pix = BarIcon("filenew");
|
||
15 years ago
|
itemId = tb->insertButton(pix, 0, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotNew()),
|
||
15 years ago
|
true, "Create.. (toggles upper button)", 50);
|
||
|
pix = BarIcon("fileopen");
|
||
15 years ago
|
tb->insertButton(pix, 1, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotOpen()),
|
||
15 years ago
|
false, "Open");
|
||
|
pix = BarIcon("filefloppy");
|
||
15 years ago
|
tb->insertButton(pix, 2, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotSave()),
|
||
15 years ago
|
true, "Save (beep or delayed popup)");
|
||
|
tb->setDelayedPopup(2, itemsMenu);
|
||
|
pix = BarIcon("fileprint");
|
||
15 years ago
|
tb->insertButton(pix, 3, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotPrint()),
|
||
15 years ago
|
true, "Print (enables/disables open)");
|
||
|
|
||
|
// And a combobox
|
||
|
// arguments: text (or strList), ID, writable, signal, object, slot, enabled,
|
||
|
// tooltiptext, size
|
||
15 years ago
|
tb->insertCombo (TQString("one"), 4, true, TQT_SIGNAL(activated(const TQString&)), this,
|
||
|
TQT_SLOT(slotList(const TQString&)), true, "ComboBox", 150);
|
||
15 years ago
|
|
||
|
|
||
|
// Then one line editor
|
||
|
// arguments: text, id, signal, object (this), slot, enabled, tooltiptext, size
|
||
15 years ago
|
tb->insertLined ("ftp://ftp.kde.org/pub/kde", 5, TQT_SIGNAL(returnPressed()), this,
|
||
|
TQT_SLOT(slotReturn()), true, "Location", 200);
|
||
15 years ago
|
|
||
|
// Set this Lined to auto size itself. Note that only one item (Lined or Combo)
|
||
|
// Can be set to autosize; If you specify more of them only last (according to
|
||
|
/// index) will be set to autosize itself. Only Lined or Combo can be
|
||
|
// set to autosize. All items after autoSized one must be aligned right.
|
||
|
// Auto size is valid only for fullWidth toolbars.
|
||
|
|
||
|
tb->setItemAutoSized (5);
|
||
|
|
||
|
// Now add another button and align it right
|
||
|
pix = BarIcon("exit");
|
||
15 years ago
|
tb->insertButton(pix, 6, TQT_SIGNAL(clicked()), KApplication::kApplication(),
|
||
|
TQT_SLOT( quit() ), true, "Exit");
|
||
15 years ago
|
tb->alignItemRight (6);
|
||
|
|
||
|
// Another toolbar
|
||
15 years ago
|
tb1 = new KToolBar(this, TQMainWindow::DockTop); // this one is normal and has separators
|
||
15 years ago
|
|
||
|
|
||
|
pix = BarIcon("filenew");
|
||
|
tb1->insertButton(pix, 0, true, "Create new file2 (Toggle)");
|
||
|
tb1->setToggle(0);
|
||
15 years ago
|
tb1->addConnection (0, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggle(bool)));
|
||
15 years ago
|
|
||
|
pix = BarIcon("fileopen");
|
||
15 years ago
|
tb1->insertButton(pix, 1, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotOpen()),
|
||
15 years ago
|
true, "Open (starts progres in sb)");
|
||
|
|
||
|
tb1->insertSeparator ();
|
||
|
|
||
|
pix = BarIcon("filefloppy");
|
||
15 years ago
|
tb1->insertButton(pix, 2, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotSave()),
|
||
15 years ago
|
true, "Save file2 (autorepeat)");
|
||
|
tb1->setAutoRepeat(2);
|
||
|
|
||
|
pix = BarIcon("fileprint");
|
||
|
tb1->insertButton(pix, 3, itemsMenu, true, "Print (pops menu)");
|
||
|
|
||
|
tb1->insertSeparator ();
|
||
|
/**** RADIO BUTTONS */
|
||
|
pix = BarIcon("filenew");
|
||
|
tb1->insertButton(pix, 4, true, "Radiobutton1");
|
||
|
tb1->setToggle(4);
|
||
|
|
||
|
pix = BarIcon("fileopen");
|
||
|
tb1->insertButton(pix, 5, true, "Radiobutton2");
|
||
|
tb1->setToggle(5);
|
||
|
|
||
|
pix = BarIcon("filefloppy");
|
||
|
tb1->insertButton(pix, 6, true, "Radiobutton3");
|
||
|
tb1->setToggle(6);
|
||
|
|
||
|
pix = BarIcon("fileprint");
|
||
|
tb1->insertButton(pix, 7, true, "Radiobutton4");
|
||
|
tb1->setToggle(7);
|
||
|
|
||
|
//Create
|
||
|
rg = new KToolBarRadioGroup (tb1);
|
||
|
|
||
|
rg->addButton(4);
|
||
|
rg->addButton(5);
|
||
|
rg->addButton(6);
|
||
|
rg->addButton(7);
|
||
|
|
||
15 years ago
|
connect (tb1, TQT_SIGNAL(toggled(int)), this, TQT_SLOT(slotToggled(int)));
|
||
15 years ago
|
|
||
|
// Set caption for floating toolbars
|
||
|
tb->setTitle ("Toolbar 1");
|
||
|
tb1->setTitle ("Toolbar 2");
|
||
|
|
||
|
// Set main widget. In this example it is Qt's multiline editor.
|
||
15 years ago
|
widget = new TQMultiLineEdit (this);
|
||
15 years ago
|
|
||
|
// Setup is now complete
|
||
|
|
||
|
// add two toolbars
|
||
|
//addToolBar (tb1);
|
||
|
//addToolBar (tb);
|
||
|
|
||
15 years ago
|
connect (tb, TQT_SIGNAL(highlighted(int,bool)), this, TQT_SLOT(slotMessage(int, bool)));
|
||
|
connect (tb1, TQT_SIGNAL(highlighted(int, bool)), this, TQT_SLOT(slotMessage(int, bool)));
|
||
15 years ago
|
|
||
|
// Floating is enabled by default, so you don't need this.
|
||
|
// tb->enableFloating(true);
|
||
|
// tb1->enableFloating(true);
|
||
|
|
||
|
// Show toolbars
|
||
|
tb->show();
|
||
|
tb1->show();
|
||
|
|
||
|
//... and main widget
|
||
|
setCentralWidget (widget);
|
||
|
|
||
|
// This is not strictly related to toolbars, menubars or KMainWindow.
|
||
|
// Setup popup for completions
|
||
14 years ago
|
completions = new TQPopupMenu;
|
||
15 years ago
|
|
||
|
completions->insertItem("/");
|
||
|
completions->insertItem("/usr/");
|
||
|
completions->insertItem("/lib/");
|
||
|
completions->insertItem("/var/");
|
||
|
completions->insertItem("/bin/");
|
||
|
completions->insertItem("/kde/");
|
||
|
completions->insertItem("/home/");
|
||
|
completions->insertItem("/vmlinuz :-)");
|
||
|
|
||
15 years ago
|
connect (completions, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotCompletionsMenu(int)));
|
||
15 years ago
|
pr = 0;
|
||
|
}
|
||
|
/***********************************/
|
||
|
/* Now slots for toolbar actions */
|
||
|
/***********************************/
|
||
|
void testWindow::slotToggled(int)
|
||
|
{
|
||
|
statusBar->message ("Buton toggled", 1500);
|
||
|
}
|
||
|
|
||
|
void testWindow::slotInsertClock()
|
||
|
{
|
||
|
//DigitalClock *clock = new DigitalClock(tb1);
|
||
15 years ago
|
//clock->setFrameStyle(TQFrame::NoFrame);
|
||
15 years ago
|
//tb1->insertWidget(8, 70, clock);
|
||
|
}
|
||
|
|
||
|
void testWindow::slotNew()
|
||
|
{
|
||
|
tb1->toggleButton(0);
|
||
|
toolBar()->removeItem( itemId );
|
||
|
}
|
||
|
void testWindow::slotOpen()
|
||
|
{
|
||
|
if (pr == 0)
|
||
15 years ago
|
pr = new TQProgressBar (statusBar);
|
||
15 years ago
|
// statusBar->message(pr);
|
||
15 years ago
|
timer = new TQTimer (pr);
|
||
15 years ago
|
|
||
15 years ago
|
connect (timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotGoGoGoo()));
|
||
15 years ago
|
timer->start(100);
|
||
|
}
|
||
|
|
||
|
void testWindow::slotGoGoGoo()
|
||
|
{
|
||
|
pr->setProgress(pr->progress()+1);
|
||
|
if (pr->progress()==100)
|
||
|
{
|
||
|
timer->stop();
|
||
|
statusBar->clear();
|
||
|
delete pr;
|
||
|
pr = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void testWindow::slotSave()
|
||
|
{
|
||
|
kapp->beep();
|
||
|
statusBar->changeItem("Saving properties...", 0);
|
||
|
}
|
||
|
|
||
|
void testWindow::slotPrint()
|
||
|
{
|
||
|
statusBar->changeItem("Print file pressed", 0);
|
||
|
ena=!ena;
|
||
|
tb->setItemEnabled(1,ena );
|
||
|
}
|
||
|
void testWindow::slotReturn()
|
||
|
{
|
||
15 years ago
|
TQString s = "You entered ";
|
||
15 years ago
|
s = s + tb->getLinedText(5);
|
||
|
statusBar->changeItem(s, 0);
|
||
|
|
||
|
}
|
||
15 years ago
|
void testWindow::slotList(const TQString &str)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString s = "You chose ";
|
||
15 years ago
|
s = s + str;
|
||
|
statusBar->changeItem(s, 0);
|
||
|
}
|
||
|
|
||
|
void testWindow::slotCompletion()
|
||
|
{
|
||
|
// Now do a completion
|
||
|
// Call your completing function and set that text in klined
|
||
15 years ago
|
// TQString s = tb->getLinedText(/* ID */ 4)
|
||
|
// TQString completed = complete (s);
|
||
15 years ago
|
// tb->setLinedText(/* ID */ 4, completed.data())
|
||
|
|
||
|
// for now this:
|
||
|
|
||
15 years ago
|
completions->popup(TQCursor::pos()); // This popup should understunf keys up and down
|
||
15 years ago
|
|
||
|
/* This is just an example. KLined automatically sets cursor at end of string
|
||
|
when ctrl-d or ctrl-s is pressed. KToolBar will also put cursor at end of text in Lined
|
||
|
after inserting text with setLinedText (...).
|
||
|
*/
|
||
|
|
||
|
}
|
||
|
|
||
|
void testWindow::slotListCompletion()
|
||
|
{
|
||
|
/*
|
||
|
Combo is not behaving good and it is ugly. I will see how it behaves in Qt-1.3,
|
||
|
and then decide should I make a new combobox.
|
||
|
*/
|
||
15 years ago
|
TQString s(tb->getComboItem(4)); // get text in combo
|
||
15 years ago
|
s+= "(completing)";
|
||
|
//tb->getCombo(4)->changeItem(s.data()); // setTextIncombo
|
||
|
|
||
|
}
|
||
|
|
||
|
void testWindow::slotCompletionsMenu(int id)
|
||
|
{
|
||
|
// Now set text in lined
|
||
15 years ago
|
TQString s =completions->text(id);
|
||
15 years ago
|
tb->setLinedText(5, s); // Cursor is automatically at the end of string after this
|
||
|
}
|
||
|
|
||
|
void testWindow::slotHide2 ()
|
||
|
{
|
||
|
tb1->show();
|
||
|
}
|
||
|
|
||
|
void testWindow::slotHide1 ()
|
||
|
{
|
||
|
tb->show();
|
||
|
}
|
||
|
|
||
|
testWindow::~testWindow ()
|
||
|
{
|
||
|
/********************************************************/
|
||
|
/* */
|
||
|
/* THIS IS NOT ANY MORE IMPORTANT BUT ALLOWED!!! */
|
||
|
/* */
|
||
|
/********************************************************/
|
||
|
|
||
|
delete tb1->getWidget(8);
|
||
13 years ago
|
//debug ("twindowtest: deleted clock");
|
||
15 years ago
|
|
||
|
delete tb;
|
||
|
delete tb1;
|
||
|
delete menuBar;
|
||
|
|
||
13 years ago
|
qDebug ("twindowtest finished");
|
||
15 years ago
|
}
|
||
|
|
||
|
void testWindow::beFixed()
|
||
|
{
|
||
|
widget->setFixedSize (400, 200);
|
||
|
}
|
||
|
|
||
|
void testWindow::beYFixed()
|
||
|
{
|
||
|
widget->setMinimumSize(400, 200);
|
||
|
widget->setMaximumSize(9999, 200);
|
||
|
}
|
||
|
|
||
|
void testWindow::slotImportant ()
|
||
|
{
|
||
|
statusBar->message("This important message will go away in 15 seconds", 15000);
|
||
|
}
|
||
|
|
||
|
void testWindow::slotExit ()
|
||
|
{
|
||
|
if (exitB == true)
|
||
|
{
|
||
|
tb->removeItem(6);
|
||
|
exitB = false;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
15 years ago
|
TQPixmap pix;
|
||
15 years ago
|
pix = BarIcon("exit");
|
||
15 years ago
|
tb->insertButton(pix, 6, TQT_SIGNAL(clicked()), KApplication::kApplication(),
|
||
|
TQT_SLOT( quit() ), true, "Exit");
|
||
15 years ago
|
tb->alignItemRight (6);
|
||
|
exitB = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void testWindow::slotLined()
|
||
|
{
|
||
|
lineL = !lineL;
|
||
|
tb->setItemEnabled(5, lineL); // enable/disable lined
|
||
|
}
|
||
|
|
||
|
void testWindow::slotToggle (bool on)
|
||
|
{
|
||
|
if (on == true)
|
||
|
statusBar->changeItem("Toggle is on", 0);
|
||
|
else
|
||
|
statusBar->changeItem("Toggle is off", 0);
|
||
|
}
|
||
|
|
||
|
void testWindow::slotFrame()
|
||
|
{
|
||
|
#if 0
|
||
|
if (greenF == false)
|
||
|
{
|
||
|
tb1->insertFrame(10, 100);
|
||
|
tb1->alignItemRight (10); // this is pointless 'cause tb1 is not fullwidth
|
||
|
|
||
15 years ago
|
TQFrame *myFrame = tb1->getFrame(10); // get frame pointer
|
||
15 years ago
|
|
||
|
if (myFrame == 0)
|
||
|
{
|
||
|
warning ("bad frame ID");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
//paint it green
|
||
|
// Or do whatever you want with it, just don't change its height (height = hardcoded = 24)
|
||
|
// And don't move it
|
||
|
// If you want to have something right from your toolbar you can reduce its
|
||
|
// max_width with setMaxWidth()
|
||
15 years ago
|
myFrame->setBackgroundColor (TQColor("green"));
|
||
15 years ago
|
|
||
|
greenF = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
tb1->removeItem (10);
|
||
|
greenF = false;
|
||
|
}
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void testWindow::slotMessage(int, bool boo)
|
||
|
{
|
||
|
if (boo)
|
||
|
statusBar->message("This button does this and that", 1500);
|
||
|
else
|
||
|
statusBar->clear();
|
||
|
}
|
||
|
// Now few Combo slots, for Torben
|
||
|
|
||
|
void testWindow::slotClearCombo()
|
||
|
{
|
||
|
tb->getCombo(4)->clear();
|
||
|
}
|
||
|
|
||
|
void testWindow::slotInsertListInCombo()
|
||
|
{
|
||
15 years ago
|
TQStringList list;
|
||
15 years ago
|
list.append("ListOne");
|
||
|
list.append("ListTwo");
|
||
|
list.append("ListThree");
|
||
|
list.append("ListFour");
|
||
|
list.append("ListFive");
|
||
|
list.append("ListSix");
|
||
|
list.append("ListSeven");
|
||
|
list.append("ListEight");
|
||
|
list.append("ListNine");
|
||
|
list.append("ListTen");
|
||
|
list.append("ListEleven");
|
||
|
list.append("ListAndSoOn");
|
||
|
tb->getCombo(4)->insertStringList (list,0);
|
||
|
}
|
||
|
|
||
|
void testWindow::slotMakeItem3Current()
|
||
|
{
|
||
|
tb->getCombo(4)->setCurrentItem(3);
|
||
|
}
|
||
|
|
||
|
int main( int argc, char *argv[] )
|
||
|
{
|
||
|
int i;
|
||
|
KCmdLineArgs::init(argc, argv, "KWindowTest", "description", "version");
|
||
|
|
||
|
KApplication *myApp = new KApplication();
|
||
|
testWindow *test = new testWindow;
|
||
|
|
||
|
myApp->setMainWidget(test);
|
||
|
|
||
15 years ago
|
i = TQMessageBox::information(0, "Select", "Select type of mainwidget",
|
||
15 years ago
|
"Fixed", "Y-fixed", "Resizable");
|
||
|
if (i == 0)
|
||
|
test->beFixed();
|
||
|
else if (i == 1)
|
||
|
test->beYFixed();
|
||
|
|
||
|
test->show();
|
||
|
test->resize(400, 500);
|
||
|
int ret = myApp->exec();
|
||
|
|
||
|
//delete test;
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
13 years ago
|
#include "twindowtest.moc"
|
||
15 years ago
|
|