From 2c42f320612ac0a4a5a041b437536c74884c1669 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Mon, 7 Nov 2011 21:50:33 -0600 Subject: Rename kwin to twin (Part 2 of 2) --- tdeui/kdockwindow.h | 41 ---- tdeui/kdoctwindow.h | 41 ++++ tdeui/kwindowinfo.cpp | 178 --------------- tdeui/kwindowinfo.h | 145 ------------ tdeui/kwindowlistmenu.cpp | 257 --------------------- tdeui/kwindowlistmenu.h | 74 ------- tdeui/tests/kwindowtest.cpp | 528 -------------------------------------------- tdeui/tests/kwindowtest.h | 71 ------ tdeui/tests/twindowtest.cpp | 528 ++++++++++++++++++++++++++++++++++++++++++++ tdeui/tests/twindowtest.h | 71 ++++++ tdeui/twindowinfo.cpp | 178 +++++++++++++++ tdeui/twindowinfo.h | 145 ++++++++++++ tdeui/twindowlistmenu.cpp | 257 +++++++++++++++++++++ tdeui/twindowlistmenu.h | 74 +++++++ 14 files changed, 1294 insertions(+), 1294 deletions(-) delete mode 100644 tdeui/kdockwindow.h create mode 100644 tdeui/kdoctwindow.h delete mode 100644 tdeui/kwindowinfo.cpp delete mode 100644 tdeui/kwindowinfo.h delete mode 100644 tdeui/kwindowlistmenu.cpp delete mode 100644 tdeui/kwindowlistmenu.h delete mode 100644 tdeui/tests/kwindowtest.cpp delete mode 100644 tdeui/tests/kwindowtest.h create mode 100644 tdeui/tests/twindowtest.cpp create mode 100644 tdeui/tests/twindowtest.h create mode 100644 tdeui/twindowinfo.cpp create mode 100644 tdeui/twindowinfo.h create mode 100644 tdeui/twindowlistmenu.cpp create mode 100644 tdeui/twindowlistmenu.h (limited to 'tdeui') diff --git a/tdeui/kdockwindow.h b/tdeui/kdockwindow.h deleted file mode 100644 index 4b7a34049..000000000 --- a/tdeui/kdockwindow.h +++ /dev/null @@ -1,41 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999 Matthias Ettrich - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KDOCKWINDOW_H -#define KDOCKWINDOW_H - -#include -#include - -#ifndef KDE_NO_COMPAT -/** - * \brief Obsolete system tray support - * - * @deprecated - * This class is obsolete, it is provided for compatibility only. - * Use KSystemTray instead. - */ -class KDE_DEPRECATED KDockWindow : public KSystemTray -{ - Q_OBJECT -public: - KDockWindow( TQWidget* parent = 0, const char* name = 0 ) - : KSystemTray( parent, name ) {} - ~KDockWindow() {} -}; -#endif -#endif diff --git a/tdeui/kdoctwindow.h b/tdeui/kdoctwindow.h new file mode 100644 index 000000000..4b7a34049 --- /dev/null +++ b/tdeui/kdoctwindow.h @@ -0,0 +1,41 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999 Matthias Ettrich + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KDOCKWINDOW_H +#define KDOCKWINDOW_H + +#include +#include + +#ifndef KDE_NO_COMPAT +/** + * \brief Obsolete system tray support + * + * @deprecated + * This class is obsolete, it is provided for compatibility only. + * Use KSystemTray instead. + */ +class KDE_DEPRECATED KDockWindow : public KSystemTray +{ + Q_OBJECT +public: + KDockWindow( TQWidget* parent = 0, const char* name = 0 ) + : KSystemTray( parent, name ) {} + ~KDockWindow() {} +}; +#endif +#endif diff --git a/tdeui/kwindowinfo.cpp b/tdeui/kwindowinfo.cpp deleted file mode 100644 index 436aa5227..000000000 --- a/tdeui/kwindowinfo.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * copyright : (C) 2001-2002 by Richard Moore - * License : This file is released under the terms of the LGPL, version 2. - * email : rich@kde.org - */ - -#include -#include -#include -#include -#include -#include - -#include "twindowinfo.h" -#include "twindowinfo.moc" - -static const int UNSPECIFIED_TIMEOUT = -1; -static const int DEFAULT_MESSAGE_TIMEOUT = 3000; - -KWindowInfo::KWindowInfo( TQWidget *parent, const char *name ) - : TQObject( parent, name ), win( parent ), autoDel( false ) -{ -} - -KWindowInfo::~KWindowInfo() -{ -} - -void KWindowInfo::showMessage( TQWidget *window, const TQString &text, int timeout ) -{ - KWindowInfo *info = new KWindowInfo( window ); - info->autoDel = true; - info->message( text, timeout ); - if ( timeout == 0 ) - delete info; -} - -void KWindowInfo::showMessage( TQWidget *window, const TQString &text, const TQPixmap &pix, int timeout ) -{ - KWindowInfo *info = new KWindowInfo( window ); - info->autoDel = true; - info->message( text, pix, timeout ); -} - -void KWindowInfo::message( const TQString &text ) -{ - message( text, TQPixmap(), UNSPECIFIED_TIMEOUT ); -} - -void KWindowInfo::message( const TQString &text, const TQPixmap &pix ) -{ - message( text, pix, UNSPECIFIED_TIMEOUT ); -} - -void KWindowInfo::message( const TQString &text, int timeout ) -{ - message( text, TQPixmap(), timeout ); -} - -void KWindowInfo::message( const TQString &text, const TQPixmap &pix, int timeout ) -{ - if ( timeout != 0 ) - save(); - - display( text, pix ); - - if ( timeout < 0 ) - timeout = DEFAULT_MESSAGE_TIMEOUT; - if ( timeout != 0 ) - TQTimer::singleShot( timeout, this, TQT_SLOT( restore() ) ); -} - -void KWindowInfo::permanent( const TQString &text ) -{ -#ifdef Q_WS_X11 - oldMiniIcon = KWin::icon( win->winId(), 16, 16, true ); - oldIcon = KWin::icon( win->winId(), 34, 34, false ); - if ( oldIcon.isNull() ) - oldIcon = KWin::icon( win->winId(), 32, 32, true ); -#endif - - permanent( text, oldIcon ); -} - -void KWindowInfo::permanent( const TQString &text, const TQPixmap &pix ) -{ - if ( !oldText.isNull() ) { - TQObjectList *l = queryList( TQTIMER_OBJECT_NAME_STRING ); - TQObjectListIt it( *l ); - TQObject *obj; - - while ( (obj = it.current()) != 0 ) { - ++it; - delete obj; - } - delete l; - } - - oldText = TQString::null; - display( text, pix ); -} - -void KWindowInfo::display( const TQString &text, const TQPixmap &pix ) -{ - TQPixmap icon; - if ( pix.isNull() ) - icon.load( "bell.png" ); - else - icon = pix; - - if ( win->inherits( "KSystemTray" ) ) { - KSystemTray *tray = static_cast( win ); - tray->setPixmap( icon ); - TQToolTip::add( tray, text ); - return; - } - - win->setCaption( text ); - win->setIcon( icon ); -#ifdef Q_WS_X11 - KWin::setIcons( win->winId(), icon, icon ); -#endif -} - -void KWindowInfo::save() -{ - if ( !oldText.isNull() ) - return; - - if ( win->inherits( "KSystemTray" ) ) { - KSystemTray *tray = static_cast( win ); - oldIcon = *(tray->pixmap()); - oldText = TQToolTip::textFor( tray ); - return; - } - - oldText = win->caption(); -#ifdef Q_WS_X11 - oldMiniIcon = KWin::icon( win->winId(), 16, 16, true ); - oldIcon = KWin::icon( win->winId(), 34, 34, false ); - if ( oldIcon.isNull() ) - oldIcon = KWin::icon( win->winId(), 32, 32, true ); -#endif - - if ( oldIcon.isNull() ) { - const TQPixmap *px = win->icon(); - if ( px ) - oldIcon = *px; - else - oldIcon.resize( 0, 0 ); - } -} - -void KWindowInfo::restore() -{ - if ( win->inherits( "KSystemTray" ) ) { - KSystemTray *tray = static_cast( win ); - tray->setPixmap( oldIcon ); - TQToolTip::add( tray, oldText ); - oldText = TQString::null; - return; - } - - win->setIcon( oldIcon ); -#ifdef Q_WS_X11 - KWin::setIcons( win->winId(), oldIcon, oldMiniIcon ); -#endif - win->setCaption( oldText ); - oldText = TQString::null; - - if ( autoDel ) - delete this; -} - - - - - diff --git a/tdeui/kwindowinfo.h b/tdeui/kwindowinfo.h deleted file mode 100644 index 780578d75..000000000 --- a/tdeui/kwindowinfo.h +++ /dev/null @@ -1,145 +0,0 @@ -// -*- c++ -*- - -/* - * copyright : (C) 2001-2002 by Richard Moore - * License : This file is released under the terms of the LGPL, version 2. - * email : rich@kde.org - */ - -#ifndef KWINDOWINFO_H -#define KWINDOWINFO_H - -#include -#include -#include - -#include - -/** - * Displays messages in the window icon and title. The message is usually - * transient with the original title and icon being restored automatically - * after a specified time. The simplest use displays a text message in the - * window title: - * \code - * KWindowInfo::showMessage( this, i18n("Message Body") ); - * \endcode - * This more complex example changes the window icon, as well as - * displaying the text. In addition, this example overrides the - * default timeout to ensure the message is only displayed for 1 - * second. - * \code - * TQPixmap px; - * px.load( "lo16-app-logtracker.png" ); - * KWindowInfo::showMessage( this, i18n("Message Body"), px, 1000 ); - * \endcode - * If the parent window inherits KSystemTray then KWindowInfo changes the - * pixmap and tooltip of the system window to display the message. - * - * @author Richard Moore, rich@kde.org - * @since 3.1 -*/ -class TDEUI_EXPORT KWindowInfo : public TQObject -{ - Q_OBJECT - -public: - /** - * Creates a KWindowInfo with the specified parent. - */ - KWindowInfo( TQWidget *parent, const char *name=0 ); - - /** - * Cleans up. - */ - virtual ~KWindowInfo(); - - /** - * Returns true iff the object should delete itself when it resets. - */ - bool autoDelete() const { return autoDel; } - - /** - * Set to true if you want the object to delete itself when the message - * timeout occurs. - */ - void setAutoDelete( bool enable ) { autoDel = enable; } - - /** - * Utility method to display a title bar message for the specified - * window. - */ - static void showMessage( TQWidget *window, const TQString &text, int timeout = -1 ); - - /** - * Utility method to display a title bar message and icon for the - * specified window. - */ - static void showMessage( TQWidget *window, const TQString &text, - const TQPixmap &pix, int timeout = -1 ); - -public slots: - /** - * Shows the specified text in the window title. - */ - void message( const TQString &text ); - - /** - * Shows the specified text in the window title, and sets the window icon. - */ - void message( const TQString &text, const TQPixmap &pix ); - - /** - * Shows the specified text in the window title for the specified time. - */ - void message( const TQString &text, int timeout ); - - /** - * Shows the specified icon and text in the window title and WM - * icon, for the specified time. The time is a delay specified in - * milliseconds, or one of the two special values. The special - * values are -1 which means the default timeout should be used, - * and 0 which means the message is permanent. - */ - void message( const TQString &text, const TQPixmap &pix, int timeout ); - - /** - * Shows the specified text in the window title with no timeout. - */ - void permanent( const TQString &text ); - - /** - * Shows the specified text and icon in the window title with no timeout. - */ - void permanent( const TQString &text, const TQPixmap &pix ); - -protected: - /** - * Displays the message in the titlebar/icon. - */ - virtual void display( const TQString &text, const TQPixmap &pix ); - -protected slots: - /** - * Saves the window title and icon. - */ - virtual void save(); - - /** - * Resets the window title and icon to the saved values. If - * auto-delete is enabled then the object is deleted. - */ - virtual void restore(); - -private: - TQWidget *win; - TQPixmap oldIcon; - TQPixmap oldMiniIcon; - TQString oldText; - bool autoDel; - - /* @internal */ - class Private *d; -}; - -#endif // KWINDOWINFO_H - diff --git a/tdeui/kwindowlistmenu.cpp b/tdeui/kwindowlistmenu.cpp deleted file mode 100644 index 1334abd6e..000000000 --- a/tdeui/kwindowlistmenu.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/***************************************************************** - -Copyright (c) 2000 Matthias Elter - Matthias Ettrich - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -******************************************************************/ - -#include - -#ifdef Q_WS_X11 - -#include "config.h" -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include - -#undef Bool -#include "twindowlistmenu.h" -#include "twindowlistmenu.moc" - -static TQCString twinName() { - TQCString appname; - int screen_number = DefaultScreen(qt_xdisplay()); - if (screen_number == 0) - appname = "twin"; - else - appname.sprintf("twin-screen-%d", screen_number); - return appname; -} - -// helper class -namespace -{ -class NameSortedInfoList : public TQPtrList -{ -public: - NameSortedInfoList() { setAutoDelete(true); } - ~NameSortedInfoList() {} - -private: - int compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 ); -}; - -int NameSortedInfoList::compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 ) -{ - KWin::WindowInfo *i1 = static_cast(s1); - KWin::WindowInfo *i2 = static_cast(s2); - TQString title1, title2; - if (i1) - title1 = i1->visibleNameWithState().lower(); - if (i2) - title2 = i2->visibleNameWithState().lower(); - return title1.compare(title2); -} - -} // namespace - -KWindowListMenu::KWindowListMenu(TQWidget *parent, const char *name) - : KPopupMenu(parent, name) -{ - twin_module = new KWinModule(TQT_TQOBJECT(this)); - - connect(this, TQT_SIGNAL(activated(int)), TQT_SLOT(slotExec(int))); -} - -KWindowListMenu::~KWindowListMenu() -{ - -} - -static bool standaloneDialog( const KWin::WindowInfo* info, const NameSortedInfoList& list ) -{ - WId group = info->groupLeader(); - if( group == 0 ) - { - return info->transientFor() == qt_xrootwin(); - } - for( TQPtrListIterator< KWin::WindowInfo > it( list ); - it.current() != NULL; - ++it ) - if( (*it)->groupLeader() == group ) - return false; - return true; -} - -void KWindowListMenu::init() -{ - int i, d; - i = 0; - - int nd = twin_module->numberOfDesktops(); - int cd = twin_module->currentDesktop(); - WId active_window = twin_module->activeWindow(); - - // Make sure the popup is not too wide, otherwise clicking in the middle of kdesktop - // wouldn't leave any place for the popup, and release would activate some menu entry. - int maxwidth = kapp->desktop()->screenGeometry( this ).width() / 2 - 100; - - clear(); - map.clear(); - - int unclutter = insertItem( i18n("Unclutter Windows"), - this, TQT_SLOT( slotUnclutterWindows() ) ); - int cascade = insertItem( i18n("Cascade Windows"), - this, TQT_SLOT( slotCascadeWindows() ) ); - - // if we only have one desktop we won't be showing titles, so put a separator in - if (nd == 1) - { - insertSeparator(); - } - - - TQValueList windows; - for (TQValueList::ConstIterator it = twin_module->windows().begin(); - it != twin_module->windows().end(); ++it) { - windows.append( KWin::windowInfo( *it, NET::WMDesktop )); - } - bool show_all_desktops_group = ( nd > 1 ); - for (d = 1; d <= nd + (show_all_desktops_group ? 1 : 0); d++) { - bool on_all_desktops = ( d > nd ); - int items = 0; - - if (!active_window && d == cd) - setItemChecked(1000 + d, true); - - NameSortedInfoList list; - list.setAutoDelete(true); - - for (TQValueList::ConstIterator it = windows.begin(); - it != windows.end(); ++it) { - if (((*it).desktop() == d) || (on_all_desktops && (*it).onAllDesktops()) - || (!show_all_desktops_group && (*it).onAllDesktops())) { - list.inSort(new KWin::WindowInfo( (*it).win(), - NET::WMVisibleName | NET::WMState | NET::XAWMState | NET::WMWindowType, - NET::WM2GroupLeader | NET::WM2TransientFor )); - } - } - - for (KWin::WindowInfo* info = list.first(); info; info = list.next(), ++i) - { - TQString itemText = KStringHandler::cPixelSqueeze(info->visibleNameWithState(), fontMetrics(), maxwidth); - NET::WindowType windowType = info->windowType( NET::NormalMask | NET::DesktopMask - | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask - | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask ); - if ( (windowType == NET::Normal || windowType == NET::Unknown - || (windowType == NET::Dialog && standaloneDialog( info, list ))) - && !(info->state() & NET::SkipTaskbar) ) { - TQPixmap pm = KWin::icon(info->win(), 16, 16, true ); - items++; - - // ok, we have items on this desktop, let's show the title - if ( items == 1 && nd > 1 ) - { - if( !on_all_desktops ) - insertTitle(twin_module->desktopName( d ), 1000 + d); - else - insertTitle(i18n("On All Desktops"), 2000 ); - } - - // Avoid creating unwanted accelerators. - itemText.replace('&', TQString::tqfromLatin1("&&")); - insertItem( pm, itemText, i); - map.insert(i, info->win()); - if (info->win() == active_window) - setItemChecked(i, true); - } - } - - if (d == cd) - { - setItemEnabled(unclutter, items > 0); - setItemEnabled(cascade, items > 0); - } - } - - // no windows? - if (i == 0) - { - if (nd > 1) - { - // because we don't have any titles, nor a separator - insertSeparator(); - } - - setItemEnabled(insertItem(i18n("No Windows")), false); - } -} - -void KWindowListMenu::slotExec(int id) -{ - if (id == 2000) - ; // do nothing - else if (id > 1000) - KWin::setCurrentDesktop(id - 1000); - else if ( id >= 0 ) - KWin::forceActiveWindow(map[id]); -} - -// This popup is much more useful from keyboard if it has the active -// window active by default - however, TQPopupMenu tries hard to resist. -// TQPopupMenu::popup() resets the active item, so this needs to be -// called after popup(). -void KWindowListMenu::selectActiveWindow() -{ - for( unsigned int i = 0; - i < count(); - ++i ) - if( isItemChecked( idAt( i ))) - { - setActiveItem( i ); - break; - } -} - -void KWindowListMenu::slotUnclutterWindows() -{ - kapp->dcopClient()->send(twinName(), "KWinInterface", "unclutterDesktop()", TQString("")); -} - -void KWindowListMenu::slotCascadeWindows() -{ - kapp->dcopClient()->send(twinName(), "KWinInterface", "cascadeDesktop()", TQString("")); -} - -void KWindowListMenu::virtual_hook( int id, void* data ) -{ KPopupMenu::virtual_hook( id, data ); } - -#endif // Q_WS_X11 - diff --git a/tdeui/kwindowlistmenu.h b/tdeui/kwindowlistmenu.h deleted file mode 100644 index dcd81826f..000000000 --- a/tdeui/kwindowlistmenu.h +++ /dev/null @@ -1,74 +0,0 @@ -/***************************************************************** - -Copyright (c) 2000 Matthias Elter - Matthias Ettrich - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -******************************************************************/ - -#ifndef __twindowlistmenu_h__ -#define __twindowlistmenu_h__ - -#include -#include - -#ifdef Q_MOC_RUN -#define Q_WS_X11 -#endif // Q_MOC_RUN - -#ifdef Q_WS_X11 // not yet available for non-X11 - -class KWinModule; -class KWindowListMenuPrivate; - -class TDEUI_EXPORT KWindowListMenu : public KPopupMenu -{ - Q_OBJECT - -public: - KWindowListMenu( TQWidget *parent = 0, const char *name = 0 ); - virtual ~KWindowListMenu(); - - void init(); - -public slots: - /** - * Pre-selects the active window in the popup menu, for faster - * keyboard navigation. Needs to be called after popup(). - * Should not be used when the popup is invoked using the mouse. - */ - void selectActiveWindow(); - -protected slots: - void slotExec(int id); - void slotUnclutterWindows(); - void slotCascadeWindows(); - -private: - KWinModule* twin_module; - TQMap map; -protected: - virtual void virtual_hook( int id, void* data ); -private: - KWindowListMenuPrivate *d; -}; - -#endif // Q_WS_X11 - -#endif diff --git a/tdeui/tests/kwindowtest.cpp b/tdeui/tests/kwindowtest.cpp deleted file mode 100644 index 9c4ac571a..000000000 --- a/tdeui/tests/kwindowtest.cpp +++ /dev/null @@ -1,528 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "twindowtest.h" - -#include - - -//#include - -/* - 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; - -testWindow::testWindow (TQWidget *parent, const char *name) - : KMainWindow (parent,name) -{ - ena=false; - setCaption("test window"); -setAutoSaveSettings(); - /******************************/ - /* First, we setup setup Menus */ - /******************************/ - menuBar = new KMenuBar (this); - - // First popup... - fileMenu = new TQPopupMenu; - // 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(), - TQT_SLOT( quit() ), ALT + Key_Q ); - - // Another popup... - toolBarMenu = new TQPopupMenu; - menuBar->insertItem ("&Toolbars", toolBarMenu); - toolBarMenu->insertItem ("(Un)Hide tollbar 1", this, TQT_SLOT(slotHide1())); - toolBarMenu->insertItem ("(Un)Hide tollbar 2", this, TQT_SLOT(slotHide2())); - - itemsMenu = new TQPopupMenu; - menuBar->insertItem ("&Items", itemsMenu); - - exitB = true; // exit button is shown - lineL = true; // Lined is enabled - greenF = false; // Frame not inserted - - 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())); - - 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); - //clk->setFrameStyle(TQFrame::NoFrame); - //statusBar->insertWidget(clk, 70, 2); - - /***********************/ - /* And now the toolbar */ - /***********************/ - - // pixmap which we will use - TQPixmap pix; - - // Create toolbar... - tb = toolBar(); - - // and set it to full width - tb->setFullSize(true); - - - - // First four buttons - pix = BarIcon("filenew"); - itemId = tb->insertButton(pix, 0, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotNew()), - true, "Create.. (toggles upper button)", 50); - pix = BarIcon("fileopen"); - tb->insertButton(pix, 1, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotOpen()), - false, "Open"); - pix = BarIcon("filefloppy"); - tb->insertButton(pix, 2, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotSave()), - true, "Save (beep or delayed popup)"); - tb->setDelayedPopup(2, itemsMenu); - pix = BarIcon("fileprint"); - tb->insertButton(pix, 3, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotPrint()), - true, "Print (enables/disables open)"); - - // And a combobox - // arguments: text (or strList), ID, writable, signal, object, slot, enabled, - // tooltiptext, size - tb->insertCombo (TQString("one"), 4, true, TQT_SIGNAL(activated(const TQString&)), this, - TQT_SLOT(slotList(const TQString&)), true, "ComboBox", 150); - - - // Then one line editor - // arguments: text, id, signal, object (this), slot, enabled, tooltiptext, size - tb->insertLined ("ftp://ftp.kde.org/pub/kde", 5, TQT_SIGNAL(returnPressed()), this, - TQT_SLOT(slotReturn()), true, "Location", 200); - - // 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"); - tb->insertButton(pix, 6, TQT_SIGNAL(clicked()), KApplication::kApplication(), - TQT_SLOT( quit() ), true, "Exit"); - tb->alignItemRight (6); - - // Another toolbar - tb1 = new KToolBar(this, TQMainWindow::DockTop); // this one is normal and has separators - - - pix = BarIcon("filenew"); - tb1->insertButton(pix, 0, true, "Create new file2 (Toggle)"); - tb1->setToggle(0); - tb1->addConnection (0, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggle(bool))); - - pix = BarIcon("fileopen"); - tb1->insertButton(pix, 1, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotOpen()), - true, "Open (starts progres in sb)"); - - tb1->insertSeparator (); - - pix = BarIcon("filefloppy"); - tb1->insertButton(pix, 2, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotSave()), - 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); - - connect (tb1, TQT_SIGNAL(toggled(int)), this, TQT_SLOT(slotToggled(int))); - - // 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. - widget = new TQMultiLineEdit (this); - - // Setup is now complete - - // add two toolbars - //addToolBar (tb1); - //addToolBar (tb); - - 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))); - - // 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 - completions = new TQPopupMenu; - - completions->insertItem("/"); - completions->insertItem("/usr/"); - completions->insertItem("/lib/"); - completions->insertItem("/var/"); - completions->insertItem("/bin/"); - completions->insertItem("/kde/"); - completions->insertItem("/home/"); - completions->insertItem("/vmlinuz :-)"); - - connect (completions, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotCompletionsMenu(int))); - pr = 0; -} -/***********************************/ -/* Now slots for toolbar actions */ -/***********************************/ -void testWindow::slotToggled(int) -{ - statusBar->message ("Buton toggled", 1500); -} - -void testWindow::slotInsertClock() -{ - //DigitalClock *clock = new DigitalClock(tb1); - //clock->setFrameStyle(TQFrame::NoFrame); - //tb1->insertWidget(8, 70, clock); -} - -void testWindow::slotNew() -{ - tb1->toggleButton(0); - toolBar()->removeItem( itemId ); -} -void testWindow::slotOpen() -{ - if (pr == 0) - pr = new TQProgressBar (statusBar); -// statusBar->message(pr); - timer = new TQTimer (pr); - - connect (timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotGoGoGoo())); - 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() -{ - TQString s = "You entered "; - s = s + tb->getLinedText(5); - statusBar->changeItem(s, 0); - -} -void testWindow::slotList(const TQString &str) -{ - TQString s = "You chose "; - s = s + str; - statusBar->changeItem(s, 0); -} - -void testWindow::slotCompletion() -{ - // Now do a completion - // Call your completing function and set that text in klined - // TQString s = tb->getLinedText(/* ID */ 4) - // TQString completed = complete (s); - // tb->setLinedText(/* ID */ 4, completed.data()) - - // for now this: - - completions->popup(TQCursor::pos()); // This popup should understunf keys up and down - - /* 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. - */ - TQString s(tb->getComboItem(4)); // get text in combo - s+= "(completing)"; - //tb->getCombo(4)->changeItem(s.data()); // setTextIncombo - -} - -void testWindow::slotCompletionsMenu(int id) -{ - // Now set text in lined - TQString s =completions->text(id); - 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); - //debug ("twindowtest: deleted clock"); - - delete tb; - delete tb1; - delete menuBar; - - qDebug ("twindowtest finished"); -} - -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 - { - TQPixmap pix; - pix = BarIcon("exit"); - tb->insertButton(pix, 6, TQT_SIGNAL(clicked()), KApplication::kApplication(), - TQT_SLOT( quit() ), true, "Exit"); - 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 - - TQFrame *myFrame = tb1->getFrame(10); // get frame pointer - - 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() - myFrame->setBackgroundColor (TQColor("green")); - - 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() -{ - TQStringList list; - 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); - - i = TQMessageBox::information(0, "Select", "Select type of mainwidget", - "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; -} - -#include "twindowtest.moc" - diff --git a/tdeui/tests/kwindowtest.h b/tdeui/tests/kwindowtest.h deleted file mode 100644 index 14e2a6da8..000000000 --- a/tdeui/tests/kwindowtest.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef testwindow_h -#define testwindow_h - -#include -#include -#include -#include -#include -#include -#include - -class TQMultiLineEdit; -class KToolBarRadioGroup; -class KHelpMenu; - -class testWindow : public KMainWindow -{ - Q_OBJECT - -public: - testWindow (TQWidget *parent=0, const char *name=0); - ~testWindow (); - -public slots: - void beFixed(); - void beYFixed(); - - void slotNew(); - void slotPrint(); - void slotReturn(); - void slotSave(); - void slotList(const TQString &str); - void slotOpen(); - void slotCompletion(); - void slotCompletionsMenu(int id); - void slotHide2 (); - void slotInsertClock(); - void slotHide1 (); - void slotLined (); - void slotImportant (); - void slotExit(); - void slotFrame(); - void slotListCompletion(); - void slotMessage(int, bool); - void slotToggle(bool); - void slotClearCombo(); - void slotGoGoGoo(); - void slotInsertListInCombo (); - void slotMakeItem3Current (); - void slotToggled(int); -protected: - KMenuBar *menuBar; - TQPopupMenu *fileMenu; - TQPopupMenu *itemsMenu; - TQPopupMenu *completions; - TQPopupMenu *toolBarMenu; - KStatusBar *statusBar; - KHelpMenu *helpMenu; - KToolBar *tb; - KToolBar *tb1; - bool lineL; - bool exitB; - bool greenF; - bool ena; - TQMultiLineEdit *widget; - TQTimer *timer; - TQProgressBar *pr; - KToolBarRadioGroup *rg; -}; -#endif - diff --git a/tdeui/tests/twindowtest.cpp b/tdeui/tests/twindowtest.cpp new file mode 100644 index 000000000..9c4ac571a --- /dev/null +++ b/tdeui/tests/twindowtest.cpp @@ -0,0 +1,528 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "twindowtest.h" + +#include + + +//#include + +/* + 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; + +testWindow::testWindow (TQWidget *parent, const char *name) + : KMainWindow (parent,name) +{ + ena=false; + setCaption("test window"); +setAutoSaveSettings(); + /******************************/ + /* First, we setup setup Menus */ + /******************************/ + menuBar = new KMenuBar (this); + + // First popup... + fileMenu = new TQPopupMenu; + // 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(), + TQT_SLOT( quit() ), ALT + Key_Q ); + + // Another popup... + toolBarMenu = new TQPopupMenu; + menuBar->insertItem ("&Toolbars", toolBarMenu); + toolBarMenu->insertItem ("(Un)Hide tollbar 1", this, TQT_SLOT(slotHide1())); + toolBarMenu->insertItem ("(Un)Hide tollbar 2", this, TQT_SLOT(slotHide2())); + + itemsMenu = new TQPopupMenu; + menuBar->insertItem ("&Items", itemsMenu); + + exitB = true; // exit button is shown + lineL = true; // Lined is enabled + greenF = false; // Frame not inserted + + 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())); + + 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); + //clk->setFrameStyle(TQFrame::NoFrame); + //statusBar->insertWidget(clk, 70, 2); + + /***********************/ + /* And now the toolbar */ + /***********************/ + + // pixmap which we will use + TQPixmap pix; + + // Create toolbar... + tb = toolBar(); + + // and set it to full width + tb->setFullSize(true); + + + + // First four buttons + pix = BarIcon("filenew"); + itemId = tb->insertButton(pix, 0, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotNew()), + true, "Create.. (toggles upper button)", 50); + pix = BarIcon("fileopen"); + tb->insertButton(pix, 1, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotOpen()), + false, "Open"); + pix = BarIcon("filefloppy"); + tb->insertButton(pix, 2, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotSave()), + true, "Save (beep or delayed popup)"); + tb->setDelayedPopup(2, itemsMenu); + pix = BarIcon("fileprint"); + tb->insertButton(pix, 3, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotPrint()), + true, "Print (enables/disables open)"); + + // And a combobox + // arguments: text (or strList), ID, writable, signal, object, slot, enabled, + // tooltiptext, size + tb->insertCombo (TQString("one"), 4, true, TQT_SIGNAL(activated(const TQString&)), this, + TQT_SLOT(slotList(const TQString&)), true, "ComboBox", 150); + + + // Then one line editor + // arguments: text, id, signal, object (this), slot, enabled, tooltiptext, size + tb->insertLined ("ftp://ftp.kde.org/pub/kde", 5, TQT_SIGNAL(returnPressed()), this, + TQT_SLOT(slotReturn()), true, "Location", 200); + + // 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"); + tb->insertButton(pix, 6, TQT_SIGNAL(clicked()), KApplication::kApplication(), + TQT_SLOT( quit() ), true, "Exit"); + tb->alignItemRight (6); + + // Another toolbar + tb1 = new KToolBar(this, TQMainWindow::DockTop); // this one is normal and has separators + + + pix = BarIcon("filenew"); + tb1->insertButton(pix, 0, true, "Create new file2 (Toggle)"); + tb1->setToggle(0); + tb1->addConnection (0, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggle(bool))); + + pix = BarIcon("fileopen"); + tb1->insertButton(pix, 1, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotOpen()), + true, "Open (starts progres in sb)"); + + tb1->insertSeparator (); + + pix = BarIcon("filefloppy"); + tb1->insertButton(pix, 2, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotSave()), + 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); + + connect (tb1, TQT_SIGNAL(toggled(int)), this, TQT_SLOT(slotToggled(int))); + + // 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. + widget = new TQMultiLineEdit (this); + + // Setup is now complete + + // add two toolbars + //addToolBar (tb1); + //addToolBar (tb); + + 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))); + + // 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 + completions = new TQPopupMenu; + + completions->insertItem("/"); + completions->insertItem("/usr/"); + completions->insertItem("/lib/"); + completions->insertItem("/var/"); + completions->insertItem("/bin/"); + completions->insertItem("/kde/"); + completions->insertItem("/home/"); + completions->insertItem("/vmlinuz :-)"); + + connect (completions, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotCompletionsMenu(int))); + pr = 0; +} +/***********************************/ +/* Now slots for toolbar actions */ +/***********************************/ +void testWindow::slotToggled(int) +{ + statusBar->message ("Buton toggled", 1500); +} + +void testWindow::slotInsertClock() +{ + //DigitalClock *clock = new DigitalClock(tb1); + //clock->setFrameStyle(TQFrame::NoFrame); + //tb1->insertWidget(8, 70, clock); +} + +void testWindow::slotNew() +{ + tb1->toggleButton(0); + toolBar()->removeItem( itemId ); +} +void testWindow::slotOpen() +{ + if (pr == 0) + pr = new TQProgressBar (statusBar); +// statusBar->message(pr); + timer = new TQTimer (pr); + + connect (timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotGoGoGoo())); + 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() +{ + TQString s = "You entered "; + s = s + tb->getLinedText(5); + statusBar->changeItem(s, 0); + +} +void testWindow::slotList(const TQString &str) +{ + TQString s = "You chose "; + s = s + str; + statusBar->changeItem(s, 0); +} + +void testWindow::slotCompletion() +{ + // Now do a completion + // Call your completing function and set that text in klined + // TQString s = tb->getLinedText(/* ID */ 4) + // TQString completed = complete (s); + // tb->setLinedText(/* ID */ 4, completed.data()) + + // for now this: + + completions->popup(TQCursor::pos()); // This popup should understunf keys up and down + + /* 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. + */ + TQString s(tb->getComboItem(4)); // get text in combo + s+= "(completing)"; + //tb->getCombo(4)->changeItem(s.data()); // setTextIncombo + +} + +void testWindow::slotCompletionsMenu(int id) +{ + // Now set text in lined + TQString s =completions->text(id); + 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); + //debug ("twindowtest: deleted clock"); + + delete tb; + delete tb1; + delete menuBar; + + qDebug ("twindowtest finished"); +} + +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 + { + TQPixmap pix; + pix = BarIcon("exit"); + tb->insertButton(pix, 6, TQT_SIGNAL(clicked()), KApplication::kApplication(), + TQT_SLOT( quit() ), true, "Exit"); + 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 + + TQFrame *myFrame = tb1->getFrame(10); // get frame pointer + + 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() + myFrame->setBackgroundColor (TQColor("green")); + + 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() +{ + TQStringList list; + 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); + + i = TQMessageBox::information(0, "Select", "Select type of mainwidget", + "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; +} + +#include "twindowtest.moc" + diff --git a/tdeui/tests/twindowtest.h b/tdeui/tests/twindowtest.h new file mode 100644 index 000000000..14e2a6da8 --- /dev/null +++ b/tdeui/tests/twindowtest.h @@ -0,0 +1,71 @@ +#ifndef testwindow_h +#define testwindow_h + +#include +#include +#include +#include +#include +#include +#include + +class TQMultiLineEdit; +class KToolBarRadioGroup; +class KHelpMenu; + +class testWindow : public KMainWindow +{ + Q_OBJECT + +public: + testWindow (TQWidget *parent=0, const char *name=0); + ~testWindow (); + +public slots: + void beFixed(); + void beYFixed(); + + void slotNew(); + void slotPrint(); + void slotReturn(); + void slotSave(); + void slotList(const TQString &str); + void slotOpen(); + void slotCompletion(); + void slotCompletionsMenu(int id); + void slotHide2 (); + void slotInsertClock(); + void slotHide1 (); + void slotLined (); + void slotImportant (); + void slotExit(); + void slotFrame(); + void slotListCompletion(); + void slotMessage(int, bool); + void slotToggle(bool); + void slotClearCombo(); + void slotGoGoGoo(); + void slotInsertListInCombo (); + void slotMakeItem3Current (); + void slotToggled(int); +protected: + KMenuBar *menuBar; + TQPopupMenu *fileMenu; + TQPopupMenu *itemsMenu; + TQPopupMenu *completions; + TQPopupMenu *toolBarMenu; + KStatusBar *statusBar; + KHelpMenu *helpMenu; + KToolBar *tb; + KToolBar *tb1; + bool lineL; + bool exitB; + bool greenF; + bool ena; + TQMultiLineEdit *widget; + TQTimer *timer; + TQProgressBar *pr; + KToolBarRadioGroup *rg; +}; +#endif + diff --git a/tdeui/twindowinfo.cpp b/tdeui/twindowinfo.cpp new file mode 100644 index 000000000..436aa5227 --- /dev/null +++ b/tdeui/twindowinfo.cpp @@ -0,0 +1,178 @@ +/* + * copyright : (C) 2001-2002 by Richard Moore + * License : This file is released under the terms of the LGPL, version 2. + * email : rich@kde.org + */ + +#include +#include +#include +#include +#include +#include + +#include "twindowinfo.h" +#include "twindowinfo.moc" + +static const int UNSPECIFIED_TIMEOUT = -1; +static const int DEFAULT_MESSAGE_TIMEOUT = 3000; + +KWindowInfo::KWindowInfo( TQWidget *parent, const char *name ) + : TQObject( parent, name ), win( parent ), autoDel( false ) +{ +} + +KWindowInfo::~KWindowInfo() +{ +} + +void KWindowInfo::showMessage( TQWidget *window, const TQString &text, int timeout ) +{ + KWindowInfo *info = new KWindowInfo( window ); + info->autoDel = true; + info->message( text, timeout ); + if ( timeout == 0 ) + delete info; +} + +void KWindowInfo::showMessage( TQWidget *window, const TQString &text, const TQPixmap &pix, int timeout ) +{ + KWindowInfo *info = new KWindowInfo( window ); + info->autoDel = true; + info->message( text, pix, timeout ); +} + +void KWindowInfo::message( const TQString &text ) +{ + message( text, TQPixmap(), UNSPECIFIED_TIMEOUT ); +} + +void KWindowInfo::message( const TQString &text, const TQPixmap &pix ) +{ + message( text, pix, UNSPECIFIED_TIMEOUT ); +} + +void KWindowInfo::message( const TQString &text, int timeout ) +{ + message( text, TQPixmap(), timeout ); +} + +void KWindowInfo::message( const TQString &text, const TQPixmap &pix, int timeout ) +{ + if ( timeout != 0 ) + save(); + + display( text, pix ); + + if ( timeout < 0 ) + timeout = DEFAULT_MESSAGE_TIMEOUT; + if ( timeout != 0 ) + TQTimer::singleShot( timeout, this, TQT_SLOT( restore() ) ); +} + +void KWindowInfo::permanent( const TQString &text ) +{ +#ifdef Q_WS_X11 + oldMiniIcon = KWin::icon( win->winId(), 16, 16, true ); + oldIcon = KWin::icon( win->winId(), 34, 34, false ); + if ( oldIcon.isNull() ) + oldIcon = KWin::icon( win->winId(), 32, 32, true ); +#endif + + permanent( text, oldIcon ); +} + +void KWindowInfo::permanent( const TQString &text, const TQPixmap &pix ) +{ + if ( !oldText.isNull() ) { + TQObjectList *l = queryList( TQTIMER_OBJECT_NAME_STRING ); + TQObjectListIt it( *l ); + TQObject *obj; + + while ( (obj = it.current()) != 0 ) { + ++it; + delete obj; + } + delete l; + } + + oldText = TQString::null; + display( text, pix ); +} + +void KWindowInfo::display( const TQString &text, const TQPixmap &pix ) +{ + TQPixmap icon; + if ( pix.isNull() ) + icon.load( "bell.png" ); + else + icon = pix; + + if ( win->inherits( "KSystemTray" ) ) { + KSystemTray *tray = static_cast( win ); + tray->setPixmap( icon ); + TQToolTip::add( tray, text ); + return; + } + + win->setCaption( text ); + win->setIcon( icon ); +#ifdef Q_WS_X11 + KWin::setIcons( win->winId(), icon, icon ); +#endif +} + +void KWindowInfo::save() +{ + if ( !oldText.isNull() ) + return; + + if ( win->inherits( "KSystemTray" ) ) { + KSystemTray *tray = static_cast( win ); + oldIcon = *(tray->pixmap()); + oldText = TQToolTip::textFor( tray ); + return; + } + + oldText = win->caption(); +#ifdef Q_WS_X11 + oldMiniIcon = KWin::icon( win->winId(), 16, 16, true ); + oldIcon = KWin::icon( win->winId(), 34, 34, false ); + if ( oldIcon.isNull() ) + oldIcon = KWin::icon( win->winId(), 32, 32, true ); +#endif + + if ( oldIcon.isNull() ) { + const TQPixmap *px = win->icon(); + if ( px ) + oldIcon = *px; + else + oldIcon.resize( 0, 0 ); + } +} + +void KWindowInfo::restore() +{ + if ( win->inherits( "KSystemTray" ) ) { + KSystemTray *tray = static_cast( win ); + tray->setPixmap( oldIcon ); + TQToolTip::add( tray, oldText ); + oldText = TQString::null; + return; + } + + win->setIcon( oldIcon ); +#ifdef Q_WS_X11 + KWin::setIcons( win->winId(), oldIcon, oldMiniIcon ); +#endif + win->setCaption( oldText ); + oldText = TQString::null; + + if ( autoDel ) + delete this; +} + + + + + diff --git a/tdeui/twindowinfo.h b/tdeui/twindowinfo.h new file mode 100644 index 000000000..780578d75 --- /dev/null +++ b/tdeui/twindowinfo.h @@ -0,0 +1,145 @@ +// -*- c++ -*- + +/* + * copyright : (C) 2001-2002 by Richard Moore + * License : This file is released under the terms of the LGPL, version 2. + * email : rich@kde.org + */ + +#ifndef KWINDOWINFO_H +#define KWINDOWINFO_H + +#include +#include +#include + +#include + +/** + * Displays messages in the window icon and title. The message is usually + * transient with the original title and icon being restored automatically + * after a specified time. The simplest use displays a text message in the + * window title: + * \code + * KWindowInfo::showMessage( this, i18n("Message Body") ); + * \endcode + * This more complex example changes the window icon, as well as + * displaying the text. In addition, this example overrides the + * default timeout to ensure the message is only displayed for 1 + * second. + * \code + * TQPixmap px; + * px.load( "lo16-app-logtracker.png" ); + * KWindowInfo::showMessage( this, i18n("Message Body"), px, 1000 ); + * \endcode + * If the parent window inherits KSystemTray then KWindowInfo changes the + * pixmap and tooltip of the system window to display the message. + * + * @author Richard Moore, rich@kde.org + * @since 3.1 +*/ +class TDEUI_EXPORT KWindowInfo : public TQObject +{ + Q_OBJECT + +public: + /** + * Creates a KWindowInfo with the specified parent. + */ + KWindowInfo( TQWidget *parent, const char *name=0 ); + + /** + * Cleans up. + */ + virtual ~KWindowInfo(); + + /** + * Returns true iff the object should delete itself when it resets. + */ + bool autoDelete() const { return autoDel; } + + /** + * Set to true if you want the object to delete itself when the message + * timeout occurs. + */ + void setAutoDelete( bool enable ) { autoDel = enable; } + + /** + * Utility method to display a title bar message for the specified + * window. + */ + static void showMessage( TQWidget *window, const TQString &text, int timeout = -1 ); + + /** + * Utility method to display a title bar message and icon for the + * specified window. + */ + static void showMessage( TQWidget *window, const TQString &text, + const TQPixmap &pix, int timeout = -1 ); + +public slots: + /** + * Shows the specified text in the window title. + */ + void message( const TQString &text ); + + /** + * Shows the specified text in the window title, and sets the window icon. + */ + void message( const TQString &text, const TQPixmap &pix ); + + /** + * Shows the specified text in the window title for the specified time. + */ + void message( const TQString &text, int timeout ); + + /** + * Shows the specified icon and text in the window title and WM + * icon, for the specified time. The time is a delay specified in + * milliseconds, or one of the two special values. The special + * values are -1 which means the default timeout should be used, + * and 0 which means the message is permanent. + */ + void message( const TQString &text, const TQPixmap &pix, int timeout ); + + /** + * Shows the specified text in the window title with no timeout. + */ + void permanent( const TQString &text ); + + /** + * Shows the specified text and icon in the window title with no timeout. + */ + void permanent( const TQString &text, const TQPixmap &pix ); + +protected: + /** + * Displays the message in the titlebar/icon. + */ + virtual void display( const TQString &text, const TQPixmap &pix ); + +protected slots: + /** + * Saves the window title and icon. + */ + virtual void save(); + + /** + * Resets the window title and icon to the saved values. If + * auto-delete is enabled then the object is deleted. + */ + virtual void restore(); + +private: + TQWidget *win; + TQPixmap oldIcon; + TQPixmap oldMiniIcon; + TQString oldText; + bool autoDel; + + /* @internal */ + class Private *d; +}; + +#endif // KWINDOWINFO_H + diff --git a/tdeui/twindowlistmenu.cpp b/tdeui/twindowlistmenu.cpp new file mode 100644 index 000000000..1334abd6e --- /dev/null +++ b/tdeui/twindowlistmenu.cpp @@ -0,0 +1,257 @@ +/***************************************************************** + +Copyright (c) 2000 Matthias Elter + Matthias Ettrich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +******************************************************************/ + +#include + +#ifdef Q_WS_X11 + +#include "config.h" +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#undef Bool +#include "twindowlistmenu.h" +#include "twindowlistmenu.moc" + +static TQCString twinName() { + TQCString appname; + int screen_number = DefaultScreen(qt_xdisplay()); + if (screen_number == 0) + appname = "twin"; + else + appname.sprintf("twin-screen-%d", screen_number); + return appname; +} + +// helper class +namespace +{ +class NameSortedInfoList : public TQPtrList +{ +public: + NameSortedInfoList() { setAutoDelete(true); } + ~NameSortedInfoList() {} + +private: + int compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 ); +}; + +int NameSortedInfoList::compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 ) +{ + KWin::WindowInfo *i1 = static_cast(s1); + KWin::WindowInfo *i2 = static_cast(s2); + TQString title1, title2; + if (i1) + title1 = i1->visibleNameWithState().lower(); + if (i2) + title2 = i2->visibleNameWithState().lower(); + return title1.compare(title2); +} + +} // namespace + +KWindowListMenu::KWindowListMenu(TQWidget *parent, const char *name) + : KPopupMenu(parent, name) +{ + twin_module = new KWinModule(TQT_TQOBJECT(this)); + + connect(this, TQT_SIGNAL(activated(int)), TQT_SLOT(slotExec(int))); +} + +KWindowListMenu::~KWindowListMenu() +{ + +} + +static bool standaloneDialog( const KWin::WindowInfo* info, const NameSortedInfoList& list ) +{ + WId group = info->groupLeader(); + if( group == 0 ) + { + return info->transientFor() == qt_xrootwin(); + } + for( TQPtrListIterator< KWin::WindowInfo > it( list ); + it.current() != NULL; + ++it ) + if( (*it)->groupLeader() == group ) + return false; + return true; +} + +void KWindowListMenu::init() +{ + int i, d; + i = 0; + + int nd = twin_module->numberOfDesktops(); + int cd = twin_module->currentDesktop(); + WId active_window = twin_module->activeWindow(); + + // Make sure the popup is not too wide, otherwise clicking in the middle of kdesktop + // wouldn't leave any place for the popup, and release would activate some menu entry. + int maxwidth = kapp->desktop()->screenGeometry( this ).width() / 2 - 100; + + clear(); + map.clear(); + + int unclutter = insertItem( i18n("Unclutter Windows"), + this, TQT_SLOT( slotUnclutterWindows() ) ); + int cascade = insertItem( i18n("Cascade Windows"), + this, TQT_SLOT( slotCascadeWindows() ) ); + + // if we only have one desktop we won't be showing titles, so put a separator in + if (nd == 1) + { + insertSeparator(); + } + + + TQValueList windows; + for (TQValueList::ConstIterator it = twin_module->windows().begin(); + it != twin_module->windows().end(); ++it) { + windows.append( KWin::windowInfo( *it, NET::WMDesktop )); + } + bool show_all_desktops_group = ( nd > 1 ); + for (d = 1; d <= nd + (show_all_desktops_group ? 1 : 0); d++) { + bool on_all_desktops = ( d > nd ); + int items = 0; + + if (!active_window && d == cd) + setItemChecked(1000 + d, true); + + NameSortedInfoList list; + list.setAutoDelete(true); + + for (TQValueList::ConstIterator it = windows.begin(); + it != windows.end(); ++it) { + if (((*it).desktop() == d) || (on_all_desktops && (*it).onAllDesktops()) + || (!show_all_desktops_group && (*it).onAllDesktops())) { + list.inSort(new KWin::WindowInfo( (*it).win(), + NET::WMVisibleName | NET::WMState | NET::XAWMState | NET::WMWindowType, + NET::WM2GroupLeader | NET::WM2TransientFor )); + } + } + + for (KWin::WindowInfo* info = list.first(); info; info = list.next(), ++i) + { + TQString itemText = KStringHandler::cPixelSqueeze(info->visibleNameWithState(), fontMetrics(), maxwidth); + NET::WindowType windowType = info->windowType( NET::NormalMask | NET::DesktopMask + | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask + | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask ); + if ( (windowType == NET::Normal || windowType == NET::Unknown + || (windowType == NET::Dialog && standaloneDialog( info, list ))) + && !(info->state() & NET::SkipTaskbar) ) { + TQPixmap pm = KWin::icon(info->win(), 16, 16, true ); + items++; + + // ok, we have items on this desktop, let's show the title + if ( items == 1 && nd > 1 ) + { + if( !on_all_desktops ) + insertTitle(twin_module->desktopName( d ), 1000 + d); + else + insertTitle(i18n("On All Desktops"), 2000 ); + } + + // Avoid creating unwanted accelerators. + itemText.replace('&', TQString::tqfromLatin1("&&")); + insertItem( pm, itemText, i); + map.insert(i, info->win()); + if (info->win() == active_window) + setItemChecked(i, true); + } + } + + if (d == cd) + { + setItemEnabled(unclutter, items > 0); + setItemEnabled(cascade, items > 0); + } + } + + // no windows? + if (i == 0) + { + if (nd > 1) + { + // because we don't have any titles, nor a separator + insertSeparator(); + } + + setItemEnabled(insertItem(i18n("No Windows")), false); + } +} + +void KWindowListMenu::slotExec(int id) +{ + if (id == 2000) + ; // do nothing + else if (id > 1000) + KWin::setCurrentDesktop(id - 1000); + else if ( id >= 0 ) + KWin::forceActiveWindow(map[id]); +} + +// This popup is much more useful from keyboard if it has the active +// window active by default - however, TQPopupMenu tries hard to resist. +// TQPopupMenu::popup() resets the active item, so this needs to be +// called after popup(). +void KWindowListMenu::selectActiveWindow() +{ + for( unsigned int i = 0; + i < count(); + ++i ) + if( isItemChecked( idAt( i ))) + { + setActiveItem( i ); + break; + } +} + +void KWindowListMenu::slotUnclutterWindows() +{ + kapp->dcopClient()->send(twinName(), "KWinInterface", "unclutterDesktop()", TQString("")); +} + +void KWindowListMenu::slotCascadeWindows() +{ + kapp->dcopClient()->send(twinName(), "KWinInterface", "cascadeDesktop()", TQString("")); +} + +void KWindowListMenu::virtual_hook( int id, void* data ) +{ KPopupMenu::virtual_hook( id, data ); } + +#endif // Q_WS_X11 + diff --git a/tdeui/twindowlistmenu.h b/tdeui/twindowlistmenu.h new file mode 100644 index 000000000..dcd81826f --- /dev/null +++ b/tdeui/twindowlistmenu.h @@ -0,0 +1,74 @@ +/***************************************************************** + +Copyright (c) 2000 Matthias Elter + Matthias Ettrich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +******************************************************************/ + +#ifndef __twindowlistmenu_h__ +#define __twindowlistmenu_h__ + +#include +#include + +#ifdef Q_MOC_RUN +#define Q_WS_X11 +#endif // Q_MOC_RUN + +#ifdef Q_WS_X11 // not yet available for non-X11 + +class KWinModule; +class KWindowListMenuPrivate; + +class TDEUI_EXPORT KWindowListMenu : public KPopupMenu +{ + Q_OBJECT + +public: + KWindowListMenu( TQWidget *parent = 0, const char *name = 0 ); + virtual ~KWindowListMenu(); + + void init(); + +public slots: + /** + * Pre-selects the active window in the popup menu, for faster + * keyboard navigation. Needs to be called after popup(). + * Should not be used when the popup is invoked using the mouse. + */ + void selectActiveWindow(); + +protected slots: + void slotExec(int id); + void slotUnclutterWindows(); + void slotCascadeWindows(); + +private: + KWinModule* twin_module; + TQMap map; +protected: + virtual void virtual_hook( int id, void* data ); +private: + KWindowListMenuPrivate *d; +}; + +#endif // Q_WS_X11 + +#endif -- cgit v1.2.3