From ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kmdi/test/Makefile.am | 10 ++++ kmdi/test/README | 16 ++++++ kmdi/test/hello.cpp | 104 +++++++++++++++++++++++++++++++++ kmdi/test/hello.h | 38 ++++++++++++ kmdi/test/main.cpp | 103 +++++++++++++++++++++++++++++++++ kmdi/test/mainwidget.cpp | 147 +++++++++++++++++++++++++++++++++++++++++++++++ kmdi/test/mainwidget.h | 71 +++++++++++++++++++++++ 7 files changed, 489 insertions(+) create mode 100644 kmdi/test/Makefile.am create mode 100644 kmdi/test/README create mode 100644 kmdi/test/hello.cpp create mode 100644 kmdi/test/hello.h create mode 100644 kmdi/test/main.cpp create mode 100644 kmdi/test/mainwidget.cpp create mode 100644 kmdi/test/mainwidget.h (limited to 'kmdi/test') diff --git a/kmdi/test/Makefile.am b/kmdi/test/Makefile.am new file mode 100644 index 000000000..73e0b8a13 --- /dev/null +++ b/kmdi/test/Makefile.am @@ -0,0 +1,10 @@ +check_PROGRAMS = kfourchildren +METASOURCES = AUTO + +INCLUDES = -I$(top_srcdir)/kmdi -I.. $(all_includes) + +kfourchildren_SOURCES = hello.cpp main.cpp mainwidget.cpp +kfourchildren_LDFLAGS = -no-undefined $(all_libraries) +kfourchildren_LDADD = $(top_builddir)/kmdi/libkmdi.la \ + $(top_builddir)/kutils/libkutils.la + diff --git a/kmdi/test/README b/kmdi/test/README new file mode 100644 index 000000000..0cdeae7ef --- /dev/null +++ b/kmdi/test/README @@ -0,0 +1,16 @@ +This example shows the use of KMdi. +Either you inherit your views from KMdiChildView or you wrap your common widgets by KMdiChildViews. +Your main widget must inherit from KMdiMainFrm. + + + +Call + qmake kFourChildren -o Makefile + make +to build the example app. +Likely you must set the environment variable KDEDIR (to e.g. /opt/kde3). + + + +Find more details on: + http://www.geocities.com/gigafalk/qextmdi.htm diff --git a/kmdi/test/hello.cpp b/kmdi/test/hello.cpp new file mode 100644 index 000000000..f3a10f65c --- /dev/null +++ b/kmdi/test/hello.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** $Id$ +** +** Copyright (C) 1992-1999 Troll Tech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "hello.h" +#include +#include +#include +#include + +/* + Constructs a Hello widget. Starts a 40 ms animation timer. +*/ + +Hello::Hello( const char *title, const char *text, QWidget *parentWidget ) + : KMdiChildView(title, parentWidget), t(text), b(0) +{ + QTimer *timer = new QTimer(this); + QObject::connect( timer, SIGNAL(timeout()), SLOT(animate()) ); + timer->start( 40 ); + + resize( 260, 130 ); +} + + +/* + This private slot is called each time the timer fires. +*/ + +void Hello::animate() +{ + b = (b + 1) & 15; + repaint( false ); +} + + +/* + Handles mouse button release events for the Hello widget. + + We emit the clicked() signal when the mouse is released inside + the widget. +*/ + +void Hello::mouseReleaseEvent( QMouseEvent *e ) +{ + if ( rect().contains( e->pos() ) ) + emit clicked(); +} + + +/* + Handles paint events for the Hello widget. + + Flicker-free update. The text is first drawn in the pixmap and the + pixmap is then blt'ed to the screen. +*/ + +void Hello::paintEvent( QPaintEvent * ) +{ + static int sin_tbl[16] = { + 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38}; + + if ( t.isEmpty() ) + return; + + // 1: Compute some sizes, positions etc. + QFontMetrics fm = fontMetrics(); + int w = fm.width(t) + 20; + int h = fm.height() * 2; + int pmx = width()/2 - w/2; + int pmy = height()/2 - h/2; + + // 2: Create the pixmap and fill it with the widget's background + QPixmap pm( w, h ); + pm.fill( this, pmx, pmy ); + + // 3: Paint the pixmap. Cool wave effect + QPainter p; + int x = 10; + int y = h/2 + fm.descent(); + int i = 0; + p.begin( &pm ); + p.setFont( font() ); + while ( !t[i].isNull() ) { + int i16 = (b+i) & 15; + p.setPen( QColor((15-i16)*16,255,255,QColor::Hsv) ); + p.drawText( x, y-sin_tbl[i16]*h/800, t.mid(i,1), 1 ); + x += fm.width( t[i] ); + i++; + } + p.end(); + + // 4: Copy the pixmap to the Hello widget + bitBlt( this, pmx, pmy, &pm ); +} + +#include "hello.moc" + diff --git a/kmdi/test/hello.h b/kmdi/test/hello.h new file mode 100644 index 000000000..59c18f3f2 --- /dev/null +++ b/kmdi/test/hello.h @@ -0,0 +1,38 @@ +/**************************************************************************** +** $Id$ +** +** Copyright (C) 1992-1999 Troll Tech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef HELLO_H +#define HELLO_H + +#include +#include + +class QWidget; +class QMouseEvent; +class QPaintEvent; + +class Hello : public KMdiChildView +{ + Q_OBJECT +public: + Hello( const char *title, const char *text, QWidget* parentWidget = 0 ); +signals: + void clicked(); +protected: + void mouseReleaseEvent( QMouseEvent * ); + void paintEvent( QPaintEvent * ); +private slots: + void animate(); +private: + QString t; + int b; +}; + +#endif diff --git a/kmdi/test/main.cpp b/kmdi/test/main.cpp new file mode 100644 index 000000000..95d9c2f83 --- /dev/null +++ b/kmdi/test/main.cpp @@ -0,0 +1,103 @@ +//---------------------------------------------------------------------------- +// filename : main.cpp +//---------------------------------------------------------------------------- +// Project : Qt MDI extension +// +// begin : 07/1999 by Szymon Stefanek as part of kvirc +// (an IRC application) +// changes : 09/1999 by Falk Brettschneider to create an +// stand-alone Qt extension set of +// classes and a Qt-based library +// 02/2000 by Massimo Morin (mmorin@schedsys.com) +// +// copyright : (C) 1999-2000 by Szymon Stefanek (stefanek@tin.it) +// and +// Falk Brettschneider +// email : falkbr@kdevelop.org (Falk Brettschneider) +//---------------------------------------------------------------------------- +// +//---------------------------------------------------------------------------- +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +//---------------------------------------------------------------------------- + +#ifndef NO_KDE +# include + KApplication* theApp; +#else +# include + QApplication* theApp; +#endif + +//#include +#include "mainwidget.h" +#include "hello.h" + +#define SHOW(v) cout << #v << " -> " << v << endl; + +int main( int argc, char **argv ) +{ +#ifndef NO_KDE + KApplication a(argc,argv,"KFourChildren"); +#else + QApplication a(argc,argv); +#endif + theApp = &a; + + RestartWidget* restartWidget = new RestartWidget; + MainWidget* mainWdg = new MainWidget(restartWidget->dockConfig,restartWidget->mdimode); + restartWidget->setWindow(mainWdg); + + Hello* h1 = new Hello( "Hello1", "Click the right mouse button on the mainframe!", mainWdg); + h1->setTabCaption("Tab changed"); + h1->setBackgroundColor( Qt::white ); + mainWdg->addWindow( h1); +// SHOW(h1->caption()); +// SHOW(h1->tabCaption()); + + QWidget* w = new QWidget(mainWdg); + KMdiChildView* h2 = mainWdg->createWrapper(w, "I'm a common but wrapped QWidget!", "Hello2"); + mainWdg->addWindow( h2 ); +// SHOW(h2->caption()); +// SHOW(h2->tabCaption()); + + Hello* h3 = new Hello( "Hello3", "Dock me using the taskbar button context menu!", 0); + h3->setBackgroundColor( Qt::white ); + h3->setFont( QFont("times",20,QFont::Bold) ); + mainWdg->addWindow( h3, KMdi::Detach ); // undock this! + h3->setGeometry( 20, 20, 400, 100); + + Hello* h4 = new Hello( "Hello4", "Hello world!", mainWdg); + h4->setMDICaption("Hello4 both changed"); + h4->setFont( QFont("times",32,QFont::Bold) ); + mainWdg->addWindow( h4); +// SHOW(h4->caption()); +// SHOW(h4->tabCaption()); + + Hello* h5 = new Hello( "Hello5", "I'm not a MDI widget :-("); + h5->setGeometry(40, 40, 400, 100); + h5->setFont( QFont("times",20,QFont::Bold) ); + h5->setCaption("MDI Test Application"); + h5->show(); + +#if 0 + KMdiIterator *it = mainWdg->createIterator(); + for ( it->first(); !it->isDone(); it->next()) { + //cout << "--> " << it->currentItem()->caption() << endl; + + } + //delete it; +#endif + + mainWdg->resize(500,500); + a.setMainWidget( restartWidget ); + restartWidget->show(); + mainWdg->show(); + + mainWdg->cascadeWindows(); + return a.exec(); +} diff --git a/kmdi/test/mainwidget.cpp b/kmdi/test/mainwidget.cpp new file mode 100644 index 000000000..872f9df27 --- /dev/null +++ b/kmdi/test/mainwidget.cpp @@ -0,0 +1,147 @@ +/*************************************************************************** + mainwidget.cpp - description + ------------------- + begin : Mon Nov 8 1999 + copyright : (C) 1999 by Falk Brettschneider + email : falkbr@kdevelop.org + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mainwidget.h" + +MainWidget::MainWidget(QDomElement& dockConfig,KMdi::MdiMode mode) +: KMdiMainFrm(0L, "theMDIMainFrm",mode) + ,m_dockConfig(dockConfig) +{ + setIDEAlModeStyle(1); // KDEV3 + + dockManager->setReadDockConfigMode(KDockManager::RestoreAllDockwidgets); + initMenu(); + + if (m_dockConfig.hasChildNodes()) { + readDockConfig(m_dockConfig); + } + + QMultiLineEdit* mle = new QMultiLineEdit(0L,"theMultiLineEditWidget"); + mle->setText("This is a QMultiLineEdit widget."); + addToolWindow( mle, KDockWidget::DockBottom, m_pMdi, 70); + + QMultiLineEdit* mle2 = new QMultiLineEdit(0L,"theMultiLineEditWidget2"); + addToolWindow( mle2, KDockWidget::DockCenter, mle, 70); + + QMultiLineEdit* mle3 = new QMultiLineEdit(0L,"theMultiLineEditWidget3"); + addToolWindow( mle3, KDockWidget::DockCenter, mle, 70); + + QMultiLineEdit* mle4 = new QMultiLineEdit(0L,"theMultiLineEditWidget4"); + addToolWindow( mle4, KDockWidget::DockCenter, mle, 70); + + KMdiToolViewAccessor *tva=createToolWindow(); + tva->setWidgetToWrap(new QMultiLineEdit(tva->wrapperWidget(),"theMultiLineEditWidget5")); + tva->placeAndShow(KDockWidget::DockCenter,mle,70); + + QListView* lv = new QListView(0L,"theListViewWidget"); +#include "../res/filenew.xpm" + lv->setIcon(filenew); + lv->addColumn("Test", 50); + lv->addColumn("KMDI", 70); + new QListViewItem(lv,QString("test"),QString("test")); + addToolWindow( lv, KDockWidget::DockLeft, m_pMdi, 35, "1"); + + QListView* lv2 = new QListView(0L,"theListViewWidget2"); + lv2->setIcon(filenew); + lv2->addColumn("Test2", 50); + lv2->addColumn("KMDI2", 70); + new QListViewItem(lv,QString("test2"),QString("test2")); + addToolWindow( lv2, KDockWidget::DockCenter, lv, 35, "2"); + + QListView* lv3 = new QListView(0L,"theListViewWidget3"); + lv3->setIcon(filenew); + lv3->addColumn("Test3", 50); + lv3->addColumn("KMDI3", 70); + new QListViewItem(lv,QString("test3"),QString("test3")); + addToolWindow( lv3, KDockWidget::DockCenter, lv, 35, "3"); + + dockManager->finishReadDockConfig(); + + setMenuForSDIModeSysButtons( menuBar()); +} + +MainWidget::~MainWidget() +{ + writeDockConfig(m_dockConfig); + QDomDocument doc = m_dockConfig.ownerDocument(); + QString s = doc.toString(); + QFile f("/tmp/dc.txt"); + f.open(IO_ReadWrite); + f.writeBlock(s.latin1(), s.length()); + f.close(); +} + +void MainWidget::initMenu() +{ + menuBar()->insertItem("&Window", windowMenu()); + menuBar()->insertItem("&Docking", dockHideShowMenu()); +} + +/** additionally fit the system menu button position to the menu position */ +void MainWidget::resizeEvent( QResizeEvent *pRSE) +{ + KMdiMainFrm::resizeEvent( pRSE); + setSysButtonsAtMenuPosition(); +} + +RestartWidget::RestartWidget():KMainWindow() +{ + mdimode=KMdi::ChildframeMode; + QVBoxLayout* bl = new QVBoxLayout(this); + QLabel* l = new QLabel("This is for the testing of\nKMdiMainFrm::read/writeDockConfig().\n", this); + QCheckBox* b1 = new QCheckBox("KMdiMainFrm close/restart", this); + b1->toggle(); + QObject::connect(b1, SIGNAL(stateChanged(int)), this, SLOT(onStateChanged(int))); + bl->add(l); + bl->add(b1); + bl->setMargin(10); + bl->activate(); + show(); + + dockConfig = domDoc.createElement("dockConfig"); + domDoc.appendChild(dockConfig); +} + +void RestartWidget::onStateChanged(int on) +{ + if (on) { + m_w = new MainWidget(dockConfig,mdimode); + m_w->resize(500,500); + m_w->show(); + } + else { + mdimode=m_w->mdiMode(); + m_w->close(); + delete m_w; + } + +} + +void RestartWidget::setWindow(MainWidget *w) { + m_w=w; +} + +#include "mainwidget.moc" diff --git a/kmdi/test/mainwidget.h b/kmdi/test/mainwidget.h new file mode 100644 index 000000000..d8f61c1cb --- /dev/null +++ b/kmdi/test/mainwidget.h @@ -0,0 +1,71 @@ +/*************************************************************************** + mainwidget.h - description + ------------------- + begin : Mon Nov 8 1999 + copyright : (C) 1999 by Falk Brettschneider + email : falkbr@kdevelop.org + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef MAINWIDGET_H +#define MAINWIDGET_H + +#include +#include +#include +#include +#include + +/** + *@author Falk Brettschneider + */ +class MainWidget : public KMdiMainFrm +{ + Q_OBJECT +public: + MainWidget(QDomElement& dockConfig,KMdi::MdiMode mode); + virtual ~MainWidget(); + void initMenu(); + +protected: // Protected methods + virtual void resizeEvent( QResizeEvent *pRSE); +private: + QDomElement m_dockConfig; +}; + + + +/** + *@author Falk Brettschneider + * This allows me to test KMdiMainFrm::read/writeDockConfig by + * closing and restarting the MainWidget via checkbox click. + */ +class RestartWidget : public KMainWindow +{ + Q_OBJECT +// methods +public: + RestartWidget(); + void setWindow(MainWidget *w); + +private slots: + void onStateChanged(int on); + +// attributes +public: + QDomDocument domDoc; + QDomElement dockConfig; + KMdi::MdiMode mdimode; +private: + MainWidget *m_w; +}; + +#endif -- cgit v1.2.1