From d888cfa39e8b38abe17f3d425d19cb8235136a79 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 1 Feb 2013 17:25:43 -0600 Subject: Fix FTBFS --- doc/api/kfontchooser.png | Bin 23765 -> 0 bytes doc/api/kfontdialog.png | Bin 28510 -> 0 bytes doc/api/kfontrequester.png | Bin 3444 -> 0 bytes doc/api/tdefontchooser.png | Bin 0 -> 23765 bytes doc/api/tdefontdialog.png | Bin 0 -> 28510 bytes doc/api/tdefontrequester.png | Bin 0 -> 3444 bytes .../tdetexteditor/blockselectiondcopinterface.cpp | 33 - .../tdetexteditor/blockselectiondcopinterface.h | 60 - .../tdetexteditor/blockselectioninterface.cpp | 74 - interfaces/tdetexteditor/blockselectioninterface.h | 82 - .../bloctdeselectiondcopinterface.cpp | 33 + .../tdetexteditor/bloctdeselectiondcopinterface.h | 60 + .../tdetexteditor/bloctdeselectioninterface.cpp | 74 + .../tdetexteditor/bloctdeselectioninterface.h | 82 + kdewidgets/pics/kactionselector.png | Bin 282 -> 0 bytes kdewidgets/pics/kfontcombo.png | Bin 1194 -> 0 bytes kdewidgets/pics/kfontrequester.png | Bin 1035 -> 0 bytes kdewidgets/pics/klistbox.png | Bin 1035 -> 0 bytes kdewidgets/pics/klistview.png | Bin 1185 -> 0 bytes kdewidgets/pics/tdeactionselector.png | Bin 0 -> 282 bytes kdewidgets/pics/tdefontcombo.png | Bin 0 -> 1194 bytes kdewidgets/pics/tdefontrequester.png | Bin 0 -> 1035 bytes kdewidgets/pics/tdelistbox.png | Bin 0 -> 1035 bytes kdewidgets/pics/tdelistview.png | Bin 0 -> 1185 bytes tdecore/kaccel.cpp | 663 ------ tdecore/kaccel.h | 390 ---- tdecore/kaccelaction.cpp | 565 ----- tdecore/kaccelaction.h | 576 ----- tdecore/kaccelbase.cpp | 616 ----- tdecore/kaccelbase.h | 282 --- tdecore/kaccelmanager.cpp | 872 ------- tdecore/kaccelmanager.h | 88 - tdecore/kaccelmanager_private.h | 196 -- tdecore/kaccelprivate.h | 53 - tdecore/kcheckaccelerators.cpp | 216 -- tdecore/kcheckaccelerators.h | 96 - tdecore/kchectdeaccelerators.cpp | 216 ++ tdecore/kchectdeaccelerators.h | 96 + tdecore/kshortcut.cpp | 671 ------ tdecore/kshortcut.h | 851 ------- tdecore/kshortcutlist.cpp | 220 -- tdecore/kshortcutlist.h | 295 --- tdecore/kshortcutmenu.cpp | 161 -- tdecore/kshortcutmenu.h | 61 - tdecore/kstdaccel.cpp | 396 ---- tdecore/kstdaccel.h | 492 ---- tdecore/network/ipv6blacklist | 3 - tdecore/network/ipv6blactdelist | 3 + tdecore/tdeaccel.cpp | 663 ++++++ tdecore/tdeaccel.h | 390 ++++ tdecore/tdeaccelaction.cpp | 565 +++++ tdecore/tdeaccelaction.h | 576 +++++ tdecore/tdeaccelbase.cpp | 616 +++++ tdecore/tdeaccelbase.h | 282 +++ tdecore/tdeaccelmanager.cpp | 872 +++++++ tdecore/tdeaccelmanager.h | 88 + tdecore/tdeaccelmanager_private.h | 196 ++ tdecore/tdeaccelprivate.h | 53 + tdecore/tdeshortcut.cpp | 671 ++++++ tdecore/tdeshortcut.h | 851 +++++++ tdecore/tdeshortcutlist.cpp | 220 ++ tdecore/tdeshortcutlist.h | 295 +++ tdecore/tdeshortcutmenu.cpp | 161 ++ tdecore/tdeshortcutmenu.h | 61 + tdecore/tdestdaccel.cpp | 396 ++++ tdecore/tdestdaccel.h | 492 ++++ tdecore/tests/kstdacceltest.cpp | 39 - tdecore/tests/tdestdacceltest.cpp | 39 + tdeio/tdefile/krecentdirs.cpp | 99 - tdeio/tdefile/krecentdirs.h | 70 - tdeio/tdefile/krecentdocument.cpp | 177 -- tdeio/tdefile/krecentdocument.h | 105 - tdeio/tdefile/tderecentdirs.cpp | 99 + tdeio/tdefile/tderecentdirs.h | 70 + tdeio/tdefile/tderecentdocument.cpp | 177 ++ tdeio/tdefile/tderecentdocument.h | 105 + tdeparts/dockmainwindow.cpp | 166 -- tdeparts/dockmainwindow.h | 88 - tdeparts/doctdemainwindow.cpp | 166 ++ tdeparts/doctdemainwindow.h | 88 + tdeui/kaccelgen.h | 280 --- tdeui/kaction.cpp | 1288 ----------- tdeui/kaction.h | 676 ------ tdeui/kactionclasses.cpp | 2421 -------------------- tdeui/kactionclasses.h | 1436 ------------ tdeui/kactioncollection.cpp | 802 ------- tdeui/kactioncollection.h | 393 ---- tdeui/kactionselector.cpp | 540 ----- tdeui/kactionselector.h | 402 ---- tdeui/kactionshortcutlist.h | 79 - tdeui/kfontcombo.cpp | 382 --- tdeui/kfontcombo.h | 179 -- tdeui/kfontdialog.cpp | 799 ------- tdeui/kfontdialog.h | 504 ---- tdeui/kfontrequester.cpp | 127 - tdeui/kfontrequester.h | 157 -- tdeui/klistbox.cpp | 266 --- tdeui/klistbox.h | 128 -- tdeui/klistview.cpp | 2411 ------------------- tdeui/klistview.h | 1094 --------- tdeui/klistviewlineedit.h | 65 - tdeui/klistviewsearchline.cpp | 501 ---- tdeui/klistviewsearchline.h | 264 --- tdeui/kmainwindow.cpp | 1249 ---------- tdeui/kmainwindow.h | 1076 --------- tdeui/kmainwindowiface.cpp | 194 -- tdeui/kmainwindowiface.h | 161 -- tdeui/kpopupmenu.cpp | 694 ------ tdeui/kpopupmenu.h | 282 --- tdeui/kselect.cpp | 534 ----- tdeui/kselect.h | 373 --- tdeui/kshortcutdialog.cpp | 529 ----- tdeui/kshortcutdialog.h | 96 - tdeui/kshortcutdialog_advanced.ui | 254 -- tdeui/kshortcutdialog_simple.ui | 120 - tdeui/ktoolbar.cpp | 2264 ------------------ tdeui/ktoolbar.h | 1130 --------- tdeui/ktoolbarbutton.cpp | 781 ------- tdeui/ktoolbarbutton.h | 331 --- tdeui/ktoolbarhandler.cpp | 246 -- tdeui/ktoolbarhandler.h | 69 - tdeui/ktoolbarlabelaction.cpp | 117 - tdeui/ktoolbarlabelaction.h | 137 -- tdeui/ktoolbarradiogroup.cpp | 77 - tdeui/ktoolbarradiogroup.h | 88 - tdeui/tdeaccelgen.h | 280 +++ tdeui/tdeaction.cpp | 1288 +++++++++++ tdeui/tdeaction.h | 676 ++++++ tdeui/tdeactionclasses.cpp | 2421 ++++++++++++++++++++ tdeui/tdeactionclasses.h | 1436 ++++++++++++ tdeui/tdeactioncollection.cpp | 802 +++++++ tdeui/tdeactioncollection.h | 393 ++++ tdeui/tdeactionselector.cpp | 540 +++++ tdeui/tdeactionselector.h | 402 ++++ tdeui/tdeactionshortcutlist.h | 79 + tdeui/tdefontcombo.cpp | 382 +++ tdeui/tdefontcombo.h | 179 ++ tdeui/tdefontdialog.cpp | 799 +++++++ tdeui/tdefontdialog.h | 504 ++++ tdeui/tdefontrequester.cpp | 127 + tdeui/tdefontrequester.h | 157 ++ tdeui/tdelistbox.cpp | 266 +++ tdeui/tdelistbox.h | 128 ++ tdeui/tdelistview.cpp | 2411 +++++++++++++++++++ tdeui/tdelistview.h | 1095 +++++++++ tdeui/tdelistviewlineedit.h | 65 + tdeui/tdelistviewsearchline.cpp | 501 ++++ tdeui/tdelistviewsearchline.h | 264 +++ tdeui/tdemainwindow.cpp | 1249 ++++++++++ tdeui/tdemainwindow.h | 1076 +++++++++ tdeui/tdemainwindowiface.cpp | 194 ++ tdeui/tdemainwindowiface.h | 161 ++ tdeui/tdepopupmenu.cpp | 694 ++++++ tdeui/tdepopupmenu.h | 282 +++ tdeui/tdeselect.cpp | 534 +++++ tdeui/tdeselect.h | 373 +++ tdeui/tdeshortcutdialog.cpp | 529 +++++ tdeui/tdeshortcutdialog.h | 96 + tdeui/tdeshortcutdialog_advanced.ui | 254 ++ tdeui/tdeshortcutdialog_simple.ui | 120 + tdeui/tdetoolbar.cpp | 2264 ++++++++++++++++++ tdeui/tdetoolbar.h | 1130 +++++++++ tdeui/tdetoolbarbutton.cpp | 781 +++++++ tdeui/tdetoolbarbutton.h | 331 +++ tdeui/tdetoolbarhandler.cpp | 246 ++ tdeui/tdetoolbarhandler.h | 69 + tdeui/tdetoolbarlabelaction.cpp | 117 + tdeui/tdetoolbarlabelaction.h | 137 ++ tdeui/tdetoolbarradiogroup.cpp | 77 + tdeui/tdetoolbarradiogroup.h | 88 + tdeui/tests/kaccelgentest.cpp | 51 - tdeui/tests/kactiontest.cpp | 38 - tdeui/tests/kfontdialogtest.cpp | 51 - tdeui/tests/klistviewtest.cpp | 39 - tdeui/tests/kmainwindowrestoretest.cpp | 41 - tdeui/tests/kmainwindowrestoretest.h | 48 - tdeui/tests/kmainwindowtest.cpp | 38 - tdeui/tests/kmainwindowtest.h | 18 - tdeui/tests/kpopuptest.cpp | 40 - tdeui/tests/ktoolbarlabelactiontest.cpp | 97 - tdeui/tests/ktoolbarlabelactiontestui.rc | 9 - tdeui/tests/tdeaccelgentest.cpp | 51 + tdeui/tests/tdeactiontest.cpp | 38 + tdeui/tests/tdefontdialogtest.cpp | 51 + tdeui/tests/tdelistviewtest.cpp | 39 + tdeui/tests/tdemainwindowrestoretest.cpp | 41 + tdeui/tests/tdemainwindowrestoretest.h | 48 + tdeui/tests/tdemainwindowtest.cpp | 38 + tdeui/tests/tdemainwindowtest.h | 18 + tdeui/tests/tdepopuptest.cpp | 40 + tdeui/tests/tdetoolbarlabelactiontest.cpp | 97 + tdeui/tests/tdetoolbarlabelactiontestui.rc | 9 + 192 files changed, 35223 insertions(+), 35222 deletions(-) delete mode 100644 doc/api/kfontchooser.png delete mode 100644 doc/api/kfontdialog.png delete mode 100644 doc/api/kfontrequester.png create mode 100644 doc/api/tdefontchooser.png create mode 100644 doc/api/tdefontdialog.png create mode 100644 doc/api/tdefontrequester.png delete mode 100644 interfaces/tdetexteditor/blockselectiondcopinterface.cpp delete mode 100644 interfaces/tdetexteditor/blockselectiondcopinterface.h delete mode 100644 interfaces/tdetexteditor/blockselectioninterface.cpp delete mode 100644 interfaces/tdetexteditor/blockselectioninterface.h create mode 100644 interfaces/tdetexteditor/bloctdeselectiondcopinterface.cpp create mode 100644 interfaces/tdetexteditor/bloctdeselectiondcopinterface.h create mode 100644 interfaces/tdetexteditor/bloctdeselectioninterface.cpp create mode 100644 interfaces/tdetexteditor/bloctdeselectioninterface.h delete mode 100644 kdewidgets/pics/kactionselector.png delete mode 100644 kdewidgets/pics/kfontcombo.png delete mode 100644 kdewidgets/pics/kfontrequester.png delete mode 100644 kdewidgets/pics/klistbox.png delete mode 100644 kdewidgets/pics/klistview.png create mode 100644 kdewidgets/pics/tdeactionselector.png create mode 100644 kdewidgets/pics/tdefontcombo.png create mode 100644 kdewidgets/pics/tdefontrequester.png create mode 100644 kdewidgets/pics/tdelistbox.png create mode 100644 kdewidgets/pics/tdelistview.png delete mode 100644 tdecore/kaccel.cpp delete mode 100644 tdecore/kaccel.h delete mode 100644 tdecore/kaccelaction.cpp delete mode 100644 tdecore/kaccelaction.h delete mode 100644 tdecore/kaccelbase.cpp delete mode 100644 tdecore/kaccelbase.h delete mode 100644 tdecore/kaccelmanager.cpp delete mode 100644 tdecore/kaccelmanager.h delete mode 100644 tdecore/kaccelmanager_private.h delete mode 100644 tdecore/kaccelprivate.h delete mode 100644 tdecore/kcheckaccelerators.cpp delete mode 100644 tdecore/kcheckaccelerators.h create mode 100644 tdecore/kchectdeaccelerators.cpp create mode 100644 tdecore/kchectdeaccelerators.h delete mode 100644 tdecore/kshortcut.cpp delete mode 100644 tdecore/kshortcut.h delete mode 100644 tdecore/kshortcutlist.cpp delete mode 100644 tdecore/kshortcutlist.h delete mode 100644 tdecore/kshortcutmenu.cpp delete mode 100644 tdecore/kshortcutmenu.h delete mode 100644 tdecore/kstdaccel.cpp delete mode 100644 tdecore/kstdaccel.h delete mode 100644 tdecore/network/ipv6blacklist create mode 100644 tdecore/network/ipv6blactdelist create mode 100644 tdecore/tdeaccel.cpp create mode 100644 tdecore/tdeaccel.h create mode 100644 tdecore/tdeaccelaction.cpp create mode 100644 tdecore/tdeaccelaction.h create mode 100644 tdecore/tdeaccelbase.cpp create mode 100644 tdecore/tdeaccelbase.h create mode 100644 tdecore/tdeaccelmanager.cpp create mode 100644 tdecore/tdeaccelmanager.h create mode 100644 tdecore/tdeaccelmanager_private.h create mode 100644 tdecore/tdeaccelprivate.h create mode 100644 tdecore/tdeshortcut.cpp create mode 100644 tdecore/tdeshortcut.h create mode 100644 tdecore/tdeshortcutlist.cpp create mode 100644 tdecore/tdeshortcutlist.h create mode 100644 tdecore/tdeshortcutmenu.cpp create mode 100644 tdecore/tdeshortcutmenu.h create mode 100644 tdecore/tdestdaccel.cpp create mode 100644 tdecore/tdestdaccel.h delete mode 100644 tdecore/tests/kstdacceltest.cpp create mode 100644 tdecore/tests/tdestdacceltest.cpp delete mode 100644 tdeio/tdefile/krecentdirs.cpp delete mode 100644 tdeio/tdefile/krecentdirs.h delete mode 100644 tdeio/tdefile/krecentdocument.cpp delete mode 100644 tdeio/tdefile/krecentdocument.h create mode 100644 tdeio/tdefile/tderecentdirs.cpp create mode 100644 tdeio/tdefile/tderecentdirs.h create mode 100644 tdeio/tdefile/tderecentdocument.cpp create mode 100644 tdeio/tdefile/tderecentdocument.h delete mode 100644 tdeparts/dockmainwindow.cpp delete mode 100644 tdeparts/dockmainwindow.h create mode 100644 tdeparts/doctdemainwindow.cpp create mode 100644 tdeparts/doctdemainwindow.h delete mode 100644 tdeui/kaccelgen.h delete mode 100644 tdeui/kaction.cpp delete mode 100644 tdeui/kaction.h delete mode 100644 tdeui/kactionclasses.cpp delete mode 100644 tdeui/kactionclasses.h delete mode 100644 tdeui/kactioncollection.cpp delete mode 100644 tdeui/kactioncollection.h delete mode 100644 tdeui/kactionselector.cpp delete mode 100644 tdeui/kactionselector.h delete mode 100644 tdeui/kactionshortcutlist.h delete mode 100644 tdeui/kfontcombo.cpp delete mode 100644 tdeui/kfontcombo.h delete mode 100644 tdeui/kfontdialog.cpp delete mode 100644 tdeui/kfontdialog.h delete mode 100644 tdeui/kfontrequester.cpp delete mode 100644 tdeui/kfontrequester.h delete mode 100644 tdeui/klistbox.cpp delete mode 100644 tdeui/klistbox.h delete mode 100644 tdeui/klistview.cpp delete mode 100644 tdeui/klistview.h delete mode 100644 tdeui/klistviewlineedit.h delete mode 100644 tdeui/klistviewsearchline.cpp delete mode 100644 tdeui/klistviewsearchline.h delete mode 100644 tdeui/kmainwindow.cpp delete mode 100644 tdeui/kmainwindow.h delete mode 100644 tdeui/kmainwindowiface.cpp delete mode 100644 tdeui/kmainwindowiface.h delete mode 100644 tdeui/kpopupmenu.cpp delete mode 100644 tdeui/kpopupmenu.h delete mode 100644 tdeui/kselect.cpp delete mode 100644 tdeui/kselect.h delete mode 100644 tdeui/kshortcutdialog.cpp delete mode 100644 tdeui/kshortcutdialog.h delete mode 100644 tdeui/kshortcutdialog_advanced.ui delete mode 100644 tdeui/kshortcutdialog_simple.ui delete mode 100644 tdeui/ktoolbar.cpp delete mode 100644 tdeui/ktoolbar.h delete mode 100644 tdeui/ktoolbarbutton.cpp delete mode 100644 tdeui/ktoolbarbutton.h delete mode 100644 tdeui/ktoolbarhandler.cpp delete mode 100644 tdeui/ktoolbarhandler.h delete mode 100644 tdeui/ktoolbarlabelaction.cpp delete mode 100644 tdeui/ktoolbarlabelaction.h delete mode 100644 tdeui/ktoolbarradiogroup.cpp delete mode 100644 tdeui/ktoolbarradiogroup.h create mode 100644 tdeui/tdeaccelgen.h create mode 100644 tdeui/tdeaction.cpp create mode 100644 tdeui/tdeaction.h create mode 100644 tdeui/tdeactionclasses.cpp create mode 100644 tdeui/tdeactionclasses.h create mode 100644 tdeui/tdeactioncollection.cpp create mode 100644 tdeui/tdeactioncollection.h create mode 100644 tdeui/tdeactionselector.cpp create mode 100644 tdeui/tdeactionselector.h create mode 100644 tdeui/tdeactionshortcutlist.h create mode 100644 tdeui/tdefontcombo.cpp create mode 100644 tdeui/tdefontcombo.h create mode 100644 tdeui/tdefontdialog.cpp create mode 100644 tdeui/tdefontdialog.h create mode 100644 tdeui/tdefontrequester.cpp create mode 100644 tdeui/tdefontrequester.h create mode 100644 tdeui/tdelistbox.cpp create mode 100644 tdeui/tdelistbox.h create mode 100644 tdeui/tdelistview.cpp create mode 100644 tdeui/tdelistview.h create mode 100644 tdeui/tdelistviewlineedit.h create mode 100644 tdeui/tdelistviewsearchline.cpp create mode 100644 tdeui/tdelistviewsearchline.h create mode 100644 tdeui/tdemainwindow.cpp create mode 100644 tdeui/tdemainwindow.h create mode 100644 tdeui/tdemainwindowiface.cpp create mode 100644 tdeui/tdemainwindowiface.h create mode 100644 tdeui/tdepopupmenu.cpp create mode 100644 tdeui/tdepopupmenu.h create mode 100644 tdeui/tdeselect.cpp create mode 100644 tdeui/tdeselect.h create mode 100644 tdeui/tdeshortcutdialog.cpp create mode 100644 tdeui/tdeshortcutdialog.h create mode 100644 tdeui/tdeshortcutdialog_advanced.ui create mode 100644 tdeui/tdeshortcutdialog_simple.ui create mode 100644 tdeui/tdetoolbar.cpp create mode 100644 tdeui/tdetoolbar.h create mode 100644 tdeui/tdetoolbarbutton.cpp create mode 100644 tdeui/tdetoolbarbutton.h create mode 100644 tdeui/tdetoolbarhandler.cpp create mode 100644 tdeui/tdetoolbarhandler.h create mode 100644 tdeui/tdetoolbarlabelaction.cpp create mode 100644 tdeui/tdetoolbarlabelaction.h create mode 100644 tdeui/tdetoolbarradiogroup.cpp create mode 100644 tdeui/tdetoolbarradiogroup.h delete mode 100644 tdeui/tests/kaccelgentest.cpp delete mode 100644 tdeui/tests/kactiontest.cpp delete mode 100644 tdeui/tests/kfontdialogtest.cpp delete mode 100644 tdeui/tests/klistviewtest.cpp delete mode 100644 tdeui/tests/kmainwindowrestoretest.cpp delete mode 100644 tdeui/tests/kmainwindowrestoretest.h delete mode 100644 tdeui/tests/kmainwindowtest.cpp delete mode 100644 tdeui/tests/kmainwindowtest.h delete mode 100644 tdeui/tests/kpopuptest.cpp delete mode 100644 tdeui/tests/ktoolbarlabelactiontest.cpp delete mode 100644 tdeui/tests/ktoolbarlabelactiontestui.rc create mode 100644 tdeui/tests/tdeaccelgentest.cpp create mode 100644 tdeui/tests/tdeactiontest.cpp create mode 100644 tdeui/tests/tdefontdialogtest.cpp create mode 100644 tdeui/tests/tdelistviewtest.cpp create mode 100644 tdeui/tests/tdemainwindowrestoretest.cpp create mode 100644 tdeui/tests/tdemainwindowrestoretest.h create mode 100644 tdeui/tests/tdemainwindowtest.cpp create mode 100644 tdeui/tests/tdemainwindowtest.h create mode 100644 tdeui/tests/tdepopuptest.cpp create mode 100644 tdeui/tests/tdetoolbarlabelactiontest.cpp create mode 100644 tdeui/tests/tdetoolbarlabelactiontestui.rc diff --git a/doc/api/kfontchooser.png b/doc/api/kfontchooser.png deleted file mode 100644 index 6357ca289..000000000 Binary files a/doc/api/kfontchooser.png and /dev/null differ diff --git a/doc/api/kfontdialog.png b/doc/api/kfontdialog.png deleted file mode 100644 index 12402d2f2..000000000 Binary files a/doc/api/kfontdialog.png and /dev/null differ diff --git a/doc/api/kfontrequester.png b/doc/api/kfontrequester.png deleted file mode 100644 index 3b36ae1d6..000000000 Binary files a/doc/api/kfontrequester.png and /dev/null differ diff --git a/doc/api/tdefontchooser.png b/doc/api/tdefontchooser.png new file mode 100644 index 000000000..6357ca289 Binary files /dev/null and b/doc/api/tdefontchooser.png differ diff --git a/doc/api/tdefontdialog.png b/doc/api/tdefontdialog.png new file mode 100644 index 000000000..12402d2f2 Binary files /dev/null and b/doc/api/tdefontdialog.png differ diff --git a/doc/api/tdefontrequester.png b/doc/api/tdefontrequester.png new file mode 100644 index 000000000..3b36ae1d6 Binary files /dev/null and b/doc/api/tdefontrequester.png differ diff --git a/interfaces/tdetexteditor/blockselectiondcopinterface.cpp b/interfaces/tdetexteditor/blockselectiondcopinterface.cpp deleted file mode 100644 index 34b7294b2..000000000 --- a/interfaces/tdetexteditor/blockselectiondcopinterface.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "blockselectiondcopinterface.h" -#include "blockselectioninterface.h" - -#include -using namespace KTextEditor; - -BlockSelectionDCOPInterface::BlockSelectionDCOPInterface( BlockSelectionInterface *Parent, const char *name) - : DCOPObject(name) -{ - m_parent = Parent; -} - -BlockSelectionDCOPInterface::~BlockSelectionDCOPInterface() -{ - -} - -uint BlockSelectionDCOPInterface::blockSelectionInterfaceNumber () -{ - return m_parent->blockSelectionInterfaceNumber(); -} -bool BlockSelectionDCOPInterface::blockSelectionMode () -{ - return m_parent->blockSelectionMode (); -} -bool BlockSelectionDCOPInterface::setBlockSelectionMode (bool on) -{ - return m_parent->setBlockSelectionMode (on); -} -bool BlockSelectionDCOPInterface::toggleBlockSelectionMode () -{ - return m_parent->toggleBlockSelectionMode (); -} diff --git a/interfaces/tdetexteditor/blockselectiondcopinterface.h b/interfaces/tdetexteditor/blockselectiondcopinterface.h deleted file mode 100644 index 4b74fd2a0..000000000 --- a/interfaces/tdetexteditor/blockselectiondcopinterface.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef BlockSelection_DCOP_INTERFACE_H -#define BlockSelection_DCOP_INTERFACE_H - -#include -#include -#include -#include - -namespace KTextEditor -{ - class BlockSelectionInterface; - /** - This is the main interface to the BlockSelectionInterface of KTextEditor. - This will provide a consistant dcop interface to all KDE applications that use it. - @short DCOP interface to BlockSelectionInterface. - @author Ian Reinhart Geiser - */ - class KTEXTEDITOR_EXPORT BlockSelectionDCOPInterface : virtual public DCOPObject - { - K_DCOP - - public: - /** - Construct a new interface object for the text editor. - @param Parent the parent BlockSelectionInterface object - that will provide us with the functions for the interface. - @param name the QObject's name - */ - BlockSelectionDCOPInterface( BlockSelectionInterface *Parent, const char *name ); - /** - Destructor - Cleans up the object. - */ - virtual ~BlockSelectionDCOPInterface(); - k_dcop: - uint blockSelectionInterfaceNumber (); - - /** - * Returns the status of the selection mode - true indicates block selection mode is on. - * If this is true, selections applied via the SelectionInterface are handled as - * blockselections and the paste functions of the ClipboardInterface works on - * rectangular blocks of text rather than normal. (copy too, but thats clear I hope ;) - */ - bool blockSelectionMode (); - - /** - * set blockselection mode to state "on" - */ - bool setBlockSelectionMode (bool on) ; - - /** - * toggle blockseletion mode - */ - bool toggleBlockSelectionMode (); - - private: - BlockSelectionInterface *m_parent; - }; -} -#endif diff --git a/interfaces/tdetexteditor/blockselectioninterface.cpp b/interfaces/tdetexteditor/blockselectioninterface.cpp deleted file mode 100644 index 6d562a43e..000000000 --- a/interfaces/tdetexteditor/blockselectioninterface.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001 Christoph Cullmann - - 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. -*/ - -// $Id$ - -#include "blockselectioninterface.h" -#include "blockselectiondcopinterface.h" -#include "document.h" - -namespace KTextEditor -{ - -class PrivateBlockSelectionInterface -{ - public: - PrivateBlockSelectionInterface() {interface = 0;} - ~PrivateBlockSelectionInterface() {} - BlockSelectionDCOPInterface *interface; -}; - -} - -using namespace KTextEditor; - -unsigned int BlockSelectionInterface::globalBlockSelectionInterfaceNumber = 0; - -BlockSelectionInterface::BlockSelectionInterface() -{ - globalBlockSelectionInterfaceNumber++; - myBlockSelectionInterfaceNumber = globalBlockSelectionInterfaceNumber++; - TQString name = "BlockSelectionInterface#" + TQString::number(myBlockSelectionInterfaceNumber); - - d = new PrivateBlockSelectionInterface(); - d->interface = new BlockSelectionDCOPInterface(this, name.latin1()); -} - -BlockSelectionInterface::~BlockSelectionInterface() -{ - delete d->interface; - delete d; -} - -unsigned int BlockSelectionInterface::blockSelectionInterfaceNumber () const -{ - return myBlockSelectionInterfaceNumber; -} - -void BlockSelectionInterface::setBlockSelectionInterfaceDCOPSuffix (const TQCString &suffix) -{ - d->interface->setObjId ("BlockSelectionInterface#"+suffix); -} - -BlockSelectionInterface *KTextEditor::blockSelectionInterface (Document *doc) -{ - if (!doc) - return 0; - - return dynamic_cast(doc); -} diff --git a/interfaces/tdetexteditor/blockselectioninterface.h b/interfaces/tdetexteditor/blockselectioninterface.h deleted file mode 100644 index b2cd785eb..000000000 --- a/interfaces/tdetexteditor/blockselectioninterface.h +++ /dev/null @@ -1,82 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001 Christoph Cullmann - - 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 __tdetexteditor_blockselectioninterface_h__ -#define __tdetexteditor_blockselectioninterface_h__ - -#include - -class TQCString; - -namespace KTextEditor -{ - -/** - * An interface for the Document class which allows the selection - * method to be changed between selecting rectangular blocks of text and normal mode - * (all text between the start cursor and the current cursor). - */ -class KTEXTEDITOR_EXPORT BlockSelectionInterface -{ - friend class PrivateBlockSelectionInterface; - - public: - BlockSelectionInterface (); - virtual ~BlockSelectionInterface (); - - unsigned int blockSelectionInterfaceNumber () const; - - protected: - void setBlockSelectionInterfaceDCOPSuffix (const TQCString &suffix); - - /** - * slots !!! - */ - public: - /** - * Returns the status of the selection mode - true indicates block selection mode is on. - * If this is true, selections applied via the SelectionInterface are handled as - * blockselections and the paste functions of the ClipboardInterface works on - * rectangular blocks of text rather than normal. (copy too, but thats clear I hope ;) - */ - virtual bool blockSelectionMode () = 0; - - /** - * Set block selection mode to state "on" - */ - virtual bool setBlockSelectionMode (bool on) = 0; - - /** - * toggle block seletion mode - */ - virtual bool toggleBlockSelectionMode () = 0; - - private: - class PrivateBlockSelectionInterface *d; - static unsigned int globalBlockSelectionInterfaceNumber; - unsigned int myBlockSelectionInterfaceNumber; -}; - -/** - * Access the block selection interface of document @param doc - */ -KTEXTEDITOR_EXPORT BlockSelectionInterface *blockSelectionInterface (class Document *doc); - -} - -#endif diff --git a/interfaces/tdetexteditor/bloctdeselectiondcopinterface.cpp b/interfaces/tdetexteditor/bloctdeselectiondcopinterface.cpp new file mode 100644 index 000000000..34b7294b2 --- /dev/null +++ b/interfaces/tdetexteditor/bloctdeselectiondcopinterface.cpp @@ -0,0 +1,33 @@ +#include "blockselectiondcopinterface.h" +#include "blockselectioninterface.h" + +#include +using namespace KTextEditor; + +BlockSelectionDCOPInterface::BlockSelectionDCOPInterface( BlockSelectionInterface *Parent, const char *name) + : DCOPObject(name) +{ + m_parent = Parent; +} + +BlockSelectionDCOPInterface::~BlockSelectionDCOPInterface() +{ + +} + +uint BlockSelectionDCOPInterface::blockSelectionInterfaceNumber () +{ + return m_parent->blockSelectionInterfaceNumber(); +} +bool BlockSelectionDCOPInterface::blockSelectionMode () +{ + return m_parent->blockSelectionMode (); +} +bool BlockSelectionDCOPInterface::setBlockSelectionMode (bool on) +{ + return m_parent->setBlockSelectionMode (on); +} +bool BlockSelectionDCOPInterface::toggleBlockSelectionMode () +{ + return m_parent->toggleBlockSelectionMode (); +} diff --git a/interfaces/tdetexteditor/bloctdeselectiondcopinterface.h b/interfaces/tdetexteditor/bloctdeselectiondcopinterface.h new file mode 100644 index 000000000..4b74fd2a0 --- /dev/null +++ b/interfaces/tdetexteditor/bloctdeselectiondcopinterface.h @@ -0,0 +1,60 @@ +#ifndef BlockSelection_DCOP_INTERFACE_H +#define BlockSelection_DCOP_INTERFACE_H + +#include +#include +#include +#include + +namespace KTextEditor +{ + class BlockSelectionInterface; + /** + This is the main interface to the BlockSelectionInterface of KTextEditor. + This will provide a consistant dcop interface to all KDE applications that use it. + @short DCOP interface to BlockSelectionInterface. + @author Ian Reinhart Geiser + */ + class KTEXTEDITOR_EXPORT BlockSelectionDCOPInterface : virtual public DCOPObject + { + K_DCOP + + public: + /** + Construct a new interface object for the text editor. + @param Parent the parent BlockSelectionInterface object + that will provide us with the functions for the interface. + @param name the QObject's name + */ + BlockSelectionDCOPInterface( BlockSelectionInterface *Parent, const char *name ); + /** + Destructor + Cleans up the object. + */ + virtual ~BlockSelectionDCOPInterface(); + k_dcop: + uint blockSelectionInterfaceNumber (); + + /** + * Returns the status of the selection mode - true indicates block selection mode is on. + * If this is true, selections applied via the SelectionInterface are handled as + * blockselections and the paste functions of the ClipboardInterface works on + * rectangular blocks of text rather than normal. (copy too, but thats clear I hope ;) + */ + bool blockSelectionMode (); + + /** + * set blockselection mode to state "on" + */ + bool setBlockSelectionMode (bool on) ; + + /** + * toggle blockseletion mode + */ + bool toggleBlockSelectionMode (); + + private: + BlockSelectionInterface *m_parent; + }; +} +#endif diff --git a/interfaces/tdetexteditor/bloctdeselectioninterface.cpp b/interfaces/tdetexteditor/bloctdeselectioninterface.cpp new file mode 100644 index 000000000..6d562a43e --- /dev/null +++ b/interfaces/tdetexteditor/bloctdeselectioninterface.cpp @@ -0,0 +1,74 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001 Christoph Cullmann + + 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. +*/ + +// $Id$ + +#include "blockselectioninterface.h" +#include "blockselectiondcopinterface.h" +#include "document.h" + +namespace KTextEditor +{ + +class PrivateBlockSelectionInterface +{ + public: + PrivateBlockSelectionInterface() {interface = 0;} + ~PrivateBlockSelectionInterface() {} + BlockSelectionDCOPInterface *interface; +}; + +} + +using namespace KTextEditor; + +unsigned int BlockSelectionInterface::globalBlockSelectionInterfaceNumber = 0; + +BlockSelectionInterface::BlockSelectionInterface() +{ + globalBlockSelectionInterfaceNumber++; + myBlockSelectionInterfaceNumber = globalBlockSelectionInterfaceNumber++; + TQString name = "BlockSelectionInterface#" + TQString::number(myBlockSelectionInterfaceNumber); + + d = new PrivateBlockSelectionInterface(); + d->interface = new BlockSelectionDCOPInterface(this, name.latin1()); +} + +BlockSelectionInterface::~BlockSelectionInterface() +{ + delete d->interface; + delete d; +} + +unsigned int BlockSelectionInterface::blockSelectionInterfaceNumber () const +{ + return myBlockSelectionInterfaceNumber; +} + +void BlockSelectionInterface::setBlockSelectionInterfaceDCOPSuffix (const TQCString &suffix) +{ + d->interface->setObjId ("BlockSelectionInterface#"+suffix); +} + +BlockSelectionInterface *KTextEditor::blockSelectionInterface (Document *doc) +{ + if (!doc) + return 0; + + return dynamic_cast(doc); +} diff --git a/interfaces/tdetexteditor/bloctdeselectioninterface.h b/interfaces/tdetexteditor/bloctdeselectioninterface.h new file mode 100644 index 000000000..b2cd785eb --- /dev/null +++ b/interfaces/tdetexteditor/bloctdeselectioninterface.h @@ -0,0 +1,82 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001 Christoph Cullmann + + 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 __tdetexteditor_blockselectioninterface_h__ +#define __tdetexteditor_blockselectioninterface_h__ + +#include + +class TQCString; + +namespace KTextEditor +{ + +/** + * An interface for the Document class which allows the selection + * method to be changed between selecting rectangular blocks of text and normal mode + * (all text between the start cursor and the current cursor). + */ +class KTEXTEDITOR_EXPORT BlockSelectionInterface +{ + friend class PrivateBlockSelectionInterface; + + public: + BlockSelectionInterface (); + virtual ~BlockSelectionInterface (); + + unsigned int blockSelectionInterfaceNumber () const; + + protected: + void setBlockSelectionInterfaceDCOPSuffix (const TQCString &suffix); + + /** + * slots !!! + */ + public: + /** + * Returns the status of the selection mode - true indicates block selection mode is on. + * If this is true, selections applied via the SelectionInterface are handled as + * blockselections and the paste functions of the ClipboardInterface works on + * rectangular blocks of text rather than normal. (copy too, but thats clear I hope ;) + */ + virtual bool blockSelectionMode () = 0; + + /** + * Set block selection mode to state "on" + */ + virtual bool setBlockSelectionMode (bool on) = 0; + + /** + * toggle block seletion mode + */ + virtual bool toggleBlockSelectionMode () = 0; + + private: + class PrivateBlockSelectionInterface *d; + static unsigned int globalBlockSelectionInterfaceNumber; + unsigned int myBlockSelectionInterfaceNumber; +}; + +/** + * Access the block selection interface of document @param doc + */ +KTEXTEDITOR_EXPORT BlockSelectionInterface *blockSelectionInterface (class Document *doc); + +} + +#endif diff --git a/kdewidgets/pics/kactionselector.png b/kdewidgets/pics/kactionselector.png deleted file mode 100644 index acfdce496..000000000 Binary files a/kdewidgets/pics/kactionselector.png and /dev/null differ diff --git a/kdewidgets/pics/kfontcombo.png b/kdewidgets/pics/kfontcombo.png deleted file mode 100644 index 87835d6ce..000000000 Binary files a/kdewidgets/pics/kfontcombo.png and /dev/null differ diff --git a/kdewidgets/pics/kfontrequester.png b/kdewidgets/pics/kfontrequester.png deleted file mode 100644 index a01f4d692..000000000 Binary files a/kdewidgets/pics/kfontrequester.png and /dev/null differ diff --git a/kdewidgets/pics/klistbox.png b/kdewidgets/pics/klistbox.png deleted file mode 100644 index f7405b39f..000000000 Binary files a/kdewidgets/pics/klistbox.png and /dev/null differ diff --git a/kdewidgets/pics/klistview.png b/kdewidgets/pics/klistview.png deleted file mode 100644 index 932d910c8..000000000 Binary files a/kdewidgets/pics/klistview.png and /dev/null differ diff --git a/kdewidgets/pics/tdeactionselector.png b/kdewidgets/pics/tdeactionselector.png new file mode 100644 index 000000000..acfdce496 Binary files /dev/null and b/kdewidgets/pics/tdeactionselector.png differ diff --git a/kdewidgets/pics/tdefontcombo.png b/kdewidgets/pics/tdefontcombo.png new file mode 100644 index 000000000..87835d6ce Binary files /dev/null and b/kdewidgets/pics/tdefontcombo.png differ diff --git a/kdewidgets/pics/tdefontrequester.png b/kdewidgets/pics/tdefontrequester.png new file mode 100644 index 000000000..a01f4d692 Binary files /dev/null and b/kdewidgets/pics/tdefontrequester.png differ diff --git a/kdewidgets/pics/tdelistbox.png b/kdewidgets/pics/tdelistbox.png new file mode 100644 index 000000000..f7405b39f Binary files /dev/null and b/kdewidgets/pics/tdelistbox.png differ diff --git a/kdewidgets/pics/tdelistview.png b/kdewidgets/pics/tdelistview.png new file mode 100644 index 000000000..932d910c8 Binary files /dev/null and b/kdewidgets/pics/tdelistview.png differ diff --git a/tdecore/kaccel.cpp b/tdecore/kaccel.cpp deleted file mode 100644 index 9dde93e7a..000000000 --- a/tdecore/kaccel.cpp +++ /dev/null @@ -1,663 +0,0 @@ -/* - Copyright (c) 2001,2002 Ellis Whitehead - - This library 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. - - 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. -*/ - -#include "kaccel.h" - -#include -#include -#include -#include -#include -#include - -#include "kaccelbase.h" -#include -#include -#include -#include - -#include "kaccelprivate.h" - -#ifdef Q_WS_X11 -# include -# ifdef KeyPress // needed for --enable-final - // defined by X11 headers - const int XKeyPress = KeyPress; -# undef KeyPress -# endif -#endif - -// TODO: Put in kaccelbase.cpp -//--------------------------------------------------------------------- -// TDEAccelEventHandler -//--------------------------------------------------------------------- -// -// In TDEAccelEventHandler::x11Event we do our own X11 keyboard event handling -// This allows us to map the Win key to Qt::MetaButton, Qt does not know about -// the Win key. -// -// TDEAccelEventHandler::x11Event will generate an AccelOverride event. The -// AccelOverride event is abused a bit to ensure that TDEAccelPrivate::eventFilter -// (as an event filter on the toplevel widget) will get the key event first -// (in the form of AccelOverride) before any of the intermediate widgets are -// able to process it. -// -// Qt normally sends an AccelOverride, Accel and then a KeyPress event. -// A widget can accept the AccelOverride event in which case the Accel event will be -// skipped and the KeyPress is followed immediately. -// If the Accel event is accepted, no KeyPress event will follow. -// -// TDEAccelEventHandler::x11Event converts a X11 keyboard event into an AccelOverride -// event, there are now two possibilities: -// -// 1) If TDEAccel intercepts the AccelOverride we are done and can consider the X11 -// keyboard event as handled. -// 2) If another widget accepts the AccelOverride, it will expect to get a normal -// Qt generated KeyPress event afterwards. So we let Qt handle the X11 keyboard event -// again. However, this will first generate an AccelOverride event, and we already -// had send that one. To compnesate for this, the global event filter in TDEApplication -// is instructed to eat the next AccelOveride event. Qt will then send a normal KeyPress -// event and from then on everything is normal again. -// -// kde_g_bKillAccelOverride is used to tell TDEApplication::notify to eat the next -// AccelOverride event. - -bool kde_g_bKillAccelOverride = false; - -class TDEAccelEventHandler : public TQWidget -{ - public: - static TDEAccelEventHandler* self() - { - if( !g_pSelf ) - g_pSelf = new TDEAccelEventHandler; - return g_pSelf; - } - - static void accelActivated( bool b ) { g_bAccelActivated = b; } - - private: - TDEAccelEventHandler(); - -# ifdef Q_WS_X11 - bool x11Event( XEvent* pEvent ); -# endif - - static TDEAccelEventHandler* g_pSelf; - static bool g_bAccelActivated; -}; - -TDEAccelEventHandler* TDEAccelEventHandler::g_pSelf = 0; -bool TDEAccelEventHandler::g_bAccelActivated = false; - -TDEAccelEventHandler::TDEAccelEventHandler() - : TQWidget( 0, "TDEAccelEventHandler" ) -{ -# ifdef Q_WS_X11 - if ( kapp ) - kapp->installX11EventFilter( TQT_TQWIDGET(this) ); -# endif -} - -#ifdef Q_WS_X11 -bool tqt_try_modal( TQWidget *, XEvent * ); - -bool TDEAccelEventHandler::x11Event( XEvent* pEvent ) -{ - if( TQWidget::keyboardGrabber() || !kapp->focusWidget() ) - return false; - - if ( !tqt_try_modal(kapp->focusWidget(), pEvent) ) - return false; - - if( pEvent->type == XKeyPress ) { - unsigned int tmp = pEvent->xkey.state; - pEvent->xkey.state &= ~0x2000; - KKeyNative keyNative( pEvent ); - pEvent->xkey.state = tmp; - KKey key( keyNative ); - key.simplify(); - int keyCodeQt = key.keyCodeQt(); - int state = 0; - if( key.modFlags() & KKey::SHIFT ) state |= TQt::ShiftButton; - if( key.modFlags() & KKey::CTRL ) state |= TQt::ControlButton; - if( key.modFlags() & KKey::ALT ) state |= TQt::AltButton; - if( key.modFlags() & KKey::WIN ) state |= TQt::MetaButton; - - TQKeyEvent ke( TQEvent::AccelOverride, keyCodeQt, 0, state ); - ke.ignore(); - - g_bAccelActivated = false; - kapp->sendEvent( kapp->focusWidget(), &ke ); - - // If the Override event was accepted from a non-TDEAccel widget, - // then kill the next AccelOverride in TDEApplication::notify. - if( ke.isAccepted() && !g_bAccelActivated ) - kde_g_bKillAccelOverride = true; - - // Stop event processing if a KDE accelerator was activated. - return g_bAccelActivated; - } - - return false; -} -#endif // Q_WS_X11 - -//--------------------------------------------------------------------- -// TDEAccelPrivate -//--------------------------------------------------------------------- - -TDEAccelPrivate::TDEAccelPrivate( TDEAccel* pParent, TQWidget* pWatch ) -: TDEAccelBase( TDEAccelBase::QT_KEYS ) -{ - //kdDebug(125) << "TDEAccelPrivate::TDEAccelPrivate( pParent = " << pParent << " ): this = " << this << endl; - m_pAccel = pParent; - m_pWatch = pWatch; - m_bAutoUpdate = true; - connect( (TQAccel*)m_pAccel, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotKeyPressed(int)) ); - -#ifdef Q_WS_X11 //only makes sense if TDEAccelEventHandler is working - if( m_pWatch ) - m_pWatch->installEventFilter( this ); -#endif - TDEAccelEventHandler::self(); -} - -void TDEAccelPrivate::setEnabled( bool bEnabled ) -{ - m_bEnabled = bEnabled; - ((TQAccel*)m_pAccel)->setEnabled( bEnabled ); -} - -bool TDEAccelPrivate::setEnabled( const TQString& sAction, bool bEnable ) -{ - kdDebug(125) << "TDEAccelPrivate::setEnabled( \"" << sAction << "\", " << bEnable << " ): this = " << this << endl; - TDEAccelAction* pAction = actionPtr( sAction ); - if( !pAction ) - return false; - if( pAction->isEnabled() == bEnable ) - return true; - - pAction->setEnabled( bEnable ); - - TQMap::const_iterator it = m_mapIDToAction.begin(); - for( ; it != m_mapIDToAction.end(); ++it ) { - if( *it == pAction ) - ((TQAccel*)m_pAccel)->setItemEnabled( it.key(), bEnable ); - } - return true; -} - -bool TDEAccelPrivate::removeAction( const TQString& sAction ) -{ - // FIXME: getID() doesn't contains any useful - // information! Use mapIDToAction. --ellis, 2/May/2002 - // Or maybe TDEAccelBase::remove() takes care of TQAccel indirectly... - TDEAccelAction* pAction = actions().actionPtr( sAction ); - if( pAction ) { - int nID = pAction->getID(); - //bool b = actions().removeAction( sAction ); - bool b = TDEAccelBase::remove( sAction ); - ((TQAccel*)m_pAccel)->removeItem( nID ); - return b; - } else - return false; -} - -bool TDEAccelPrivate::emitSignal( TDEAccelBase::Signal signal ) -{ - if( signal == TDEAccelBase::KEYCODE_CHANGED ) { - m_pAccel->emitKeycodeChanged(); - return true; - } - return false; -} - -bool TDEAccelPrivate::connectKey( TDEAccelAction& action, const KKeyServer::Key& key ) -{ - uint keyQt = key.keyCodeQt(); - int nID = ((TQAccel*)m_pAccel)->insertItem( keyQt ); - m_mapIDToAction[nID] = &action; - m_mapIDToKey[nID] = keyQt; - - if( action.objSlotPtr() && action.methodSlotPtr() ) { -#ifdef Q_WS_WIN /** @todo TEMP: new implementation (commit #424926) didn't work */ - ((TQAccel*)m_pAccel)->connectItem( nID, action.objSlotPtr(), action.methodSlotPtr() ); -#else - ((TQAccel*)m_pAccel)->connectItem( nID, this, TQT_SLOT(slotKeyPressed(int))); -#endif - if( !action.isEnabled() ) - ((TQAccel*)m_pAccel)->setItemEnabled( nID, false ); - } - - kdDebug(125) << "TDEAccelPrivate::connectKey( \"" << action.name() << "\", " << key.key().toStringInternal() << " = 0x" << TQString::number(keyQt,16) << " ): id = " << nID << " m_pObjSlot = " << action.objSlotPtr() << endl; - //kdDebug(125) << "m_pAccel = " << m_pAccel << endl; - return nID != 0; -} - -bool TDEAccelPrivate::connectKey( const KKeyServer::Key& key ) -{ - uint keyQt = key.keyCodeQt(); - int nID = ((TQAccel*)m_pAccel)->insertItem( keyQt ); - - m_mapIDToKey[nID] = keyQt; - - kdDebug(125) << "TDEAccelPrivate::connectKey( " << key.key().toStringInternal() << " = 0x" << TQString::number(keyQt,16) << " ): id = " << nID << endl; - return nID != 0; -} - -bool TDEAccelPrivate::disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ) -{ - int keyQt = key.keyCodeQt(); - TQMap::iterator it = m_mapIDToKey.begin(); - for( ; it != m_mapIDToKey.end(); ++it ) { - //kdDebug(125) << "m_mapIDToKey[" << it.key() << "] = " << TQString::number(*it,16) << " == " << TQString::number(keyQt,16) << endl; - if( *it == keyQt ) { - int nID = it.key(); - kdDebug(125) << "TDEAccelPrivate::disconnectKey( \"" << action.name() << "\", 0x" << TQString::number(keyQt,16) << " ) : id = " << nID << " m_pObjSlot = " << action.objSlotPtr() << endl; - ((TQAccel*)m_pAccel)->removeItem( nID ); - m_mapIDToAction.remove( nID ); - m_mapIDToKey.remove( it ); - return true; - } - } - //kdWarning(125) << kdBacktrace() << endl; - kdWarning(125) << "Didn't find key in m_mapIDToKey." << endl; - return false; -} - -bool TDEAccelPrivate::disconnectKey( const KKeyServer::Key& key ) -{ - int keyQt = key.keyCodeQt(); - kdDebug(125) << "TDEAccelPrivate::disconnectKey( 0x" << TQString::number(keyQt,16) << " )" << endl; - TQMap::iterator it = m_mapIDToKey.begin(); - for( ; it != m_mapIDToKey.end(); ++it ) { - if( *it == keyQt ) { - ((TQAccel*)m_pAccel)->removeItem( it.key() ); - m_mapIDToKey.remove( it ); - return true; - } - } - //kdWarning(125) << kdBacktrace() << endl; - kdWarning(125) << "Didn't find key in m_mapIDTokey." << endl; - return false; -} - -void TDEAccelPrivate::slotKeyPressed( int id ) -{ - kdDebug(125) << "TDEAccelPrivate::slotKeyPressed( " << id << " )" << endl; - - if( m_mapIDToKey.contains( id ) ) { - KKey key = m_mapIDToKey[id]; - KKeySequence seq( key ); - TQPopupMenu* pMenu = createPopupMenu( m_pWatch, seq ); - - // If there was only one action mapped to this key, - // and that action is not a multi-key shortcut, - // then activated it without popping up the menu. - // This is needed for when there are multiple actions - // with the same shortcut where all but one is disabled. - // pMenu->count() also counts the menu title, so one shortcut will give count = 2. - if( pMenu->count() == 2 && pMenu->accel(1).isEmpty() ) { - int iAction = pMenu->idAt(1); - slotMenuActivated( iAction ); - } else { - connect( pMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotMenuActivated(int)) ); - pMenu->exec( m_pWatch->mapToGlobal( TQPoint( 0, 0 ) ) ); - disconnect( pMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotMenuActivated(int)) ); - } - delete pMenu; - } -} - -void TDEAccelPrivate::slotShowMenu() -{ -} - -void TDEAccelPrivate::slotMenuActivated( int iAction ) -{ - kdDebug(125) << "TDEAccelPrivate::slotMenuActivated( " << iAction << " )" << endl; - TDEAccelAction* pAction = actions().actionPtr( iAction ); -#ifdef Q_WS_WIN /** @todo TEMP: new implementation (commit #424926) didn't work */ - if( pAction ) { - connect( this, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() ); - emit menuItemActivated(); - disconnect( this, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() ); - } -#else - emitActivatedSignal( pAction ); -#endif -} - -bool TDEAccelPrivate::eventFilter( TQObject* /*pWatched*/, TQEvent* pEvent ) -{ - if( pEvent->type() == TQEvent::AccelOverride && m_bEnabled ) { - TQKeyEvent* pKeyEvent = (TQKeyEvent*) pEvent; - KKey key( pKeyEvent ); - kdDebug(125) << "TDEAccelPrivate::eventFilter( AccelOverride ): this = " << this << ", key = " << key.toStringInternal() << endl; - int keyCodeQt = key.keyCodeQt(); - TQMap::iterator it = m_mapIDToKey.begin(); - for( ; it != m_mapIDToKey.end(); ++it ) { - if( (*it) == keyCodeQt ) { - int nID = it.key(); - kdDebug(125) << "shortcut found!" << endl; - if( m_mapIDToAction.contains( nID ) ) { - // TODO: reduce duplication between here and slotMenuActivated - TDEAccelAction* pAction = m_mapIDToAction[nID]; - if( !pAction->isEnabled() ) - continue; -#ifdef Q_WS_WIN /** @todo TEMP: new implementation (commit #424926) didn't work */ - TQGuardedPtr me = this; - connect( this, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() ); - emit menuItemActivated(); - if (me) { - disconnect( me, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() ); - } -#else - emitActivatedSignal( pAction ); -#endif - } else - slotKeyPressed( nID ); - - pKeyEvent->accept(); - TDEAccelEventHandler::accelActivated( true ); - return true; - } - } - } - return false; -} - -#ifndef Q_WS_WIN /** @todo TEMP: new implementation (commit #424926) didn't work */ -void TDEAccelPrivate::emitActivatedSignal( TDEAccelAction* pAction ) -{ - if( pAction ) { - TQGuardedPtr me = this; - TQRegExp reg( "([ ]*TDEAccelAction.*)" ); - if( reg.search( pAction->methodSlotPtr()) >= 0 ) { - connect( this, TQT_SIGNAL(menuItemActivated(TDEAccelAction*)), - pAction->objSlotPtr(), pAction->methodSlotPtr() ); - emit menuItemActivated( pAction ); - if (me) - disconnect( me, TQT_SIGNAL(menuItemActivated(TDEAccelAction*)), - pAction->objSlotPtr(), pAction->methodSlotPtr() ); - } else { - connect( this, TQT_SIGNAL(menuItemActivated()), - pAction->objSlotPtr(), pAction->methodSlotPtr() ); - emit menuItemActivated(); - if (me) - disconnect( me, TQT_SIGNAL(menuItemActivated()), - pAction->objSlotPtr(), pAction->methodSlotPtr() ); - - } - } -} -#endif - -//--------------------------------------------------------------------- -// TDEAccel -//--------------------------------------------------------------------- - -TDEAccel::TDEAccel( TQWidget* pParent, const char* psName ) -: TQAccel( pParent, (psName) ? psName : "TDEAccel-TQAccel" ) -{ - kdDebug(125) << "TDEAccel( pParent = " << pParent << ", psName = " << psName << " ): this = " << this << endl; - d = new TDEAccelPrivate( this, pParent ); -} - -TDEAccel::TDEAccel( TQWidget* watch, TQObject* pParent, const char* psName ) -: TQAccel( watch, pParent, (psName) ? psName : "TDEAccel-TQAccel" ) -{ - kdDebug(125) << "TDEAccel( watch = " << watch << ", pParent = " << pParent << ", psName = " << psName << " ): this = " << this << endl; - if( !watch ) - kdDebug(125) << kdBacktrace() << endl; - d = new TDEAccelPrivate( this, watch ); -} - -TDEAccel::~TDEAccel() -{ - kdDebug(125) << "~TDEAccel(): this = " << this << endl; - delete d; -} - -TDEAccelActions& TDEAccel::actions() { return d->actions(); } -const TDEAccelActions& TDEAccel::actions() const { return d->actions(); } -bool TDEAccel::isEnabled() { return d->isEnabled(); } -void TDEAccel::setEnabled( bool bEnabled ) { d->setEnabled( bEnabled ); } -bool TDEAccel::setAutoUpdate( bool bAuto ) { return d->setAutoUpdate( bAuto ); } - -TDEAccelAction* TDEAccel::insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, - const TDEShortcut& cutDef, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable, bool bEnabled ) -{ - return d->insert( sAction, sLabel, sWhatsThis, - cutDef, cutDef, - pObjSlot, psMethodSlot, - bConfigurable, bEnabled ); -} - -TDEAccelAction* TDEAccel::insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, - const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable, bool bEnabled ) -{ - return d->insert( sAction, sLabel, sWhatsThis, - cutDef3, cutDef4, - pObjSlot, psMethodSlot, - bConfigurable, bEnabled ); -} - -TDEAccelAction* TDEAccel::insert( const char* psAction, const TDEShortcut& cutDef, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable, bool bEnabled ) -{ - return d->insert( psAction, i18n(psAction), TQString::null, - cutDef, cutDef, - pObjSlot, psMethodSlot, - bConfigurable, bEnabled ); -} - -TDEAccelAction* TDEAccel::insert( TDEStdAccel::StdAccel id, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable, bool bEnabled ) -{ - TQString sAction = TDEStdAccel::name( id ); - if( sAction.isEmpty() ) - return 0; - - TDEAccelAction* pAction = d->insert( sAction, TDEStdAccel::label( id ), TDEStdAccel::whatsThis( id ), - TDEStdAccel::shortcutDefault3( id ), TDEStdAccel::shortcutDefault4( id ), - pObjSlot, psMethodSlot, - bConfigurable, bEnabled ); - if( pAction ) - pAction->setShortcut( TDEStdAccel::shortcut( id ) ); - - return pAction; -} - -bool TDEAccel::remove( const TQString& sAction ) - { return d->removeAction( sAction ); } -bool TDEAccel::updateConnections() - { return d->updateConnections(); } - -const TDEShortcut& TDEAccel::shortcut( const TQString& sAction ) const -{ - const TDEAccelAction* pAction = actions().actionPtr( sAction ); - return (pAction) ? pAction->shortcut() : TDEShortcut::null(); -} - -bool TDEAccel::setSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ) - { return d->setActionSlot( sAction, pObjSlot, psMethodSlot ); } - -bool TDEAccel::setEnabled( const TQString& sAction, bool bEnable ) - { return d->setEnabled( sAction, bEnable ); } - -bool TDEAccel::setShortcut( const TQString& sAction, const TDEShortcut& cut ) -{ - kdDebug(125) << "TDEAccel::setShortcut( \"" << sAction << "\", " << cut.toStringInternal() << " )" << endl; - TDEAccelAction* pAction = actions().actionPtr( sAction ); - if( pAction ) { - if( pAction->shortcut() != cut ) - return d->setShortcut( sAction, cut ); - return true; - } - return false; -} - -const TQString& TDEAccel::configGroup() const - { return d->configGroup(); } -// for tdegames/ksirtet -void TDEAccel::setConfigGroup( const TQString& s ) - { d->setConfigGroup( s ); } - -bool TDEAccel::readSettings( TDEConfigBase* pConfig ) -{ - d->readSettings( pConfig ); - return true; -} - -bool TDEAccel::writeSettings( TDEConfigBase* pConfig ) const - { d->writeSettings( pConfig ); return true; } - -void TDEAccel::emitKeycodeChanged() -{ - kdDebug(125) << "TDEAccel::emitKeycodeChanged()" << endl; - emit keycodeChanged(); -} - -#ifndef KDE_NO_COMPAT -//------------------------------------------------------------ -// Obsolete methods -- for backward compatibility -//------------------------------------------------------------ - -bool TDEAccel::insertItem( const TQString& sLabel, const TQString& sAction, - const char* cutsDef, - int /*nIDMenu*/, TQPopupMenu *, bool bConfigurable ) -{ - TDEShortcut cut( cutsDef ); - bool b = d->insert( sAction, sLabel, TQString::null, - cut, cut, - 0, 0, - bConfigurable ) != 0; - return b; -} - -bool TDEAccel::insertItem( const TQString& sLabel, const TQString& sAction, - int key, - int /*nIDMenu*/, TQPopupMenu*, bool bConfigurable ) -{ - TDEShortcut cut; - cut.init( TQKeySequence(key) ); - TDEAccelAction* pAction = d->insert( sAction, sLabel, TQString::null, - cut, cut, - 0, 0, - bConfigurable ); - return pAction != 0; -} - -// Used in tdeutils/kjots -bool TDEAccel::insertStdItem( TDEStdAccel::StdAccel id, const TQString& sLabel ) -{ - TDEAccelAction* pAction = d->insert( TDEStdAccel::name( id ), sLabel, TQString::null, - TDEStdAccel::shortcutDefault3( id ), TDEStdAccel::shortcutDefault4( id ), - 0, 0 ); - if( pAction ) - pAction->setShortcut( TDEStdAccel::shortcut( id ) ); - - return true; -} - -bool TDEAccel::connectItem( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot, bool bActivate ) -{ - kdDebug(125) << "TDEAccel::connectItem( " << sAction << ", " << pObjSlot << ", " << psMethodSlot << " )" << endl; - if( bActivate == false ) - d->setActionEnabled( sAction, false ); - bool b = setSlot( sAction, pObjSlot, psMethodSlot ); - if( bActivate == true ) - d->setActionEnabled( sAction, true ); - return b; -} - -bool TDEAccel::removeItem( const TQString& sAction ) - { return d->removeAction( sAction ); } - -bool TDEAccel::setItemEnabled( const TQString& sAction, bool bEnable ) - { return setEnabled( sAction, bEnable ); } - -void TDEAccel::changeMenuAccel( TQPopupMenu *menu, int id, const TQString& action ) -{ - TDEAccelAction* pAction = actions().actionPtr( action ); - TQString s = menu->text( id ); - if( !pAction || s.isEmpty() ) - return; - - int i = s.find( '\t' ); - - TQString k = pAction->shortcut().seq(0).toString(); - if( k.isEmpty() ) - return; - - if ( i >= 0 ) - s.replace( i+1, s.length()-i, k ); - else { - s += '\t'; - s += k; - } - - TQPixmap *pp = menu->pixmap(id); - if( pp && !pp->isNull() ) - menu->changeItem( *pp, s, id ); - else - menu->changeItem( s, id ); -} - -void TDEAccel::changeMenuAccel( TQPopupMenu *menu, int id, TDEStdAccel::StdAccel accel ) -{ - changeMenuAccel( menu, id, TDEStdAccel::name( accel ) ); -} - -int TDEAccel::stringToKey( const TQString& sKey ) -{ - return KKey( sKey ).keyCodeQt(); -} - -int TDEAccel::currentKey( const TQString& sAction ) const -{ - TDEAccelAction* pAction = d->actionPtr( sAction ); - if( pAction ) - return pAction->shortcut().keyCodeQt(); - return 0; -} - -TQString TDEAccel::findKey( int key ) const -{ - TDEAccelAction* pAction = d->actionPtr( KKey(key) ); - if( pAction ) - return pAction->name(); - else - return TQString::null; -} -#endif // !KDE_NO_COMPAT - -void TDEAccel::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -#include "kaccel.moc" -#include "kaccelprivate.moc" diff --git a/tdecore/kaccel.h b/tdecore/kaccel.h deleted file mode 100644 index 8a3f2d499..000000000 --- a/tdecore/kaccel.h +++ /dev/null @@ -1,390 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001,2002 Ellis Whitehead - - This library 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. - - 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 _KACCEL_H -#define _KACCEL_H - -#include -#include -#include -#include "tdelibs_export.h" - -class TQPopupMenu; // for obsolete insertItem() methods below -class TQWidget; -class TDEAccelAction; -class TDEAccelActions; -class TDEConfigBase; - -class TDEAccelPrivate; -/** - * Handle shortcuts. - * - * Allow a user to configure shortcuts - * through application configuration files or through the - * KKeyChooser GUI. - * - * A TDEAccel contains a list of accelerator actions. - * - * For example, CTRL+Key_P could be a shortcut for printing a document. The key - * codes are listed in tqnamespace.h. "Print" could be the action name for printing. - * The action name identifies the shortcut in configuration files and the - * KKeyChooser GUI. - * - * A TDEAccel object handles key events sent to its parent widget and to all - * children of this parent widget. The most recently created TDEAccel object - * has precedence over any TDEAccel objects created before it. - * When a shortcut pressed, TDEAccel calls the slot to which it has been - * connected. If you want to set global accelerators, independent of the window - * which has the focus, use TDEGlobalAccel. - * - * Reconfiguration of a given shortcut can be prevented by specifying - * that an accelerator item is not configurable when it is inserted. A special - * group of non-configurable key bindings are known as the - * standard accelerators. - * - * The standard accelerators appear repeatedly in applications for - * standard document actions such as printing and saving. A convenience method is - * available to insert and connect these accelerators which are configurable on - * a desktop-wide basis. - * - * It is possible for a user to choose to have no key associated with - * an action. - * - * The translated first argument for insertItem() is used only - * in the configuration dialog. - *\code - * TDEAccel* pAccel = new TDEAccel( this ); - * - * // Insert an action "Scroll Up" which is associated with the "Up" key: - * pAccel->insert( "Scroll Up", i18n("Scroll up"), - * i18n("Scroll up the current document by one line."), - * Qt::Key_Up, this, TQT_SLOT(slotScrollUp()) ); - * // Insert an standard acclerator action. - * pAccel->insert( TDEStdAccel::Print, this, TQT_SLOT(slotPrint()) ); - * - * // Update the shortcuts by read any user-defined settings from the - * // application's config file. - * pAccel->readSettings(); - * \endcode - * - * @short Configurable shortcut support for widgets. - * @see TDEGlobalAccel - * @see TDEAccelShortcutList - * @see KKeyChooser - * @see KKeyDialog - */ - -class TDECORE_EXPORT TDEAccel : public TQAccel -{ - Q_OBJECT - public: - /** - * Creates a new TDEAccel that watches @p pParent, which is also - * the QObject's parent. - * - * @param pParent the parent and widget to watch for key strokes - * @param psName the name of the QObject - */ - TDEAccel( TQWidget* pParent, const char* psName = 0 ); - - /** - * Creates a new TDEAccel that watches @p watch. - * - * @param watch the widget to watch for key strokes - * @param parent the parent of the QObject - * @param psName the name of the QObject - */ - TDEAccel( TQWidget* watch, TQObject* parent, const char* psName = 0 ); - virtual ~TDEAccel(); - - /** - * @internal - * Returns the TDEAccel's @p TDEAccelActions, a list of @p TDEAccelAction. - * @return the TDEAccelActions of the TDEAccel - */ - TDEAccelActions& actions(); - - /** - * @internal - * Returns the TDEAccel's @p TDEAccelActions, a list of @p TDEAccelAction. - * @return the TDEAccelActions of the TDEAccel - */ - const TDEAccelActions& actions() const; - - /** - * Checks whether the TDEAccel is active. - * @return true if the TQAccel is enabled - */ - bool isEnabled(); - - /** - * Enables or disables the TDEAccel. - * @param bEnabled true to enable, false to disable - */ - void setEnabled( bool bEnabled ); - - /** - * Enable auto-update of connections. This means that the signals - * are automatically disconnected when you disable an action, and - * re-enabled when you enable it. By default auto update is turned - * on. If you disable auto-update, you need to call - * updateConnections() after changing actions. - * - * @param bAuto true to enable, false to disable - * @return the value of the flag before this call - */ - bool setAutoUpdate( bool bAuto ); - - /** - * Create an accelerator action. - * - * Usage: - *\code - * insert( "Do Something", i18n("Do Something"), - * i18n("This action allows you to do something really great with this program to " - * "the currently open document."), - * ALT+Key_D, this, TQT_SLOT(slotDoSomething()) ); - *\endcode - * - * @param sAction The internal name of the action. - * @param sLabel An i18n'ized short description of the action displayed when - * using KKeyChooser to reconfigure the shortcuts. - * @param sWhatsThis An extended description of the action. - * @param cutDef The default shortcut. - * @param pObjSlot Pointer to the slot object. - * @param psMethodSlot Pointer to the slot method. - * @param bConfigurable Allow the user to change this shortcut if set to 'true'. - * @param bEnabled The action will be activated by the shortcut if set to 'true'. - */ - TDEAccelAction* insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, - const TDEShortcut& cutDef, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable = true, bool bEnabled = true ); - /** - * Same as first insert(), but with separate shortcuts defined for - * 3- and 4- modifier defaults. - */ - TDEAccelAction* insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, - const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable = true, bool bEnabled = true ); - /** - * This is an overloaded function provided for convenience. - * The advantage of this is when you want to use the same text for the name - * of the action as for the user-visible label. - * - * Usage: - * \code - * insert( i18n("Do Something"), ALT+Key_D, this, TQT_SLOT(slotDoSomething()) ); - * \endcode - * - * @param psAction The name AND label of the action. - * @param cutDef The default shortcut for this action. - * @param pObjSlot Pointer to the slot object. - * @param psMethodSlot Pointer to the slot method. - * @param bConfigurable Allow the user to change this shortcut if set to 'true'. - * @param bEnabled The action will be activated by the shortcut if set to 'true'. - */ - TDEAccelAction* insert( const char* psAction, const TDEShortcut& cutDef, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable = true, bool bEnabled = true ); - /** - * Similar to the first insert() method, but with the action - * name, short description, help text, and default shortcuts all - * set according to one of the standard accelerators. - * @see TDEStdAccel. - */ - TDEAccelAction* insert( TDEStdAccel::StdAccel id, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable = true, bool bEnabled = true ); - - /** - * Removes the accelerator action identified by the name. - * Remember to also call updateConnections(). - * @param sAction the name of the action to remove - * @return true if successful, false otherwise - */ - bool remove( const TQString& sAction ); - - /** - * Updates the connections of the accelerations after changing them. - * This is only necessary if you have disabled auto updates which are - * on by default. - * @return true if successful, false otherwise - * @see setAutoUpdate() - * @see getAutoUpdate() - */ - bool updateConnections(); - - /** - * Return the shortcut associated with the action named by @p sAction. - * @param sAction the name of the action - * @return the action's shortcut, or a null shortcut if not found - */ - const TDEShortcut& shortcut( const TQString& sAction ) const; - - /** - * Set the shortcut to be associated with the action named by @p sAction. - * @param sAction the name of the action - * @param shortcut the shortcut to set - * @return true if successful, false otherwise - */ - bool setShortcut( const TQString& sAction, const TDEShortcut &shortcut ); - - /** - * Set the slot to be called when the shortcut of the action named - * by @p sAction is pressed. - * @param sAction the name of the action - * @param pObjSlot the owner of the slot - * @param psMethodSlot the name of the slot - * @return true if successful, false otherwise - */ - bool setSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ); - /** - * Enable or disable the action named by @p sAction. - * @param sAction the action to en-/disable - * @param bEnabled true to enable, false to disable - * @return true if successful, false otherwise - */ - bool setEnabled( const TQString& sAction, bool bEnabled ); - - /** - * Returns the configuration group of the settings. - * @return the configuration group - * @see TDEConfig - */ - const TQString& configGroup() const; - - /** - * Returns the configuration group of the settings. - * @param name the new configuration group - * @see TDEConfig - */ - void setConfigGroup( const TQString &name ); - - /** - * Read all shortcuts from @p pConfig, or (if @p pConfig - * is zero) from the application's configuration file - * TDEGlobal::config(). - * - * The group in which the configuration is stored can be - * set with setConfigGroup(). - * @param pConfig the configuration file, or 0 for the application - * configuration file - * @return true if successful, false otherwise - */ - bool readSettings( TDEConfigBase* pConfig = 0 ); - /** - * Write the current shortcuts to @p pConfig, - * or (if @p pConfig is zero) to the application's - * configuration file. - * @param pConfig the configuration file, or 0 for the application - * configuration file - * @return true if successful, false otherwise - */ - bool writeSettings( TDEConfigBase* pConfig = 0 ) const; - - /** - * Emits the keycodeChanged() signal. - */ - void emitKeycodeChanged(); - - signals: - /** - * Emitted when one of the key codes has changed. - */ - void keycodeChanged(); - -#ifndef KDE_NO_COMPAT - public: - // Source compatibility to KDE 2.x - /** - * @deprecated use insert - */ - bool insertItem( const TQString& sLabel, const TQString& sAction, - const char* psKey, - int nIDMenu = 0, TQPopupMenu* pMenu = 0, bool bConfigurable = true ) KDE_DEPRECATED; - /** - * @deprecated use insert - */ - bool insertItem( const TQString& sLabel, const TQString& sAction, - int key, - int nIDMenu = 0, TQPopupMenu* pMenu = 0, bool bConfigurable = true ) KDE_DEPRECATED; - /** - * @deprecated use insert - */ - bool insertStdItem( TDEStdAccel::StdAccel id, const TQString& descr = TQString::null ) KDE_DEPRECATED; - /** - * @deprecated use insert - */ - bool connectItem( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot, bool bActivate = true ) KDE_DEPRECATED; - /** - * @deprecated use insert( accel, pObjSlot, psMethodSlot ); - * - */ - KDE_DEPRECATED bool connectItem( TDEStdAccel::StdAccel accel, const TQObject* pObjSlot, const char* psMethodSlot ) - { return insert( accel, pObjSlot, psMethodSlot ); } - /** - * @deprecated use remove - */ - bool removeItem( const TQString& sAction ) KDE_DEPRECATED; - /** - * @deprecated - */ - bool setItemEnabled( const TQString& sAction, bool bEnable ) KDE_DEPRECATED; - /** - * @deprecated see KDE3PORTING.html - */ - void changeMenuAccel( TQPopupMenu *menu, int id, const TQString& action ) KDE_DEPRECATED; - /** - * @deprecated see KDE3PORTING.html - */ - void changeMenuAccel( TQPopupMenu *menu, int id, TDEStdAccel::StdAccel accel ) KDE_DEPRECATED; - /** - * @deprecated - */ - static int stringToKey( const TQString& ) KDE_DEPRECATED; - - /** - * @deprecated Use shortcut(). - * - * Retrieve the key code of the accelerator item with the action name - * @p action, or zero if either the action name cannot be - * found or the current key is set to no key. - */ - int currentKey( const TQString& action ) const KDE_DEPRECATED; - - /** - * @deprecated Use actions().actionPtr(). - * - * Return the name of the accelerator item with the keycode @p key, - * or TQString::null if the item cannot be found. - */ - TQString findKey( int key ) const KDE_DEPRECATED; -#endif // !KDE_NO_COMPAT - - protected: - /** \internal */ - virtual void virtual_hook( int id, void* data ); - private: - class TDEAccelPrivate* d; - friend class TDEAccelPrivate; -}; - -#endif // _KACCEL_H diff --git a/tdecore/kaccelaction.cpp b/tdecore/kaccelaction.cpp deleted file mode 100644 index d3ec59be3..000000000 --- a/tdecore/kaccelaction.cpp +++ /dev/null @@ -1,565 +0,0 @@ -/* - Copyright (C) 1998 Mark Donohoe - Copyright (C) 1997-2000 Nicolas Hadacek - Copyright (C) 1998 Matthias Ettrich - Copyright (c) 2001,2002 Ellis Whitehead - - This library 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. - - 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. -*/ - -#include "kaccelaction.h" -#include "kaccelbase.h" // for TDEAccelBase::slotRemoveAction() & emitSignal() - -#include - -#include -#include "kckey.h" -#include -#include -#include -#include -#include - -//--------------------------------------------------------------------- -// TDEAccelAction -//--------------------------------------------------------------------- - -class TDEAccelActionPrivate -{ - public: - uint m_nConnections; -}; - -TDEAccelAction::TDEAccelAction() -{ - //kdDebug(125) << "TDEAccelAction(): this = " << this << endl; - d = new TDEAccelActionPrivate; - m_pObjSlot = 0; - m_psMethodSlot = 0; - m_bConfigurable = true; - m_bEnabled = true; - m_nIDAccel = 0; - d->m_nConnections = 0; -} - -TDEAccelAction::TDEAccelAction( const TDEAccelAction& action ) -{ - //kdDebug(125) << "TDEAccelAction( copy from \"" << action.m_sName << "\" ): this = " << this << endl; - d = new TDEAccelActionPrivate; - *this = action; -} - -TDEAccelAction::TDEAccelAction( const TQString& sName, const TQString& sLabel, const TQString& sWhatsThis, - const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable, bool bEnabled ) -{ - //kdDebug(125) << "TDEAccelAction( \"" << sName << "\" ): this = " << this << endl; - d = new TDEAccelActionPrivate; - init( sName, sLabel, sWhatsThis, - cutDef3, cutDef4, - pObjSlot, psMethodSlot, - bConfigurable, bEnabled ); -} - -TDEAccelAction::~TDEAccelAction() -{ - //kdDebug(125) << "\t\t\tTDEAccelAction::~TDEAccelAction( \"" << m_sName << "\" ): this = " << this << endl; - delete d; -} - -void TDEAccelAction::clear() -{ - m_cut.clear(); - m_pObjSlot = 0; - m_psMethodSlot = 0; - m_bConfigurable = true; - m_bEnabled = true; - m_nIDAccel = 0; - d->m_nConnections = 0; -} - -bool TDEAccelAction::init( const TQString& sName, const TQString& sLabel, const TQString& sWhatsThis, - const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable, bool bEnabled ) -{ - m_sName = sName; - m_sLabel = sLabel; - m_sWhatsThis = sWhatsThis; - m_cutDefault3 = rgCutDefaults3; - m_cutDefault4 = rgCutDefaults4; - m_pObjSlot = pObjSlot; - m_psMethodSlot = psMethodSlot; - m_bConfigurable = bConfigurable; - m_bEnabled = bEnabled; - m_nIDAccel = 0; - m_cut = shortcutDefault(); - d->m_nConnections = 0; - if( !m_bEnabled ) - kdDebug(125) << "TDEAccelAction::init( \"" << sName << "\" ): created with enabled = false" << endl; - return true; -} - -TDEAccelAction& TDEAccelAction::operator =( const TDEAccelAction& action ) -{ - m_sName = action.m_sName; - m_sLabel = action.m_sLabel; - m_sWhatsThis = action.m_sWhatsThis; - m_cutDefault3 = action.m_cutDefault3; - m_cutDefault4 = action.m_cutDefault4; - m_pObjSlot = action.m_pObjSlot; - m_psMethodSlot = action.m_psMethodSlot; - m_bConfigurable = action.m_bConfigurable; - m_bEnabled = action.m_bEnabled; - m_nIDAccel = action.m_nIDAccel; - m_cut = action.m_cut; - d->m_nConnections = action.d->m_nConnections; - - return *this; -} - -void TDEAccelAction::setName( const TQString& s ) - { m_sName = s; } -void TDEAccelAction::setLabel( const TQString& s ) - { m_sLabel = s; } -void TDEAccelAction::setWhatsThis( const TQString& s ) - { m_sWhatsThis = s; } - -bool TDEAccelAction::setShortcut( const TDEShortcut& cut ) -{ - m_cut = cut; - return true; -} - -void TDEAccelAction::setSlot( const TQObject* pObjSlot, const char* psMethodSlot ) -{ - m_pObjSlot = pObjSlot; - m_psMethodSlot = psMethodSlot; -} - -void TDEAccelAction::setConfigurable( bool b ) - { m_bConfigurable = b; } -void TDEAccelAction::setEnabled( bool b ) - { m_bEnabled = b; } - -TQString TDEAccelAction::toString() const - { return m_cut.toString(); } - -TQString TDEAccelAction::toStringInternal() const - { return m_cut.toStringInternal( &shortcutDefault() ); } - -bool TDEAccelAction::setKeySequence( uint i, const KKeySequence& seq ) -{ - if( i < m_cut.count() ) { - m_cut.setSeq( i, seq ); - return true; - } else if( i == m_cut.count() ) - return m_cut.append( seq ); - return false; -} - -void TDEAccelAction::clearShortcut() -{ - m_cut.clear(); -} - -bool TDEAccelAction::contains( const KKeySequence& seq ) -{ - return m_cut.contains( seq ); - for( uint i = 0; i < m_cut.count(); i++ ) { - if( m_cut.seq(i) == seq ) - return true; - } - return false; -} - -const TDEShortcut& TDEAccelAction::shortcutDefault() const - { return (useFourModifierKeys()) ? m_cutDefault4 : m_cutDefault3; } -bool TDEAccelAction::isConnected() const - { return d->m_nConnections; } -void TDEAccelAction::incConnections() - { d->m_nConnections++; } -void TDEAccelAction::decConnections() - { if( d->m_nConnections > 0 ) d->m_nConnections--; } - -// Indicate whether to default to the 3- or 4- modifier keyboard schemes -int TDEAccelAction::g_bUseFourModifierKeys = -1; - -bool TDEAccelAction::useFourModifierKeys() -{ - if( TDEAccelAction::g_bUseFourModifierKeys == -1 ) { - // Read in whether to use 4 modifier keys - TDEConfigGroupSaver cgs( TDEGlobal::config(), "Keyboard" ); - bool b = TDEGlobal::config()->readBoolEntry( "Use Four Modifier Keys", false ); - TDEAccelAction::g_bUseFourModifierKeys = b && KKeyNative::keyboardHasWinKey(); - } - return TDEAccelAction::g_bUseFourModifierKeys == 1; -} - -void TDEAccelAction::useFourModifierKeys( bool b ) -{ - if( TDEAccelAction::g_bUseFourModifierKeys != (int)b ) { - TDEAccelAction::g_bUseFourModifierKeys = b && KKeyNative::keyboardHasWinKey(); - // If we're 'turning off' the meta key or, if we're turning it on, - // the keyboard must actually have a meta key. - if( b && !KKeyNative::keyboardHasWinKey() ) - kdDebug(125) << "Tried to use four modifier keys on a keyboard layout without a Meta key.\n"; - } - TDEConfigGroupSaver cgs( TDEGlobal::config(), "Keyboard" ); - TDEGlobal::config()->writeEntry( "Use Four Modifier Keys", TDEAccelAction::g_bUseFourModifierKeys, true, true); - - kdDebug(125) << "bUseFourModifierKeys = " << TDEAccelAction::g_bUseFourModifierKeys << endl; -} - -//--------------------------------------------------------------------- -// TDEAccelActions -//--------------------------------------------------------------------- - -class TDEAccelActionsPrivate -{ - public: -}; - -TDEAccelActions::TDEAccelActions() -{ - kdDebug(125) << "TDEAccelActions(): this = " << this << endl; - initPrivate( 0 ); -} - -TDEAccelActions::TDEAccelActions( const TDEAccelActions& actions ) -{ - kdDebug(125) << "TDEAccelActions( actions = " << &actions << " ): this = " << this << endl; - initPrivate( 0 ); - init( actions ); -} - -TDEAccelActions::TDEAccelActions( TDEAccelBase* pTDEAccelBase ) -{ - kdDebug(125) << "TDEAccelActions( TDEAccelBase = " << pTDEAccelBase << " ): this = " << this << endl; - initPrivate( pTDEAccelBase ); -} - -TDEAccelActions::~TDEAccelActions() -{ - //kdDebug(125) << "TDEAccelActions::~TDEAccelActions(): this = " << this << endl; - clear(); - //delete d; -} - -void TDEAccelActions::initPrivate( TDEAccelBase* pTDEAccelBase ) -{ - m_pTDEAccelBase = pTDEAccelBase; - m_nSizeAllocated = m_nSize = 0; - m_prgActions = 0; - //d = new TDEAccelActionsPrivate; -} - -void TDEAccelActions::clear() -{ - kdDebug(125) << "\tTDEAccelActions::clear()" << endl; - for( uint i = 0; i < m_nSize; i++ ) - delete m_prgActions[i]; - delete[] m_prgActions; - - m_nSizeAllocated = m_nSize = 0; - m_prgActions = 0; -} - -bool TDEAccelActions::init( const TDEAccelActions& actions ) -{ - clear(); - resize( actions.count() ); - for( uint i = 0; i < m_nSize; i++ ) { - TDEAccelAction* pAction = actions.m_prgActions[i]; - if( pAction ) - m_prgActions[i] = new TDEAccelAction( *pAction ); - else - m_prgActions[i] = 0; - } - - return true; -} - -bool TDEAccelActions::init( TDEConfigBase& config, const TQString& sGroup ) -{ - kdDebug(125) << "TDEAccelActions::init( " << sGroup << " )" << endl; - TQMap mapEntry = config.entryMap( sGroup ); - resize( mapEntry.count() ); - - TQMap::Iterator it( mapEntry.begin() ); - for( uint i = 0; it != mapEntry.end(); ++it, i++ ) { - TQString sShortcuts = *it; - TDEShortcut cuts; - - kdDebug(125) << it.key() << " = " << sShortcuts << endl; - if( !sShortcuts.isEmpty() && sShortcuts != "none" ) - cuts.init( sShortcuts ); - - m_prgActions[i] = new TDEAccelAction( it.key(), it.key(), it.key(), - cuts, cuts, - 0, 0, // pObjSlot, psMethodSlot, - true, false ); // bConfigurable, bEnabled - } - - return true; -} - -void TDEAccelActions::resize( uint nSize ) -{ - if( nSize > m_nSizeAllocated ) { - uint nSizeAllocated = ((nSize/10) + 1) * 10; - TDEAccelAction** prgActions = new TDEAccelAction* [nSizeAllocated]; - - // Copy pointers over to new array - for( uint i = 0; i < m_nSizeAllocated; i++ ) - prgActions[i] = m_prgActions[i]; - - // Null out new pointers - for( uint i = m_nSizeAllocated; i < nSizeAllocated; i++ ) - prgActions[i] = 0; - - delete[] m_prgActions; - m_prgActions = prgActions; - m_nSizeAllocated = nSizeAllocated; - } - - m_nSize = nSize; -} - -void TDEAccelActions::insertPtr( TDEAccelAction* pAction ) -{ - resize( m_nSize + 1 ); - m_prgActions[m_nSize-1] = pAction; -} - -void TDEAccelActions::updateShortcuts( TDEAccelActions& actions2 ) -{ - kdDebug(125) << "TDEAccelActions::updateShortcuts()" << endl; - bool bChanged = false; - - for( uint i = 0; i < m_nSize; i++ ) { - TDEAccelAction* pAction = m_prgActions[i]; - if( pAction && pAction->m_bConfigurable ) { - TDEAccelAction* pAction2 = actions2.actionPtr( pAction->m_sName ); - if( pAction2 ) { - TQString sOld = pAction->m_cut.toStringInternal(); - pAction->m_cut = pAction2->m_cut; - kdDebug(125) << "\t" << pAction->m_sName - << " found: " << sOld - << " => " << pAction2->m_cut.toStringInternal() - << " = " << pAction->m_cut.toStringInternal() << endl; - bChanged = true; - } - } - } - - if( bChanged ) - emitKeycodeChanged(); -} - -int TDEAccelActions::actionIndex( const TQString& sAction ) const -{ - for( uint i = 0; i < m_nSize; i++ ) { - if( m_prgActions[i] == 0 ) - kdWarning(125) << "TDEAccelActions::actionPtr( " << sAction << " ): encountered null pointer at m_prgActions[" << i << "]" << endl; - else if( m_prgActions[i]->m_sName == sAction ) - return (int) i; - } - return -1; -} - -TDEAccelAction* TDEAccelActions::actionPtr( uint i ) -{ - return m_prgActions[i]; -} - -const TDEAccelAction* TDEAccelActions::actionPtr( uint i ) const -{ - return m_prgActions[i]; -} - -TDEAccelAction* TDEAccelActions::actionPtr( const TQString& sAction ) -{ - int i = actionIndex( sAction ); - return (i >= 0) ? m_prgActions[i] : 0; -} - -const TDEAccelAction* TDEAccelActions::actionPtr( const TQString& sAction ) const -{ - int i = actionIndex( sAction ); - return (i >= 0) ? m_prgActions[i] : 0; -} - -TDEAccelAction* TDEAccelActions::actionPtr( KKeySequence cut ) -{ - for( uint i = 0; i < m_nSize; i++ ) { - if( m_prgActions[i] == 0 ) - kdWarning(125) << "TDEAccelActions::actionPtr( " << cut.toStringInternal() << " ): encountered null pointer at m_prgActions[" << i << "]" << endl; - else if( m_prgActions[i]->contains( cut ) ) - return m_prgActions[i]; - } - return 0; -} - -TDEAccelAction& TDEAccelActions::operator []( uint i ) -{ - return *actionPtr( i ); -} - -const TDEAccelAction& TDEAccelActions::operator []( uint i ) const -{ - return *actionPtr( i ); -} - -TDEAccelAction* TDEAccelActions::insert( const TQString& sName, const TQString& sLabel ) -{ - if( actionPtr( sName ) ) { - kdWarning(125) << "TDEAccelActions::insertLabel( " << sName << ", " << sLabel << " ): action with same name already present." << endl; - return 0; - } - - TDEAccelAction* pAction = new TDEAccelAction; - pAction->m_sName = sName; - pAction->m_sLabel = sLabel; - pAction->m_bConfigurable = false; - pAction->m_bEnabled = false; - - insertPtr( pAction ); - return pAction; -} - -TDEAccelAction* TDEAccelActions::insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, - const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable, bool bEnabled ) -{ - //kdDebug(125) << "TDEAccelActions::insert()2 begin" << endl; - if( actionPtr( sAction ) ) { - kdWarning(125) << "TDEAccelActions::insert( " << sAction << " ): action with same name already present." << endl; - return 0; - } - - TDEAccelAction* pAction = new TDEAccelAction( - sAction, sLabel, sWhatsThis, - rgCutDefaults3, rgCutDefaults4, - pObjSlot, psMethodSlot, - bConfigurable, bEnabled ); - insertPtr( pAction ); - - //kdDebug(125) << "TDEAccelActions::insert()2 end" << endl; - return pAction; -} - -bool TDEAccelActions::remove( const TQString& sAction ) -{ - kdDebug(125) << "TDEAccelActions::remove( \"" << sAction << "\" ): this = " << this << " m_pTDEAccelBase = " << m_pTDEAccelBase << endl; - - int iAction = actionIndex( sAction ); - if( iAction < 0 ) - return false; - - if( m_pTDEAccelBase ) - m_pTDEAccelBase->slotRemoveAction( m_prgActions[iAction] ); - delete m_prgActions[iAction]; - - for( uint i = iAction; i < m_nSize - 1; i++ ) - m_prgActions[i] = m_prgActions[i+1]; - m_nSize--; - - return true; -} - -bool TDEAccelActions::readActions( const TQString& sConfigGroup, TDEConfigBase* pConfig ) -{ - TDEAccelShortcutList accelList(*this, false); - return accelList.readSettings( sConfigGroup, pConfig ); -} - -/* - 1) TDEAccelAction = "Something" - 1) KKeySequence = "Meta+X,Asterisk" - 1) TDEAccelSequence = "Meta+X" - 1) KKeySequence = Meta+X - 2) TDEAccelSequence = "Asterisk" - 1) KKeySequence = Shift+8 (English layout) - 2) KKeySequence = Keypad_Asterisk - 2) KKeySequence = "Alt+F2" - 1) TDEAccelSequence = "Alt+F2" - 1) KKeySequence = Alt+F2 - -> "Something=Meta+X,Asterisk;Alt+F2" -*/ -bool TDEAccelActions::writeActions( const TQString &sGroup, TDEConfigBase* pConfig, - bool bWriteAll, bool bGlobal ) const -{ - kdDebug(125) << "TDEAccelActions::writeActions( " << sGroup << ", " << pConfig << ", " << bWriteAll << ", " << bGlobal << " )" << endl; - if( !pConfig ) - pConfig = TDEGlobal::config(); - TDEConfigGroupSaver cs( pConfig, sGroup ); - - for( uint i = 0; i < m_nSize; i++ ) { - if( m_prgActions[i] == 0 ) { - kdWarning(125) << "TDEAccelActions::writeActions(): encountered null pointer at m_prgActions[" << i << "]" << endl; - continue; - } - const TDEAccelAction& action = *m_prgActions[i]; - - TQString s; - bool bConfigHasAction = !pConfig->readEntry( action.m_sName ).isEmpty(); - bool bSameAsDefault = true; - bool bWriteAction = false; - - if( action.m_bConfigurable ) { - s = action.toStringInternal(); - bSameAsDefault = (action.m_cut == action.shortcutDefault()); - - //if( bWriteAll && s.isEmpty() ) - if( s.isEmpty() ) - s = "none"; - - // If we're using a global config or this setting - // differs from the default, then we want to write. - if( bWriteAll || !bSameAsDefault ) - bWriteAction = true; - - if( bWriteAction ) { - kdDebug(125) << "\twriting " << action.m_sName << " = " << s << endl; - // Is passing bGlobal irrelevant, since if it's true, - // then we're using the global config anyway? --ellis - pConfig->writeEntry( action.m_sName, s, true, bGlobal ); - } - // Otherwise, this key is the same as default - // but exists in config file. Remove it. - else if( bConfigHasAction ) { - kdDebug(125) << "\tremoving " << action.m_sName << " because == default" << endl; - pConfig->deleteEntry( action.m_sName, bGlobal ); - } - - } - } - - pConfig->sync(); - return true; -} - -void TDEAccelActions::emitKeycodeChanged() -{ - if( m_pTDEAccelBase ) - m_pTDEAccelBase->emitSignal( TDEAccelBase::KEYCODE_CHANGED ); -} - -uint TDEAccelActions::count() const - { return m_nSize; } diff --git a/tdecore/kaccelaction.h b/tdecore/kaccelaction.h deleted file mode 100644 index 809533ff8..000000000 --- a/tdecore/kaccelaction.h +++ /dev/null @@ -1,576 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001,2002 Ellis Whitehead - - This library 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. - - 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 _KACCELACTION_H -#define _KACCELACTION_H - -#include -#include -#include -#include - -#include - -class TDEAccelBase; - -class TQObject; -class TDEConfig; -class TDEConfigBase; - -/** - * @internal - * A TDEAccelAction prepresents an action that can be executed using - * an accelerator key. Each TDEAccelAction has a name, a label, a - * "What's this" string and a TDEShortcut. The user can configure and - * enable/disable them using KKeyDialog. - * - * \code - * 1) TDEAccelAction = "Run Command" - * Default3 = "Alt+F2" - * Default4 = "Meta+Enter;Alt+F2" - * 1) TDEShortcut = "Meta+Enter" - * 1) KKeySequence = "Meta+Enter" - * 1) KKey = "Meta+Enter" - * 1) Meta+Enter - * 2) Meta+Keypad_Enter - * 2) TDEShortcut = "Alt+F2" - * 1) KKeySequence = "Alt+F2" - * 1) Alt+F2 - * 2) TDEAccelAction = "Something" - * Default3 = "" - * Default4 = "" - * 1) TDEShortcut = "Meta+X,Asterisk" - * 1) KKeySequence = "Meta+X,Asterisk" - * 1) KKey = "Meta+X" - * 1) Meta+X - * 2) KKey = "Asterisk" - * 1) Shift+8 (English layout) - * 2) Keypad_Asterisk - * \endcode - * @short An accelerator action - * @see TDEAccel - * @see TDEGlobalAccel - * @see KKeyChooser - * @see KKeyDialog - */ -class TDECORE_EXPORT TDEAccelAction -{ - public: - /** - * Creates an empty TDEAccelAction. - * @see clear() - */ - TDEAccelAction(); - - /** - * Copy constructor. - */ - TDEAccelAction( const TDEAccelAction& ); - - /** - * Creates a new TDEAccelAction. - * @param sName the name of the accelerator - * @param sLabel the label of the accelerator (i18n!) - * @param sWhatsThis the What's This text (18n!) - * @param cutDef3 the default shortcut for 3 modifier systems - * @param cutDef4 the default shortcut for 4 modifier systems - * @param pObjSlot the receiver of a signal when the key has been - * pressed - * @param psMethodSlot the slot to connect for key presses. Receives - * an int, as set by setID(), as only argument - * @param bConfigurable if true the user can configure the shortcut - * @param bEnabled true if the accelerator should be enabled - */ - TDEAccelAction( const TQString& sName, const TQString& sLabel, const TQString& sWhatsThis, - const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable, bool bEnabled ); - ~TDEAccelAction(); - - /** - * Clears the accelerator. - */ - void clear(); - - /** - * Re-initialized the TDEAccelAction. - * @param sName the name of the accelerator - * @param sLabel the label of the accelerator (i18n!) - * @param sWhatsThis the What's This text (18n!) - * @param cutDef3 the default shortcut for 3 modifier systems - * @param cutDef4 the default shortcut for 4 modifier systems - * @param pObjSlot the receiver of a signal when the key has been - * pressed - * @param psMethodSlot the slot to connect for key presses. Receives - * an int, as set by setID(), as only argument - * @param bConfigurable if true the user can configure the shortcut - * @param bEnabled true if the accelerator should be enabled - * @return true if successful, false otherwise - */ - bool init( const TQString& sName, const TQString& sLabel, const TQString& sWhatsThis, - const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable, bool bEnabled ); - - /** - * Copies this TDEAccelAction. - */ - TDEAccelAction& operator=( const TDEAccelAction& ); - - /** - * Returns the name of the accelerator action. - * @return the name of the accelerator action, can be null if not - * set - */ - const TQString& name() const { return m_sName; } - - /** - * Returns the label of the accelerator action. - * @return the label of the accelerator action, can be null if - * not set - */ - const TQString& label() const { return m_sLabel; } - - /** - * Returns the What's This text of the accelerator action. - * @return the What's This text of the accelerator action, can be - * null if not set - */ - const TQString& whatsThis() const { return m_sWhatsThis; } - - /** - * The shortcut that is actually used (may be used configured). - * @return the shortcut of the TDEAccelAction, can be null if not set - * @see shortcutDefault() - */ - const TDEShortcut& shortcut() const { return m_cut; } - - /** - * The default shortcut for this system. - * @return the default shortcut on this system, can be null if not set - * @see shortcut() - * @see shortcutDefault3() - * @see shortcutDefault4() - */ - const TDEShortcut& shortcutDefault() const; - - /** - * The default shortcut for 3 modifier systems. - * @return the default shortcut for 3 modifier systems, can be null - * if not set - * @see shortcutDefault() - * @see shortcutDefault4() - * @see useFourModifierKeys() - */ - const TDEShortcut& shortcutDefault3() const { return m_cutDefault3; } - - /** - * The default shortcut for 4 modifier systems. - * @return the default shortcut for 4 modifier systems, can be null - * if not set - * @see shortcutDefault() - * @see shortcutDefault3() - * @see useFourModifierKeys() - */ - const TDEShortcut& shortcutDefault4() const { return m_cutDefault4; } - - /** - * Returns the receiver of signals. - * @return the receiver of signals (can be 0 if not set) - */ - const TQObject* objSlotPtr() const { return m_pObjSlot; } - - /** - * Returns the slot for the signal. - * @return the slot for the signal - */ - const char* methodSlotPtr() const { return m_psMethodSlot; } - - /** - * Checks whether the user can configure the action. - * @return true if configurable, false otherwise - */ - bool isConfigurable() const { return m_bConfigurable; } - - /** - * Checks whether the action is enabled. - * @return true if enabled, false otherwise - */ - bool isEnabled() const { return m_bEnabled; } - - /** - * Sets the name of the accelerator action. - * @param name the new name - */ - void setName( const TQString& name ); - - /** - * Sets the user-readable label of the accelerator action. - * @param label the new label (i18n!) - */ - void setLabel( const TQString& label ); - - /** - * Sets the What's This text for the accelerator action. - * @param whatsThis the new What's This text (i18n!) - */ - void setWhatsThis( const TQString& whatsThis ); - - /** - * Sets the new shortcut of the accelerator action. - * @param rgCuts the shortcut to set - * @return true if successful, false otherwise - */ - bool setShortcut( const TDEShortcut& rgCuts ); - - /** - * Sets the slot of the accelerator action. - * @param pObjSlot the receiver object of the signal - * @param psMethodSlot the slot for the signal - */ - void setSlot( const TQObject* pObjSlot, const char* psMethodSlot ); - - /** - * Enables or disabled configuring the action. - * @param configurable true to enable configurability, false to disable - */ - void setConfigurable( bool configurable ); - - /** - * Enables or disabled the action. - * @param enable true to enable the action, false to disable - */ - void setEnabled( bool enable ); - - /** - * Retrieves the id set using setID. - * @return the id of the accelerator action - */ - int getID() const { return m_nIDAccel; } - - /** - * Allows you to set an id that will be used as the action - * signal's argument. - * - * @param n the new id - * @see getID() - */ - void setID( int n ) { m_nIDAccel = n; } - - /** - * Checkes whether the action is connected (emits signals). - * @return true if connected, false otherwise - */ - bool isConnected() const; - - /** - * Sets a key sequence of the action's shortcut. - * @param i the position of the sequence - * @param keySeq the new new sequence - * @return true if successful, false otherwise - * @see TDEShortcut::setSeq() - */ - bool setKeySequence( uint i, const KKeySequence &keySeq ); - - /** - * Clears the action's shortcut. It will not contain any sequences after - * calling this method. - * @see TDEShortcut::clear() - */ - void clearShortcut(); - - /** - * Checks whether the action's shortcut contains the given key sequence. - * @param keySeq the key sequence to check - * @return true if the shortcut contains the given sequence - * @see TDEShortcut::contains() - */ - bool contains( const KKeySequence &keySeq ); - - /** - * Returns the string representation of the action's shortcut. - * @return the string representation of the action's shortcut. - * @see TDEShortcut::toString() - */ - TQString toString() const; - - /** - * @internal - */ - TQString toStringInternal() const; - - /** - * Returns true if four modifier keys will be used. - * @return true if four modifier keys will be used. - */ - static bool useFourModifierKeys(); - - /** - * Selects 3 or 4 modifier default shortcuts. - * @param use true to use 4 modifier shortcuts, false to use - * 3 modifier shortcuts - */ - static void useFourModifierKeys( bool use ); - - protected: - TQString m_sName /**< Name of accel. @sa setName() */, - m_sLabel /**< Label of accel. User-visible. */, - m_sWhatsThis /**< WhatsThis help for accel. User-visible. */; - TDEShortcut m_cut /**< Shortcut actually assigned. */; - TDEShortcut m_cutDefault3 /**< Default shortcut in 3-modifier layout */, - m_cutDefault4 /**< Default shortcur in 4-modifier layout */; - const TQObject* m_pObjSlot /**< Object we will send signals to. */; - const char* m_psMethodSlot /**< Slot we send signals to, in m_pObjSlot */; - bool m_bConfigurable /**< Can this accel be configured by the user? */, - m_bEnabled /**< Is this accel enabled? */; - int m_nIDAccel /**< Id of this accel, from the list of IDs */; - uint m_nConnections /**< Number of connections to this accel. */ ; - - /** @internal Increment the number of connections to this accel. */ - void incConnections(); - /** @internal Decrement the number of connections to this accel (bouded by zero). */ - void decConnections(); - - private: - static int g_bUseFourModifierKeys; - class TDEAccelActionPrivate* d; - - friend class TDEAccelActions; - friend class TDEAccelBase; -}; - -//--------------------------------------------------------------------- -// TDEAccelActions -//--------------------------------------------------------------------- - -/** - * @internal - * This class represents a collection of TDEAccelAction objects. - * - * @short A collection of accelerator actions - * @see TDEAccelAction - */ -class TDECORE_EXPORT TDEAccelActions -{ - public: - /** - * Creates a new, empty TDEAccelActions object. - */ - TDEAccelActions(); - - /** - * Copy constructor (deep copy). - */ - TDEAccelActions( const TDEAccelActions& ); - virtual ~TDEAccelActions(); - - /** - * Removes all items from this collection. - */ - void clear(); - - /** - * Initializes this object with the given actions. - * It will make a deep copy of all actions. - * @param actions the actions to copy - * @return true if successful, false otherwise - */ - bool init( const TDEAccelActions &actions ); - - /** - * Loads the actions from the given configuration file. - * - * @param config the configuration file to load from - * @param sGroup the group in the configuration file - * @return true if successful, false otherwise - */ - bool init( TDEConfigBase& config, const TQString& sGroup ); - - /** - * Updates the shortcuts of all actions in this object - * with the shortcuts from the given object. - * @param shortcuts the collection that contains the new - * shortcuts - */ - void updateShortcuts( TDEAccelActions &shortcuts ); - - /** - * Retrieves the index of the action with the given name. - * @param sAction the action to search - * @return the index of the action, or -1 if not found - */ - int actionIndex( const TQString& sAction ) const; - - /** - * Returns the action with the given @p index. - * @param index the index of an action. You must not - * use an index that is too high. - * @return the TDEAccelAction with the given index - * @see count() - */ - TDEAccelAction* actionPtr( uint index ); - - /** - * Returns the action with the given @p index. - * @param index the index of an action. You must not - * use an index that is too high. - * @return the TDEAccelAction with the given index - * @see count() - */ - const TDEAccelAction* actionPtr( uint index ) const; - - /** - * Returns the action with the given name. - * @param sAction the name of the action to search - * @return the TDEAccelAction with the given name, or 0 - * if not found - */ - TDEAccelAction* actionPtr( const TQString& sAction ); - - /** - * Returns the action with the given name. - * @param sAction the name of the action to search - * @return the TDEAccelAction with the given name, or 0 - * if not found - */ - const TDEAccelAction* actionPtr( const TQString& sAction ) const; - - /** - * Returns the action with the given key sequence. - * @param cut the sequence to search for - * @return the TDEAccelAction with the given sequence, or 0 - * if not found - */ - TDEAccelAction* actionPtr( KKeySequence cut ); - - /** - * Returns the action with the given @p index. - * @param index the index of an action. You must not - * use an index that is too high. - * @return the TDEAccelAction with the given index - * @see actionPtr() - * @see count() - */ - TDEAccelAction& operator []( uint index ); - - /** - * Returns the action with the given @p index. - * @param index the index of an action. You must not - * use an index that is too high. - * @return the TDEAccelAction with the given index - * @see actionPtr() - * @see count() - */ - const TDEAccelAction& operator []( uint index ) const; - - /** - * Inserts an action into the collection. - * @param sAction the name of the accelerator - * @param sLabel the label of the accelerator (i18n!) - * @param sWhatsThis the What's This text (18n!) - * @param rgCutDefaults3 the default shortcut for 3 modifier systems - * @param rgCutDefaults4 the default shortcut for 4 modifier systems - * @param pObjSlot the receiver of a signal when the key has been - * pressed - * @param psMethodSlot the slot to connect for key presses. Receives - * an int, as set by setID(), as only argument - * @param bConfigurable if true the user can configure the shortcut - * @param bEnabled if true the accelerator should be enabled - * @return the new action - */ - TDEAccelAction* insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, - const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4, - const TQObject* pObjSlot = 0, const char* psMethodSlot = 0, - bool bConfigurable = true, bool bEnabled = true ); - - /** - * Inserts an action into the collection. - * @param sName the name of the accelerator - * @param sLabel the label of the accelerator (i18n!) - * @return the new action - */ - TDEAccelAction* insert( const TQString& sName, const TQString& sLabel ); - - /** - * Removes the given action. - * @param sAction the name of the action. - * @return true if successful, false otherwise - */ - bool remove( const TQString& sAction ); - - /** - * Loads the actions from the given configuration file. - * - * @param sConfigGroup the group in the configuration file - * @param pConfig the configuration file to load from - * @return true if successful, false otherwise - */ - bool readActions( const TQString& sConfigGroup = "Shortcuts", TDEConfigBase* pConfig = 0 ); - - /** - * Writes the actions to the given configuration file. - * - * @param sConfigGroup the group in the configuration file - * @param pConfig the configuration file to save to - * @param bWriteAll true to write all actions - * @param bGlobal true to write to the global configuration file - * @return true if successful, false otherwise - */ - bool writeActions( const TQString& sConfigGroup = "Shortcuts", TDEConfigBase* pConfig = 0, - bool bWriteAll = false, bool bGlobal = false ) const; - - /** - * Emit a keycodeChanged signal. - */ - void emitKeycodeChanged(); - - /** - * Returns the number of actions in the collection. - * @return the number of actions - */ - uint count() const; - - protected: - /** Base object that proxies signals from us. */ - TDEAccelBase* m_pTDEAccelBase; - /** Array of actions we're hanging on to. */ - TDEAccelAction** m_prgActions; - uint m_nSizeAllocated /**< Allocated size of the array. */, - m_nSize /**< Amount in use. */ ; - - /** - * Resize the list to the given number @p new_size of entries. - * @todo Can you make it smaller? - * @todo Implementation seems to break m_nSize. - */ - void resize( uint new_size ); - /** Add a action to this collection. @todo Document ownership. */ - void insertPtr( TDEAccelAction* ); - - private: - class TDEAccelActionsPrivate* d; - - TDEAccelActions( TDEAccelBase* ); - void initPrivate( TDEAccelBase* ); - TDEAccelActions& operator =( TDEAccelActions& ); - - friend class TDEAccelBase; -}; - -#endif // _KACCELACTION_H diff --git a/tdecore/kaccelbase.cpp b/tdecore/kaccelbase.cpp deleted file mode 100644 index 235803134..000000000 --- a/tdecore/kaccelbase.cpp +++ /dev/null @@ -1,616 +0,0 @@ -/* - Copyright (C) 1997-2000 Nicolas Hadacek - Copyright (C) 1998 Mark Donohoe - Copyright (C) 1998 Matthias Ettrich - Copyright (c) 2001,2002 Ellis Whitehead - - This library 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. - - 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. -*/ - -#include "kaccelbase.h" - -#include -#include -#include - -#include -#include "kckey.h" -#include -#include -#include -#include "kkeyserver.h" -#include -#include "kshortcutmenu.h" - -//--------------------------------------------------------------------- -// class TDEAccelBase::ActionInfo -//--------------------------------------------------------------------- - -//--------------------------------------------------------------------- -// class TDEAccelBase -//--------------------------------------------------------------------- - -TDEAccelBase::TDEAccelBase( int fInitCode ) -: m_rgActions( this ) -{ - kdDebug(125) << "TDEAccelBase(): this = " << this << endl; - m_bNativeKeys = fInitCode & NATIVE_KEYS; - m_bEnabled = true; - m_sConfigGroup = "Shortcuts"; - m_bConfigIsGlobal = false; - m_bAutoUpdate = false; - mtemp_pActionRemoving = 0; -} - -TDEAccelBase::~TDEAccelBase() -{ - kdDebug(125) << "~TDEAccelBase(): this = " << this << endl; -} - -uint TDEAccelBase::actionCount() const { return m_rgActions.count(); } -TDEAccelActions& TDEAccelBase::actions() { return m_rgActions; } -bool TDEAccelBase::isEnabled() const { return m_bEnabled; } -// see TDEGlobalAccel::blockShortcuts() stuff - it's to temporarily block -// all global shortcuts, so that the key grabs are released, but from the app's -// point of view the TDEGlobalAccel is still enabled, so TDEGlobalAccel needs -// to disable key grabbing even if enabled -bool TDEAccelBase::isEnabledInternal() const { return isEnabled(); } - -TDEAccelAction* TDEAccelBase::actionPtr( const TQString& sAction ) - { return m_rgActions.actionPtr( sAction ); } - -const TDEAccelAction* TDEAccelBase::actionPtr( const TQString& sAction ) const - { return m_rgActions.actionPtr( sAction ); } - -TDEAccelAction* TDEAccelBase::actionPtr( const KKeyServer::Key& key ) -{ - if( !m_mapKeyToAction.contains( key ) ) - return 0; - // Note: If more than one action is connected to a single key, nil will be returned. - return m_mapKeyToAction[key].pAction; -} - -TDEAccelAction* TDEAccelBase::actionPtr( const KKey& key ) -{ - KKeyServer::Key k2; - k2.init( key, !m_bNativeKeys ); - return actionPtr( k2 ); -} - -void TDEAccelBase::setConfigGroup( const TQString& sConfigGroup ) - { m_sConfigGroup = sConfigGroup; } - -void TDEAccelBase::setConfigGlobal( bool global ) - { m_bConfigIsGlobal = global; } - -bool TDEAccelBase::setActionEnabled( const TQString& sAction, bool bEnable ) -{ - TDEAccelAction* pAction = actionPtr( sAction ); - if( pAction ) { - if( pAction->m_bEnabled != bEnable ) { - kdDebug(125) << "TDEAccelBase::setActionEnabled( " << sAction << ", " << bEnable << " )" << endl; - pAction->m_bEnabled = bEnable; - if( m_bAutoUpdate ) { - // FIXME: the action may already have it's connections inserted! - if( bEnable ) - insertConnection( pAction ); - else if( pAction->isConnected() ) - removeConnection( pAction ); - } - } - return true; - } - return false; -} - -bool TDEAccelBase::setAutoUpdate( bool bAuto ) -{ - kdDebug(125) << "TDEAccelBase::setAutoUpdate( " << bAuto << " ): m_bAutoUpdate on entrance = " << m_bAutoUpdate << endl; - bool b = m_bAutoUpdate; - if( !m_bAutoUpdate && bAuto ) - updateConnections(); - m_bAutoUpdate = bAuto; - return b; -} - -TDEAccelAction* TDEAccelBase::insert( const TQString& sAction, const TQString& sDesc, const TQString& sHelp, - const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable, bool bEnabled ) -{ - //kdDebug(125) << "TDEAccelBase::insert() begin" << endl; - TDEAccelAction* pAction = m_rgActions.insert( - sAction, sDesc, sHelp, - rgCutDefaults3, rgCutDefaults4, - pObjSlot, psMethodSlot, - bConfigurable, bEnabled ); - - if( pAction && m_bAutoUpdate ) - insertConnection( pAction ); - - //kdDebug(125) << "TDEAccelBase::insert() end" << endl; - return pAction; -} - -TDEAccelAction* TDEAccelBase::insert( const TQString& sName, const TQString& sDesc ) - { return m_rgActions.insert( sName, sDesc ); } - -bool TDEAccelBase::remove( const TQString& sAction ) -{ - return m_rgActions.remove( sAction ); -} - -void TDEAccelBase::slotRemoveAction( TDEAccelAction* pAction ) -{ - removeConnection( pAction ); -} - -bool TDEAccelBase::setActionSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ) -{ - kdDebug(125) << "TDEAccelBase::setActionSlot( " << sAction << ", " << pObjSlot << ", " << psMethodSlot << " )\n"; - TDEAccelAction* pAction = m_rgActions.actionPtr( sAction ); - if( pAction ) { - // If there was a previous connection, remove it. - if( m_bAutoUpdate && pAction->isConnected() ) { - kdDebug(125) << "\tm_pObjSlot = " << pAction->m_pObjSlot << " m_psMethodSlot = " << pAction->m_psMethodSlot << endl; - removeConnection( pAction ); - } - - pAction->m_pObjSlot = pObjSlot; - pAction->m_psMethodSlot = psMethodSlot; - - // If we're setting a connection, - if( m_bAutoUpdate && pObjSlot && psMethodSlot ) - insertConnection( pAction ); - - return true; - } else - return false; -} - -/* -TDEAccelBase - Run Command=Meta+Enter;Alt+F2 - TDEAccelAction = "Run Command" - 1) TDEAccelKeySeries = "Meta+Enter" - 1a) Meta+Enter - 1b) Meta+Keypad_Enter - 2) TDEAccelKeySeries = "Alt+F2" - 1a) Alt+F2 - - Konqueror=Meta+I,I - TDEAccelAction = "Konqueror" - 1) TDEAccelKeySeries = "Meta+I,I" - 1a) Meta+I - 2a) I - - Something=Meta+Asterisk,X - TDEAccelAction = "Something" - 1) TDEAccelKeySeries = "Meta+Asterisk,X" - 1a) Meta+Shift+8 - 1b) Meta+Keypad_8 - 2a) X - -read in a config entry - split by ';' - find key sequences to disconnect - find new key sequences to connect -check for conflicts with implicit keys - disconnect conflicting implicit keys -connect new key sequences -*/ -/* -{ - For { - for( TDEAccelAction::iterator itAction = m_rgActions.begin(); itAction != m_rgActions.end(); ++itAction ) { - TDEAccelAction& action = *itAction; - for( TDEAccelSeries::iterator itSeries = action.m_rgSeries.begin(); itSeries != action.m_rgSeries.end(); ++itSeries ) { - TDEAccelSeries& series = *itSeries; - if( - } - } - } - Sort by: iVariation, iSequence, iSeries, iAction - - 1) TDEAccelAction = "Run Command" - 1) TDEAccelKeySeries = "Meta+Enter" - 1a) Meta+Enter - 1b) Meta+Keypad_Enter - 2) TDEAccelKeySeries = "Alt+F2" - 1a) Alt+F2 - - 2) TDEAccelAction = "Enter Calculation" - 1) TDEAccelKeySeries = "Meta+Keypad_Enter" - 1a) Meta+Keypad_Enter - - List = - Meta+Enter -> 1, 1, 1a - Meta+Keypad_Enter -> 2, 1, 1a - Alt+F2 -> 1, 2, 1a - [Meta+Keypad_Enter] -> [1, 1, 1b] - -} -*/ - -#ifdef Q_WS_X11 -struct TDEAccelBase::X -{ - uint iAction, iSeq, iVari; - KKeyServer::Key key; - - X() {} - X( uint _iAction, uint _iSeq, uint _iVari, const KKeyServer::Key& _key ) - { iAction = _iAction; iSeq = _iSeq; iVari = _iVari; key = _key; } - - int compare( const X& x ) - { - int n = key.compare( x.key ); - if( n != 0 ) return n; - if( iVari != x.iVari ) return iVari - x.iVari; - if( iSeq != x.iSeq ) return iSeq - x.iSeq; - return 0; - } - - bool operator <( const X& x ) { return compare( x ) < 0; } - bool operator >( const X& x ) { return compare( x ) > 0; } - bool operator <=( const X& x ) { return compare( x ) <= 0; } -}; -#endif //Q_WS_X11 - -/* -#1 Ctrl+A -#2 Ctrl+A -#3 Ctrl+B - ------ - Ctrl+A => Null - Ctrl+B => #3 - -#1 Ctrl+A -#1 Ctrl+B;Ctrl+A - ------ - Ctrl+A => #1 - Ctrl+B => #2 - -#1 Ctrl+A -#1 Ctrl+B,C -#1 Ctrl+B,D - ------ - Ctrl+A => #1 - Ctrl+B => Null - -#1 Ctrl+A -#2 Ctrl+Plus(Ctrl+KP_Add) - ------ - Ctrl+A => #1 - Ctrl+Plus => #2 - Ctrl+KP_Add => #2 - -#1 Ctrl+Plus(Ctrl+KP_Add) -#2 Ctrl+KP_Add - ------ - Ctrl+Plus => #1 - Ctrl+KP_Add => #2 - -#1 Ctrl+Plus(Ctrl+KP_Add) -#2 Ctrl+A;Ctrl+KP_Add - ------ - Ctrl+A => #2 - Ctrl+Plus => #1 - Ctrl+KP_Add => #2 -*/ - -bool TDEAccelBase::updateConnections() -{ -#ifdef Q_WS_X11 - kdDebug(125) << "TDEAccelBase::updateConnections() this = " << this << endl; - // Retrieve the list of keys to be connected, sorted by priority. - // (key, variation, seq) - TQValueVector rgKeys; - createKeyList( rgKeys ); - m_rgActionsNonUnique.clear(); - - KKeyToActionMap mapKeyToAction; - for( uint i = 0; i < rgKeys.size(); i++ ) { - X& x = rgKeys[i]; - KKeyServer::Key& key = x.key; - ActionInfo info; - bool bNonUnique = false; - - info.pAction = m_rgActions.actionPtr( x.iAction ); - info.iSeq = x.iSeq; - info.iVariation = x.iVari; - - // If this is a multi-key shortcut, - if( info.pAction->shortcut().seq(info.iSeq).count() > 1 ) - bNonUnique = true; - // If this key is requested by more than one action, - else if( i < rgKeys.size() - 1 && key == rgKeys[i+1].key ) { - // If multiple actions requesting this key - // have the same priority as the first one, - if( info.iVariation == rgKeys[i+1].iVari && info.iSeq == rgKeys[i+1].iSeq ) - bNonUnique = true; - - kdDebug(125) << "key conflict = " << key.key().toStringInternal() - << " action1 = " << info.pAction->name() - << " action2 = " << m_rgActions.actionPtr( rgKeys[i+1].iAction )->name() - << " non-unique = " << bNonUnique << endl; - - // Skip over the other records with this same key. - while( i < rgKeys.size() - 1 && key == rgKeys[i+1].key ) - i++; - } - - if( bNonUnique ) { - // Remove connection to single action if there is one - if( m_mapKeyToAction.contains( key ) ) { - TDEAccelAction* pAction = m_mapKeyToAction[key].pAction; - if( pAction ) { - m_mapKeyToAction.remove( key ); - disconnectKey( *pAction, key ); - pAction->decConnections(); - m_rgActionsNonUnique.append( pAction ); - } - } - // Indicate that no single action is associated with this key. - m_rgActionsNonUnique.append( info.pAction ); - info.pAction = 0; - } - - //kdDebug(125) << "mapKeyToAction[" << key.toStringInternal() << "] = " << info.pAction << endl; - mapKeyToAction[key] = info; - } - - // Disconnect keys which no longer have bindings: - for( KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); it != m_mapKeyToAction.end(); ++it ) { - const KKeyServer::Key& key = it.key(); - TDEAccelAction* pAction = (*it).pAction; - // If this key is longer used or it points to a different action now, - if( !mapKeyToAction.contains( key ) || mapKeyToAction[key].pAction != pAction ) { - if( pAction ) { - disconnectKey( *pAction, key ); - pAction->decConnections(); - } else - disconnectKey( key ); - } - } - - // Connect any unconnected keys: - // In other words, connect any keys which are present in the - // new action map, but which are _not_ present in the old one. - for( KKeyToActionMap::iterator it = mapKeyToAction.begin(); it != mapKeyToAction.end(); ++it ) { - const KKeyServer::Key& key = it.key(); - TDEAccelAction* pAction = (*it).pAction; - if( !m_mapKeyToAction.contains( key ) || m_mapKeyToAction[key].pAction != pAction ) { - // TODO: Decide what to do if connect fails. - // Probably should remove this item from map. - if( pAction ) { - if( connectKey( *pAction, key ) ) - pAction->incConnections(); - } else - connectKey( key ); - } - } - - // Store new map. - m_mapKeyToAction = mapKeyToAction; - -#ifndef NDEBUG - for( KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); it != m_mapKeyToAction.end(); ++it ) { - kdDebug(125) << "Key: " << it.key().key().toStringInternal() << " => '" - << (((*it).pAction) ? (*it).pAction->name() : TQString::null) << "'" << endl; - } -#endif -#endif //Q_WS_X11 - return true; -} - -#ifdef Q_WS_X11 -// Construct a list of keys to be connected, sorted highest priority first. -void TDEAccelBase::createKeyList( TQValueVector& rgKeys ) -{ - //kdDebug(125) << "TDEAccelBase::createKeyList()" << endl; - if( !isEnabledInternal()) - return; - - // create the list - // For each action - for( uint iAction = 0; iAction < m_rgActions.count(); iAction++ ) { - TDEAccelAction* pAction = m_rgActions.actionPtr( iAction ); - if( pAction && pAction->m_pObjSlot && pAction->m_psMethodSlot && pAction != mtemp_pActionRemoving ) { - // For each key sequence associated with action - for( uint iSeq = 0; iSeq < pAction->shortcut().count(); iSeq++ ) { - const KKeySequence& seq = pAction->shortcut().seq(iSeq); - if( seq.count() > 0 ) { - KKeyServer::Variations vars; - vars.init( seq.key(0), !m_bNativeKeys ); - for( uint iVari = 0; iVari < vars.count(); iVari++ ) { - if( vars.key(iVari).code() && vars.key(iVari).sym() ) - rgKeys.push_back( X( iAction, iSeq, iVari, vars.key( iVari ) ) ); - //kdDebug(125) << "\t" << pAction->name() << ": " << vars.key(iVari).toStringInternal() << endl; - } - } - //else - // kdDebug(125) << "\t*" << pAction->name() << ":" << endl; - } - } - } - - // sort by priority: iVariation[of first key], iSequence, iAction - qHeapSort( rgKeys.begin(), rgKeys.end() ); -} -#endif //Q_WS_X11 - -bool TDEAccelBase::insertConnection( TDEAccelAction* pAction ) -{ - if( !pAction->m_pObjSlot || !pAction->m_psMethodSlot ) - return true; - - kdDebug(125) << "TDEAccelBase::insertConnection( " << pAction << "=\"" << pAction->m_sName << "\"; shortcut = " << pAction->shortcut().toStringInternal() << " ) this = " << this << endl; - - // For each sequence associated with the given action: - for( uint iSeq = 0; iSeq < pAction->shortcut().count(); iSeq++ ) { - // Get the first key of the sequence. - KKeyServer::Variations vars; - vars.init( pAction->shortcut().seq(iSeq).key(0), !m_bNativeKeys ); - for( uint iVari = 0; iVari < vars.count(); iVari++ ) { - const KKeyServer::Key& key = vars.key( iVari ); - - //if( !key.isNull() ) { - if( key.sym() ) { - if( !m_mapKeyToAction.contains( key ) ) { - // If this is a single-key shortcut, - if( pAction->shortcut().seq(iSeq).count() == 1 ) { - m_mapKeyToAction[key] = ActionInfo( pAction, iSeq, iVari ); - if( connectKey( *pAction, key ) ) - pAction->incConnections(); - } - // Else this is a multi-key shortcut, - else { - m_mapKeyToAction[key] = ActionInfo( 0, 0, 0 ); - // Insert into non-unique list if it's not already there. - if( m_rgActionsNonUnique.findIndex( pAction ) == -1 ) - m_rgActionsNonUnique.append( pAction ); - if( connectKey( key ) ) - pAction->incConnections(); - } - } else { - // There is a key conflict. A full update - // check is necessary. - // TODO: make this more efficient where possible. - if( m_mapKeyToAction[key].pAction != pAction - && m_mapKeyToAction[key].pAction != 0 ) { - kdDebug(125) << "Key conflict with action = " << m_mapKeyToAction[key].pAction->name() - << " key = " << key.key().toStringInternal() << " : call updateConnections()" << endl; - return updateConnections(); - } - } - } - } - } - - //kdDebug(125) << "\tActions = " << m_rgActions.size() << endl; - //for( TDEAccelActions::const_iterator it = m_rgActions.begin(); it != m_rgActions.end(); ++it ) { - // kdDebug(125) << "\t" << &(*it) << " '" << (*it).m_sName << "'" << endl; - //} - - //kdDebug(125) << "\tKeys = " << m_mapKeyToAction.size() << endl; - //for( KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); it != m_mapKeyToAction.end(); ++it ) { - // //kdDebug(125) << "\tKey: " << it.key().toString() << " => '" << (*it)->m_sName << "'" << endl; - // kdDebug(125) << "\tKey: " << it.key().toString() << " => '" << *it << "'" << endl; - // kdDebug(125) << "\t\t'" << (*it)->m_sName << "'" << endl; - //} - - return true; -} - -bool TDEAccelBase::removeConnection( TDEAccelAction* pAction ) -{ - kdDebug(125) << "TDEAccelBase::removeConnection( " << pAction << " = \"" << pAction->m_sName << "\"; shortcut = " << pAction->m_cut.toStringInternal() << " ): this = " << this << endl; - - //for( KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); it != m_mapKeyToAction.end(); ++it ) - // kdDebug(125) << "\tKey: " << it.key().toString() << " => '" << (*it)->m_sName << "'" << " " << *it << endl; - - if( m_rgActionsNonUnique.findIndex( pAction ) >= 0 ) { - mtemp_pActionRemoving = pAction; - bool b = updateConnections(); - mtemp_pActionRemoving = 0; - return b; - } - - KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); - while( it != m_mapKeyToAction.end() ) { - KKeyServer::Key key = it.key(); - ActionInfo* pInfo = &(*it); - - // If the given action is connected to this key, - if( pAction == pInfo->pAction ) { - disconnectKey( *pAction, key ); - pAction->decConnections(); - - KKeyToActionMap::iterator itRemove = it++; - m_mapKeyToAction.remove( itRemove ); - } else - ++it; - } - return true; -} - -bool TDEAccelBase::setShortcut( const TQString& sAction, const TDEShortcut& cut ) -{ - TDEAccelAction* pAction = actionPtr( sAction ); - if( pAction ) { - if( m_bAutoUpdate ) - removeConnection( pAction ); - - pAction->setShortcut( cut ); - - if( m_bAutoUpdate && !pAction->shortcut().isNull() ) - insertConnection( pAction ); - return true; - } else - return false; -} - -void TDEAccelBase::readSettings( TDEConfigBase* pConfig ) -{ - m_rgActions.readActions( m_sConfigGroup, pConfig ); - if( m_bAutoUpdate ) - updateConnections(); -} - -void TDEAccelBase::writeSettings( TDEConfigBase* pConfig ) const -{ - m_rgActions.writeActions( m_sConfigGroup, pConfig, m_bConfigIsGlobal, m_bConfigIsGlobal ); -} - -TQPopupMenu* TDEAccelBase::createPopupMenu( TQWidget* pParent, const KKeySequence& seq ) -{ - TDEShortcutMenu* pMenu = new TDEShortcutMenu( pParent, &actions(), seq ); - - bool bActionInserted = false; - bool bInsertSeparator = false; - for( uint i = 0; i < actionCount(); i++ ) { - const TDEAccelAction* pAction = actions().actionPtr( i ); - - if( !pAction->isEnabled() ) - continue; - - // If an action has already been inserted into the menu - // and we have a label instead of an action here, - // then indicate that we should insert a separator before the next menu entry. - if( bActionInserted && !pAction->isConfigurable() && pAction->name().contains( ':' ) ) - bInsertSeparator = true; - - for( uint iSeq = 0; iSeq < pAction->shortcut().count(); iSeq++ ) { - const KKeySequence& seqAction = pAction->shortcut().seq(iSeq); - if( seqAction.startsWith( seq ) ) { - if( bInsertSeparator ) { - pMenu->insertSeparator(); - bInsertSeparator = false; - } - - pMenu->insertAction( i, seqAction ); - - //kdDebug(125) << "sLabel = " << sLabel << ", seq = " << (TQString)seqMenu.qt() << ", i = " << i << endl; - //kdDebug(125) << "pMenu->accel(" << i << ") = " << (TQString)pMenu->accel(i) << endl; - bActionInserted = true; - break; - } - } - } - pMenu->updateShortcuts(); - return pMenu; -} diff --git a/tdecore/kaccelbase.h b/tdecore/kaccelbase.h deleted file mode 100644 index 3d7180c4f..000000000 --- a/tdecore/kaccelbase.h +++ /dev/null @@ -1,282 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001 Ellis Whitehead - - This library 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. - - 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 _KACCELBASE_H -#define _KACCELBASE_H - -#include -#include -#include -#include -#include - -#include "kaccelaction.h" -#include "kkeyserver.h" - -class TQPopupMenu; -class TQWidget; - -//---------------------------------------------------- - -/** - * @internal - * Handle keyboard accelerators. - * - * Allow an user to configure - * key bindings through application configuration files or through the - * KKeyChooser GUI. - * - * A TDEAccel contains a list of accelerator items. Each accelerator item - * consists of an action name and a keyboard code combined with modifiers - * (Shift, Ctrl and Alt.) - * - * For example, "Ctrl+P" could be a shortcut for printing a document. The key - * codes are listed in ckey.h. "Print" could be the action name for printing. - * The action name identifies the key binding in configuration files and the - * KKeyChooser GUI. - * - * When pressed, an accelerator key calls the slot to which it has been - * connected. Accelerator items can be connected so that a key will activate - * two different slots. - * - * A TDEAccel object handles key events sent to its parent widget and to all - * children of this parent widget. - * - * Key binding reconfiguration during run time can be prevented by specifying - * that an accelerator item is not configurable when it is inserted. A special - * group of non-configurable key bindings are known as the - * standard accelerators. - * - * The standard accelerators appear repeatedly in applications for - * standard document actions such as printing and saving. Convenience methods are - * available to insert and connect these accelerators which are configurable on - * a desktop-wide basis. - * - * It is possible for a user to choose to have no key associated with - * an action. - * - * The translated first argument for insertItem() is used only - * in the configuration dialog. - *\code - * TDEAccel *a = new TDEAccel( myWindow ); - * // Insert an action "Scroll Up" which is associated with the "Up" key: - * a->insertItem( i18n("Scroll Up"), "Scroll Up", "Up" ); - * // Insert an action "Scroll Down" which is not associated with any key: - * a->insertItem( i18n("Scroll Down"), "Scroll Down", 0); - * a->connectItem( "Scroll up", myWindow, TQT_SLOT( scrollUp() ) ); - * // a->insertStdItem( TDEStdAccel::Print ); //not necessary, since it - * // is done automatially with the - * // connect below! - * a->connectItem(TDEStdAccel::Print, myWindow, TQT_SLOT( printDoc() ) ); - * - * a->readSettings(); - *\endcode - * - * If a shortcut has a menu entry as well, you could insert them like - * this. The example is again the TDEStdAccel::Print from above. - * - * \code - * int id; - * id = popup->insertItem("&Print",this, TQT_SLOT(printDoc())); - * a->changeMenuAccel(popup, id, TDEStdAccel::Print ); - * \endcode - * - * If you want a somewhat "exotic" name for your standard print action, like - * id = popup->insertItem(i18n("Print &Document"),this, TQT_SLOT(printDoc())); - * it might be a good idea to insert the standard action before as - * a->insertStdItem( TDEStdAccel::Print, i18n("Print Document") ) - * as well, so that the user can easily find the corresponding function. - * - * This technique works for other actions as well. Your "scroll up" function - * in a menu could be done with - * - * \code - * id = popup->insertItem(i18n"Scroll &up",this, TQT_SLOT(scrollUp())); - * a->changeMenuAccel(popup, id, "Scroll Up" ); - * \endcode - * - * Please keep the order right: First insert all functions in the - * acceleratior, then call a -> readSettings() and @em then build your - * menu structure. - * - * @short Configurable key binding support. - */ - -class TDECORE_EXPORT TDEAccelBase -{ - public: - /** Initialization mode of the TDEAccelBase, used in constructor. */ - enum Init { QT_KEYS = 0x00, NATIVE_KEYS = 0x01 }; - - /** Enum for kinds of signals which may be emitted. */ - enum Signal { KEYCODE_CHANGED }; - - /** Constructor. @p fInitCode should be a bitwise OR of - * values from the Init enum. - */ - TDEAccelBase( int fInitCode ); - virtual ~TDEAccelBase(); - - /** Returns number of actions in this handler. */ - uint actionCount() const; - /** Returns a list of all the actions in this handler. */ - TDEAccelActions& actions(); - /** Returns whether this accelerator handler is enabled or not. */ - bool isEnabled() const; - - /** Returns a pointer to the TDEAccelAction named @p sAction. */ - TDEAccelAction* actionPtr( const TQString& sAction ); - /** Const version of the above. */ - const TDEAccelAction* actionPtr( const TQString& sAction ) const; - /** Returns a pointer to the TDEAccelAction associated with - * the key @p key. This function takes into account the - * key mapping defined in the constructor. - * - * May return 0 if no (or more than one) - * action is associated with the key. - */ - TDEAccelAction* actionPtr( const KKey& key ); - /** Basically the same as above, except a KKeyServer::Key - * already has a key mapping defined (either NATIVE_KEYS or not). - */ - TDEAccelAction* actionPtr( const KKeyServer::Key& key ); - - /** Returns the name of the configuration group these - * accelerators are stored in. The default is "Shortcuts". - */ - const TQString& configGroup() const { return m_sConfigGroup; } - /** Set the group (in the configuration file) for storing - * accelerators. - */ - void setConfigGroup( const TQString& group ); - void setConfigGlobal( bool global ); - /** Enables or disables the accelerator. - * @param bEnabled determines whether the accelerator should be enabled or - * disabled. - */ - virtual void setEnabled( bool bEnabled ) = 0; - /** Returns whether autoupdate is enabled for these accelerators. */ - bool getAutoUpdate() { return m_bAutoUpdate; } - /** Enables (or disables) autoupdate for these accelerators. - * @return the value of autoupdate before the call. - */ - bool setAutoUpdate( bool bAuto ); - -// Procedures for manipulating Actions. - //void clearActions(); - - TDEAccelAction* insert( const TQString& sName, const TQString& sDesc ); - TDEAccelAction* insert( - const TQString& sAction, const TQString& sDesc, const TQString& sHelp, - const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4, - const TQObject* pObjSlot, const char* psMethodSlot, - bool bConfigurable = true, bool bEnabled = true ); - bool remove( const TQString& sAction ); - bool setActionSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ); - - bool updateConnections(); - - bool setShortcut( const TQString& sAction, const TDEShortcut& cut ); - -// Modify individual Action sub-items - bool setActionEnabled( const TQString& sAction, bool bEnable ); - - /** - * Read all key associations from @p config, or (if @p config - * is zero) from the application's configuration file - * TDEGlobal::config(). - * - * The group in which the configuration is stored can be - * set with setConfigGroup(). - */ - void readSettings( TDEConfigBase* pConfig = 0 ); - - /** - * Write the current configurable associations to @p config, - * or (if @p config is zero) to the application's - * configuration file. - */ - void writeSettings( TDEConfigBase* pConfig = 0 ) const; - - TQPopupMenu* createPopupMenu( TQWidget* pParent, const KKeySequence& ); - - // Protected methods - protected: - void slotRemoveAction( TDEAccelAction* ); - - struct X; - - /** Constructs a list of keys to be connected, sorted highest priority first. - * @param rgKeys constructed list of keys - */ - void createKeyList( TQValueVector& rgKeys ); - bool insertConnection( TDEAccelAction* ); - bool removeConnection( TDEAccelAction* ); - - /** Emits a signal. - * @param signal signal to be emitted - */ - virtual bool emitSignal( Signal signal ) = 0; - /** Defines a key which activates the accelerator and executes the action - * @param action action to be executed when key is pressed - * @param key key which causes the action to be executed - */ - virtual bool connectKey( TDEAccelAction& action, const KKeyServer::Key& key ) = 0; - /** Defines a key which activates the accelerator - * @param key key which causes the action to be executed - */ - virtual bool connectKey( const KKeyServer::Key& key) = 0; - /** Removes the key from accelerator so it no longer executes the action - */ - virtual bool disconnectKey( TDEAccelAction&, const KKeyServer::Key& ) = 0; - /** Removes the key from accelerator - */ - virtual bool disconnectKey( const KKeyServer::Key& ) = 0; - - protected: - virtual bool isEnabledInternal() const; - struct ActionInfo - { - TDEAccelAction* pAction; - uint iSeq, iVariation; - //ActionInfo* pInfoNext; // nil if only one action uses this key. - - ActionInfo() { pAction = 0; iSeq = 0xffff; iVariation = 0xffff; } - ActionInfo( TDEAccelAction* _pAction, uint _iSeq, uint _iVariation ) - { pAction = _pAction; iSeq = _iSeq; iVariation = _iVariation; } - }; - typedef TQMap KKeyToActionMap; - - TDEAccelActions m_rgActions; - KKeyToActionMap m_mapKeyToAction; - TQValueList m_rgActionsNonUnique; - bool m_bNativeKeys; // Use native key codes instead of Qt codes - bool m_bEnabled; - bool m_bConfigIsGlobal; - TQString m_sConfigGroup; - bool m_bAutoUpdate; - TDEAccelAction* mtemp_pActionRemoving; - - private: - TDEAccelBase& operator =( const TDEAccelBase& ); - - friend class TDEAccelActions; -}; - -#endif // _KACCELBASE_H diff --git a/tdecore/kaccelmanager.cpp b/tdecore/kaccelmanager.cpp deleted file mode 100644 index 9ac4dbdae..000000000 --- a/tdecore/kaccelmanager.cpp +++ /dev/null @@ -1,872 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002 Matthias H�lzer-Kl�pfel - - This library 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. - - 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. -*/ - -#include "kaccelmanager.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - - -#include "kaccelmanager_private.h" -#include "../tdeui/kstdaction_p.h" -#include "../tdeutils/tdemultitabbar.h" - - -/********************************************************************* - - class Item - helper class containing widget information - - This class stores information about the widgets the need accelerators, - as well as about their relationship. - - *********************************************************************/ - - - -/********************************************************************* - - class TDEAcceleratorManagerPrivate - internal helper class - - This class does all the work to find accelerators for a hierarchy of - widgets. - - *********************************************************************/ - - -class TDEAcceleratorManagerPrivate -{ -public: - - static void manage(TQWidget *widget); - static bool programmers_mode; - static bool standardName(const TQString &str); - - static bool checkChange(const TDEAccelString &as) { - TQString t2 = as.accelerated(); - TQString t1 = as.originalText(); - if (t1 != t2) - { - if (as.accel() == -1) { - removed_string += "" + TQStyleSheet::escape(t1) + ""; - } else if (as.originalAccel() == -1) { - added_string += "" + TQStyleSheet::escape(t2) + ""; - } else { - changed_string += "" + TQStyleSheet::escape(t1) + ""; - changed_string += "" + TQStyleSheet::escape(t2) + ""; - } - return true; - } - return false; - } - static TQString changed_string; - static TQString added_string; - static TQString removed_string; - static TQMap ignored_widgets; - -private: - class Item; -public: - typedef TQPtrList ItemList; - -private: - static void traverseChildren(TQWidget *widget, Item *item); - - static void manageWidget(TQWidget *widget, Item *item); - static void manageMenuBar(TQMenuBar *mbar, Item *item); - static void manageTabBar(TQTabBar *bar, Item *item); - - static void calculateAccelerators(Item *item, TQString &used); - - class Item - { - public: - - Item() : m_widget(0), m_children(0), m_index(-1) {} - ~Item(); - - void addChild(Item *item); - - TQWidget *m_widget; - TDEAccelString m_content; - ItemList *m_children; - int m_index; - - }; -}; - - -bool TDEAcceleratorManagerPrivate::programmers_mode = false; -TQString TDEAcceleratorManagerPrivate::changed_string; -TQString TDEAcceleratorManagerPrivate::added_string; -TQString TDEAcceleratorManagerPrivate::removed_string; -static TQStringList *kaccmp_sns = 0; -static KStaticDeleter kaccmp_sns_d; -TQMap TDEAcceleratorManagerPrivate::ignored_widgets; - -bool TDEAcceleratorManagerPrivate::standardName(const TQString &str) -{ - if (!kaccmp_sns) - kaccmp_sns_d.setObject(kaccmp_sns, new TQStringList(KStdAction::internal_stdNames())); - return kaccmp_sns->contains(str); -} - -TDEAcceleratorManagerPrivate::Item::~Item() -{ - delete m_children; -} - - -void TDEAcceleratorManagerPrivate::Item::addChild(Item *item) -{ - if (!m_children) { - m_children = new ItemList; - m_children->setAutoDelete(true); - } - - m_children->append(item); -} - -void TDEAcceleratorManagerPrivate::manage(TQWidget *widget) -{ - if (!widget) - { - kdDebug(131) << "null pointer given to manage" << endl; - return; - } - - if (dynamic_cast(widget)) - { - // create a popup accel manager that can deal with dynamic menus - TDEPopupAccelManager::manage(static_cast(widget)); - return; - } - - Item *root = new Item; - - manageWidget(widget, root); - - TQString used; - calculateAccelerators(root, used); - delete root; -} - - -void TDEAcceleratorManagerPrivate::calculateAccelerators(Item *item, TQString &used) -{ - if (!item->m_children) - return; - - // collect the contents - TDEAccelStringList contents; - for (Item *it = item->m_children->first(); it != 0; - it = item->m_children->next()) - { - contents << it->m_content; - } - - // find the right accelerators - TDEAccelManagerAlgorithm::findAccelerators(contents, used); - - // write them back into the widgets - int cnt = -1; - for (Item *it = item->m_children->first(); it != 0; - it = item->m_children->next()) - { - cnt++; - - TQTabBar *tabBar = dynamic_cast(it->m_widget); - if (tabBar) - { - if (checkChange(contents[cnt])) - tabBar->tabAt(it->m_index)->setText(contents[cnt].accelerated()); - continue; - } - TQMenuBar *menuBar = dynamic_cast(it->m_widget); - if (menuBar) - { - if (it->m_index >= 0) - { - TQMenuItem *mitem = menuBar->findItem(menuBar->idAt(it->m_index)); - if (mitem) - { - checkChange(contents[cnt]); - mitem->setText(contents[cnt].accelerated()); - } - continue; - } - } - // we possibly reserved an accel, but we won't set it as it looks silly - if ( dynamic_cast( it->m_widget ) ) - continue; - // links look weird with ampersands - if ( dynamic_cast( it->m_widget ) && it->m_widget->inherits("KURLLabel") ) - continue; - - int tprop = it->m_widget->metaObject()->findProperty("text", true); - if (tprop != -1) { - if (checkChange(contents[cnt])) - it->m_widget->setProperty("text", contents[cnt].accelerated()); - } else { - tprop = it->m_widget->metaObject()->findProperty("title", true); - if (tprop != -1 && checkChange(contents[cnt])) - it->m_widget->setProperty("title", contents[cnt].accelerated()); - } - } - - // calculate the accelerators for the children - for (Item *it = item->m_children->first(); it != 0; - it = item->m_children->next()) - { - if (it->m_widget && it->m_widget->isVisibleTo( item->m_widget ) ) - calculateAccelerators(it, used); - } -} - - -void TDEAcceleratorManagerPrivate::traverseChildren(TQWidget *widget, Item *item) -{ - TQObjectList *childList = widget->queryList(TQWIDGET_OBJECT_NAME_STRING, 0, false, false); - for ( TQObject *it = childList->first(); it; it = childList->next() ) - { - TQWidget *w = TQT_TQWIDGET(it); - - if ( !w->isVisibleTo( widget ) || ( w->isTopLevel() && dynamic_cast(w) == NULL ) ) - continue; - - if ( TDEAcceleratorManagerPrivate::ignored_widgets.find( w ) != TDEAcceleratorManagerPrivate::ignored_widgets.end() ) - continue; - - manageWidget(w, item); - } - delete childList; -} - -void TDEAcceleratorManagerPrivate::manageWidget(TQWidget *w, Item *item) -{ - // first treat the special cases - - TQTabBar *tabBar = dynamic_cast(w); - if (tabBar) - { - manageTabBar(tabBar, item); - return; - } - - TQWidgetStack *wds = dynamic_cast( w ); - if ( wds ) - { - QWidgetStackAccelManager::manage( wds ); - // return; - } - - TQPopupMenu *popupMenu = dynamic_cast(w); - if (popupMenu) - { - // create a popup accel manager that can deal with dynamic menus - TDEPopupAccelManager::manage(popupMenu); - return; - } - - TQWidgetStack *wdst = dynamic_cast( w ); - if ( wdst ) - { - QWidgetStackAccelManager::manage( wdst ); - // return; - } - - TQMenuBar *menuBar = dynamic_cast(w); - if (menuBar) - { - manageMenuBar(menuBar, item); - return; - } - - if (dynamic_cast(w) || dynamic_cast(w) || - dynamic_cast(w) || dynamic_cast(w) || - dynamic_cast(w) || static_cast(w->tqt_cast("KMultiTabBar"))) - return; - - // now treat 'ordinary' widgets - TQLabel *label = dynamic_cast(w); - if ( label ) { - if ( !label->buddy() ) - label = 0; - else { - if ( label->textFormat() == Qt::RichText || - ( label->textFormat() == Qt::AutoText && - TQStyleSheet::mightBeRichText( label->text() ) ) ) - label = 0; - } - } - - if (w->isFocusEnabled() || label || dynamic_cast(w) || dynamic_cast( w )) - { - TQString content; - TQVariant variant; - int tprop = w->metaObject()->findProperty("text", true); - if (tprop != -1) { - const TQMetaProperty* p = w->metaObject()->property( tprop, true ); - if ( p && p->isValid() ) - w->tqt_property( tprop, 1, &variant ); - else - tprop = -1; - } - - if (tprop == -1) { - tprop = w->metaObject()->findProperty("title", true); - if (tprop != -1) { - const TQMetaProperty* p = w->metaObject()->property( tprop, true ); - if ( p && p->isValid() ) - w->tqt_property( tprop, 1, &variant ); - } - } - - if (variant.isValid()) - content = variant.toString(); - - if (!content.isEmpty()) - { - Item *i = new Item; - i->m_widget = w; - - // put some more weight on the usual action elements - int weight = TDEAccelManagerAlgorithm::DEFAULT_WEIGHT; - if (dynamic_cast(w) || dynamic_cast(w) || dynamic_cast(w) || dynamic_cast(w)) - weight = TDEAccelManagerAlgorithm::ACTION_ELEMENT_WEIGHT; - - // don't put weight on group boxes, as usually the contents are more important - if (dynamic_cast(w)) - weight = TDEAccelManagerAlgorithm::GROUP_BOX_WEIGHT; - - // put a lot of extra weight on the KDialogBaseButton's - if (w->inherits("KDialogBaseButton")) - weight += TDEAccelManagerAlgorithm::DIALOG_BUTTON_EXTRA_WEIGHT; - - i->m_content = TDEAccelString(content, weight); - item->addChild(i); - } - } - traverseChildren(w, item); -} - -void TDEAcceleratorManagerPrivate::manageTabBar(TQTabBar *bar, Item *item) -{ - for (int i=0; icount(); i++) - { - TQString content = bar->tabAt(i)->text(); - if (content.isEmpty()) - continue; - - Item *it = new Item; - item->addChild(it); - it->m_widget = bar; - it->m_index = i; - it->m_content = TDEAccelString(content); - } -} - -void TDEAcceleratorManagerPrivate::manageMenuBar(TQMenuBar *mbar, Item *item) -{ - TQMenuItem *mitem; - TQString s; - - for (uint i=0; icount(); ++i) - { - mitem = mbar->findItem(mbar->idAt(i)); - if (!mitem) - continue; - - // nothing to do for separators - if (mitem->isSeparator()) - continue; - - s = mitem->text(); - if (!s.isEmpty()) - { - Item *it = new Item; - item->addChild(it); - it->m_content = - TDEAccelString(s, - // menu titles are important, so raise the weight - TDEAccelManagerAlgorithm::MENU_TITLE_WEIGHT); - - it->m_widget = mbar; - it->m_index = i; - } - - // have a look at the popup as well, if present - if (mitem->popup()) - TDEPopupAccelManager::manage(mitem->popup()); - } -} - - -/********************************************************************* - - class TDEAcceleratorManager - main entry point - - This class is just here to provide a clean public API... - - *********************************************************************/ - -void TDEAcceleratorManager::manage(TQWidget *widget) -{ - TDEAcceleratorManager::manage(widget, false); -} - -void TDEAcceleratorManager::manage(TQWidget *widget, bool programmers_mode) -{ - kdDebug(131) << "TDEAcceleratorManager::manage\n"; - TDEAcceleratorManagerPrivate::changed_string = TQString::null; - TDEAcceleratorManagerPrivate::added_string = TQString::null; - TDEAcceleratorManagerPrivate::removed_string = TQString::null; - TDEAcceleratorManagerPrivate::programmers_mode = programmers_mode; - TDEAcceleratorManagerPrivate::manage(widget); -} - -void TDEAcceleratorManager::last_manage(TQString &added, TQString &changed, TQString &removed) -{ - added = TDEAcceleratorManagerPrivate::added_string; - changed = TDEAcceleratorManagerPrivate::changed_string; - removed = TDEAcceleratorManagerPrivate::removed_string; -} - - -/********************************************************************* - - class TDEAccelString - a string with weighted characters - - *********************************************************************/ - -TDEAccelString::TDEAccelString(const TQString &input, int initialWeight) - : m_pureText(input), m_weight() -{ - m_orig_accel = m_pureText.find("(!)&"); - if (m_orig_accel != -1) - m_pureText.remove(m_orig_accel, 4); - - m_orig_accel = m_pureText.find("(&&)"); - if (m_orig_accel != -1) - m_pureText.replace(m_orig_accel, 4, "&"); - - m_origText = m_pureText; - - if (m_pureText.contains('\t')) - m_pureText = m_pureText.left(m_pureText.find('\t')); - - m_orig_accel = m_accel = stripAccelerator(m_pureText); - - if (initialWeight == -1) - initialWeight = TDEAccelManagerAlgorithm::DEFAULT_WEIGHT; - - calculateWeights(initialWeight); - - // dump(); -} - - -TQString TDEAccelString::accelerated() const -{ - TQString result = m_origText; - if (result.isEmpty()) - return result; - - if (TDEAcceleratorManagerPrivate::programmers_mode) - { - if (m_accel != m_orig_accel) { - int oa = m_orig_accel; - - if (m_accel >= 0) { - result.insert(m_accel, "(!)&"); - if (m_accel < m_orig_accel) - oa += 4; - } - if (m_orig_accel >= 0) - result.replace(oa, 1, "(&&)"); - } - } else { - if (m_accel >= 0 && m_orig_accel != m_accel) { - result.remove(m_orig_accel, 1); - result.insert(m_accel, "&"); - } - } - return result; -} - - -TQChar TDEAccelString::accelerator() const -{ - if ((m_accel < 0) || (m_accel > (int)m_pureText.length())) - return TQChar(); - - return m_pureText[m_accel].lower(); -} - - -void TDEAccelString::calculateWeights(int initialWeight) -{ - m_weight.resize(m_pureText.length()); - - uint pos = 0; - bool start_character = true; - - while (pos= 0) - { - p = text.find('&', p)+1; - - if (p <= 0 || p >= (int)text.length()) - return -1; - - if (text[p] != '&') - { - TQChar c = text[p]; - if (c.isPrint()) - { - text.remove(p-1,1); - return p-1; - } - } - - p++; - } - - return -1; -} - - -int TDEAccelString::maxWeight(int &index, const TQString &used) -{ - int max = 0; - index = -1; - - for (uint pos=0; pos max) - { - max = m_weight[pos]; - index = pos; - } - - return max; -} - - -void TDEAccelString::dump() -{ - TQString s; - for (uint i=0; imax) - { - max = m; - index = i; - accel = a; - } - } - - // stop if no more accelerators can be found - if (index < 0) - return; - - // insert the accelerator - if (accel >= 0) - { - result[index].setAccel(accel); - used.append(result[index].accelerator()); - } - - // make sure we don't visit this one again - accel_strings[index] = TDEAccelString(); - } -} - - -/********************************************************************* - - class TDEPopupAccelManager - managing TQPopupMenu widgets dynamically - - *********************************************************************/ - -TDEPopupAccelManager::TDEPopupAccelManager(TQPopupMenu *popup) - : TQObject(popup), m_popup(popup), m_count(-1) -{ - aboutToShow(); // do one check and then connect to show - connect(popup, TQT_SIGNAL(aboutToShow()), TQT_SLOT(aboutToShow())); -} - - -void TDEPopupAccelManager::aboutToShow() -{ - // Note: we try to be smart and avoid recalculating the accelerators - // whenever possible. Unfortunately, there is no way to know if an - // item has been added or removed, so we can not do much more than - // to compare the items each time the menu is shown :-( - - if (m_count != (int)m_popup->count()) - { - findMenuEntries(m_entries); - calculateAccelerators(); - m_count = m_popup->count(); - } - else - { - TDEAccelStringList entries; - findMenuEntries(entries); - if (entries != m_entries) - { - m_entries = entries; - calculateAccelerators(); - } - } -} - - -void TDEPopupAccelManager::calculateAccelerators() -{ - // find the new accelerators - TQString used; - TDEAccelManagerAlgorithm::findAccelerators(m_entries, used); - - // change the menu entries - setMenuEntries(m_entries); -} - - -void TDEPopupAccelManager::findMenuEntries(TDEAccelStringList &list) -{ - TQMenuItem *mitem; - TQString s; - - list.clear(); - - // read out the menu entries - for (uint i=0; icount(); i++) - { - mitem = m_popup->findItem(m_popup->idAt(i)); - if (mitem->isSeparator()) - continue; - - s = mitem->text(); - - // in full menus, look at entries with global accelerators last - int weight = 50; - if (s.contains('\t')) - weight = 0; - - list.append(TDEAccelString(s, weight)); - - // have a look at the popup as well, if present - if (mitem->popup()) - TDEPopupAccelManager::manage(mitem->popup()); - } -} - - -void TDEPopupAccelManager::setMenuEntries(const TDEAccelStringList &list) -{ - TQMenuItem *mitem; - - uint cnt = 0; - for (uint i=0; icount(); i++) - { - mitem = m_popup->findItem(m_popup->idAt(i)); - if (mitem->isSeparator()) - continue; - - if (TDEAcceleratorManagerPrivate::checkChange(list[cnt])) - mitem->setText(list[cnt].accelerated()); - cnt++; - } -} - - -void TDEPopupAccelManager::manage(TQPopupMenu *popup) -{ - // don't add more than one manager to a popup - if (popup->child(0, "TDEPopupAccelManager", false) == 0 ) - new TDEPopupAccelManager(popup); -} - -void QWidgetStackAccelManager::manage( TQWidgetStack *stack ) -{ - if ( stack->child( 0, "QWidgetStackAccelManager", false ) == 0 ) - new QWidgetStackAccelManager( stack ); -} - -QWidgetStackAccelManager::QWidgetStackAccelManager(TQWidgetStack *stack) - : TQObject(stack), m_stack(stack) -{ - aboutToShow(stack->visibleWidget()); // do one check and then connect to show - connect(stack, TQT_SIGNAL(aboutToShow(TQWidget *)), TQT_SLOT(aboutToShow(TQWidget *))); -} - -bool QWidgetStackAccelManager::eventFilter ( TQObject * watched, TQEvent * e ) -{ - if ( e->type() == TQEvent::Show && tqApp->activeWindow() ) { - TDEAcceleratorManager::manage( TQT_TQWIDGET(tqApp->activeWindow()) ); - watched->removeEventFilter( this ); - } - return false; -} - -void QWidgetStackAccelManager::aboutToShow(TQWidget *child) -{ - if (!child) - { - kdDebug(131) << "null pointer given to aboutToShow" << endl; - return; - } - - child->installEventFilter( this ); -} - -void TDEAcceleratorManager::setNoAccel( TQWidget *widget ) -{ - TDEAcceleratorManagerPrivate::ignored_widgets[widget] = 1; -} - -#include "kaccelmanager_private.moc" diff --git a/tdecore/kaccelmanager.h b/tdecore/kaccelmanager.h deleted file mode 100644 index 03ee627b3..000000000 --- a/tdecore/kaccelmanager.h +++ /dev/null @@ -1,88 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002 Matthias Hoelzer-Kluepfel - - This library 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. - - 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 __K_ACCELMANAGER_H__ -#define __K_ACCELMANAGER_H__ - - -class TQWidget; -class TQString; - -#include - -/** - * KDE Accelerator manager. - * - * This class can be used to find a valid and working set of - * accelerators for any widget. - * - * @author Matthias Hoelzer-Kluepfel - * @since 3.1 -*/ - -class TDECORE_EXPORT TDEAcceleratorManager -{ -public: - - /** - * Manages the accelerators of a widget. - * - * Call this function on the top widget of the hierarchy you - * want to manage. It will fix the accelerators of the child widgets so - * there are never duplicate accelerators. It also tries to put - * accelerators on as many widgets as possible. - * - * The algorithm used tries to take the existing accelerators into - * account, as well as the class of each widget. Hopefully, the result - * is close to what you would assign manually. - * - * QPopupMenu's are managed dynamically, so when you add or remove entries, - * the accelerators are reassigned. If you add or remove widgets to your - * toplevel widget, you will have to call manage again to fix the - * accelerators. - * - * @param widget The toplevel widget you want to manage. - */ - - static void manage(TQWidget *widget); - - /** - * Does the same as the above function, but puts hints in the GUI so the - * programmer can enhance his program. - * - * TODO KDE4: merge with the above - * @param widget The toplevel widget you want to manage. - * @param programmers_mode if true, TDEAcceleratorManager adds (&) for removed - * accels and & before added accels - */ - static void manage(TQWidget *widget, bool programmers_mode); - - /** \internal returns the result of the last manage operation. */ - static void last_manage(TQString &added, TQString &changed, TQString &removed); - - /** - * Use this method for a widget (and its children) you want no accels to be set on. - * @since 3.4 - */ - static void setNoAccel( TQWidget *widget ); -}; - - -#endif diff --git a/tdecore/kaccelmanager_private.h b/tdecore/kaccelmanager_private.h deleted file mode 100644 index ed401801e..000000000 --- a/tdecore/kaccelmanager_private.h +++ /dev/null @@ -1,196 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002 Matthias Hoelzer-Kluepfel - - This library 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. - - 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 __KACCELMANAGER_PRIVATE_H__ -#define __KACCELMANAGER_PRIVATE_H__ - - -#include -#include -#include -#include - -class TQWidgetStack; - -/** - * A string class handling accelerators. - * - * This class contains a string and knowledge about accelerators. - * It keeps a list weights, telling how valuable each character - * would be as an accelerator. - * - * @author Matthias Hoelzer-Kluepfel -*/ - -class TDEAccelString -{ -public: - - TDEAccelString() : m_pureText(), m_accel(-1) {} - TDEAccelString(const TQString &input, int initalWeight=-1); - - void calculateWeights(int initialWeight); - - const TQString &pure() const { return m_pureText; } - TQString accelerated() const; - - int accel() const { return m_accel; } - void setAccel(int accel) { m_accel = accel; } - - int originalAccel() const { return m_orig_accel; } - TQString originalText() const { return m_origText; } - - TQChar accelerator() const; - - int maxWeight(int &index, const TQString &used); - - bool operator == (const TDEAccelString &c) const { return m_pureText == c.m_pureText && m_accel == c.m_accel && m_orig_accel == c.m_orig_accel; } - - -private: - - int stripAccelerator(TQString &input); - - void dump(); - - TQString m_pureText, m_origText; - int m_accel, m_orig_accel; - TQMemArray m_weight; - -}; - - -typedef TQValueList TDEAccelStringList; - - -/** - * This class encapsulates the algorithm finding the 'best' - * distribution of accelerators in a hierarchy of widgets. - * - * @author Matthias Hoelzer-Kluepfel -*/ - -class TDEAccelManagerAlgorithm -{ -public: - - /// Constants used in the algorithm - enum { - /// Default control weight - DEFAULT_WEIGHT = 50, - /// Additional weight for first character in string - FIRST_CHARACTER_EXTRA_WEIGHT = 50, - /// Additional weight for the beginning of a word - WORD_BEGINNING_EXTRA_WEIGHT = 50, - /// Additional weight for the dialog buttons (large, we basically never want these reassigned) - DIALOG_BUTTON_EXTRA_WEIGHT = 300, - /// Additional weight for a 'wanted' accelerator - WANTED_ACCEL_EXTRA_WEIGHT = 150, - /// Default weight for an 'action' widget (ie, pushbuttons) - ACTION_ELEMENT_WEIGHT = 50, - /// Default weight for group boxes (low priority) - GROUP_BOX_WEIGHT = -2000, - /// Default weight for menu titles - MENU_TITLE_WEIGHT = 250, - /// Additional weight for KDE standard accelerators - STANDARD_ACCEL = 300 - }; - - /// Method to call to find the best distribution of accelerators. - static void findAccelerators(TDEAccelStringList &result, TQString &used); - -}; - - -class TQPopupMenu; - - -/** - * This class manages a popup menu. It will notice if entries have been - * added or changed, and will recalculate the accelerators accordingly. - * - * This is necessary for dynamic menus like for example in kicker. - * - * @author Matthias Hoelzer-Kluepfel -*/ - -class TDEPopupAccelManager : public TQObject -{ - Q_OBJECT - -public: - - static void manage(TQPopupMenu *popup); - - -protected: - - TDEPopupAccelManager(TQPopupMenu *popup); - - -private slots: - - void aboutToShow(); - - -private: - - void calculateAccelerators(); - - void findMenuEntries(TDEAccelStringList &list); - void setMenuEntries(const TDEAccelStringList &list); - - TQPopupMenu *m_popup; - TDEAccelStringList m_entries; - int m_count; - -}; - - -class QWidgetStackAccelManager : public TQObject -{ - Q_OBJECT - -public: - - static void manage(TQWidgetStack *popup); - - -protected: - - QWidgetStackAccelManager(TQWidgetStack *popup); - - -private slots: - - void aboutToShow(TQWidget *); - bool eventFilter ( TQObject * watched, TQEvent * e ); - -private: - - void calculateAccelerators(); - - TQWidgetStack *m_stack; - TDEAccelStringList m_entries; - -}; - - -#endif diff --git a/tdecore/kaccelprivate.h b/tdecore/kaccelprivate.h deleted file mode 100644 index 0d967998d..000000000 --- a/tdecore/kaccelprivate.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __KACCELPRIVATE_H -#define __KACCELPRIVATE_H - -#include "kkeyserver_x11.h" -#include - -class TDEAccelAction; - -/** - * @internal - */ -class TDECORE_EXPORT TDEAccelPrivate : public TQObject, public TDEAccelBase -{ - Q_OBJECT - public: - TDEAccel* m_pAccel; - TQWidget* m_pWatch; - TQMap m_mapIDToKey; - TQMap m_mapIDToAction; - TQTimer m_timerShowMenu; - - TDEAccelPrivate( TDEAccel* pParent, TQWidget* pWatch ); - - virtual void setEnabled( bool bEnabled ); - - bool setEnabled( const TQString& sAction, bool bEnable ); - - virtual bool removeAction( const TQString& sAction ); - - virtual bool emitSignal( TDEAccelBase::Signal signal ); - virtual bool connectKey( TDEAccelAction& action, const KKeyServer::Key& key ); - virtual bool connectKey( const KKeyServer::Key& key ); - virtual bool disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ); - virtual bool disconnectKey( const KKeyServer::Key& key ); - - signals: - void menuItemActivated(); - void menuItemActivated(TDEAccelAction*); - - private: -#ifndef Q_WS_WIN /** @todo TEMP: new implementation (commit #424926) didn't work */ - void emitActivatedSignal(TDEAccelAction*); -#endif - - private slots: - void slotKeyPressed( int id ); - void slotShowMenu(); - void slotMenuActivated( int iAction ); - - bool eventFilter( TQObject* pWatched, TQEvent* pEvent ); // virtual method from QObject -}; - -#endif // !__KACCELPRIVATE_H diff --git a/tdecore/kcheckaccelerators.cpp b/tdecore/kcheckaccelerators.cpp deleted file mode 100644 index ec11f50a8..000000000 --- a/tdecore/kcheckaccelerators.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) - Copyright (C) 1998, 1999, 2000 KDE Team - - This library 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. - - 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. - */ - -// $Id$ - -#define INCLUDE_MENUITEM_DEF -#include - -#include "config.h" - -#include "kcheckaccelerators.h" -#include "kaccelmanager.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -/* - - HOWTO: - - This class allows translators (and application developers) to check for accelerator - conflicts in menu and widgets. Put the following in your kdeglobals (or the config - file for the application you're testing): - - [Development] - CheckAccelerators=F12 - AutoCheckAccelerators=false - AlwaysShowCheckAccelerators=false - - The checking can be either manual or automatic. To perform manual check, press - the keyboard shortcut set to 'CheckAccelerators' (here F12). If automatic checking - is enabled by setting 'AutoCheckAccelerators' to true, check will be performed every - time the GUI changes. It's possible that in certain cases the check will be - done also when no visible changes in the GUI happen or the check won't be done - even if the GUI changed (in the latter case, use manual check ). Automatic - checks can be anytime disabled by the checkbox in the dialog presenting - the results of the check. If you set 'AlwaysShowCheckAccelerators' to true, - the dialog will be shown even if the automatic check didn't find any conflicts, - and all submenus will be shown, even those without conflicts. - - The dialog first lists the name of the window, then all results for all menus - (if the window has a menubar) and then result for all controls in the active - window (if there are any checkboxes etc.). For every submenu and all controls - there are shown all conflicts grouped by accelerator, and a list of all used - accelerators. -*/ - -KCheckAccelerators::KCheckAccelerators( TQObject* parent ) - : TQObject( parent, "kapp_accel_filter" ), key(0), block( false ), drklash(0) -{ - parent->installEventFilter( this ); - TDEConfigGroupSaver saver( TDEGlobal::config(), "Development" ); - TQString sKey = TDEGlobal::config()->readEntry( "CheckAccelerators" ).stripWhiteSpace(); - if( !sKey.isEmpty() ) { - TDEShortcut cuts( sKey ); - if( cuts.count() > 0 ) - key = int(cuts.seq(0).qt()); - } - alwaysShow = TDEGlobal::config()->readBoolEntry( "AlwaysShowCheckAccelerators", false ); - autoCheck = TDEGlobal::config()->readBoolEntry( "AutoCheckAccelerators", true ); - connect( &autoCheckTimer, TQT_SIGNAL( timeout()), TQT_SLOT( autoCheckSlot())); -} - -bool KCheckAccelerators::eventFilter( TQObject * , TQEvent * e) -{ - if ( block ) - return false; - - switch ( e->type() ) { // just simplify debuggin - case TQEvent::Accel: - if ( key && (TQT_TQKEYEVENT(e)->key() == key) ) { - block = true; - checkAccelerators( false ); - block = false; - TQT_TQKEYEVENT(e)->accept(); - return true; - } - break; - case TQEvent::ChildInserted: - case TQEvent::ChildRemoved: - case TQEvent::Resize: - case TQEvent::LayoutHint: - case TQEvent::WindowActivate: - case TQEvent::WindowDeactivate: - if( autoCheck ) - autoCheckTimer.start( 20, true ); // 20 ms - break; - case TQEvent::Timer: - case TQEvent::MouseMove: - case TQEvent::Paint: - return false; - default: - // kdDebug(125) << "KCheckAccelerators::eventFilter " << e->type() << " " << autoCheck << endl; - break; - } - return false; -} - -void KCheckAccelerators::autoCheckSlot() -{ - if( block ) - { - autoCheckTimer.start( 20, true ); - return; - } - block = true; - checkAccelerators( !alwaysShow ); - block = false; -} - -void KCheckAccelerators::createDialog(TQWidget *actWin, bool automatic) -{ - if ( drklash ) - return; - - drklash = new TQDialog( actWin, "kapp_accel_check_dlg", false, (WFlags)TQt::WDestructiveClose); - drklash->setCaption( i18n( "Dr. Klash' Accelerator Diagnosis" )); - drklash->resize( 500, 460 ); - TQVBoxLayout* layout = new TQVBoxLayout( drklash, 11, 6 ); - layout->setAutoAdd( true ); - drklash_view = new TQTextView( drklash ); - TQCheckBox* disableAutoCheck = NULL; - if( automatic ) { - disableAutoCheck = new TQCheckBox( i18n( "&Disable automatic checking" ), drklash ); - connect(disableAutoCheck, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotDisableCheck(bool))); - } - TQPushButton* btnClose = new TQPushButton( i18n( "&Close" ), drklash ); - btnClose->setDefault( true ); - connect( btnClose, TQT_SIGNAL( clicked() ), drklash, TQT_SLOT( close() ) ); - if (disableAutoCheck) - disableAutoCheck->setFocus(); - else - drklash_view->setFocus(); -} - -void KCheckAccelerators::slotDisableCheck(bool on) -{ - autoCheck = !on; - if (!on) - autoCheckSlot(); -} - -void KCheckAccelerators::checkAccelerators( bool automatic ) -{ - TQWidget* actWin = TQT_TQWIDGET(tqApp->activeWindow()); - if ( !actWin ) - return; - - TDEAcceleratorManager::manage(actWin); - TQString a, c, r; - TDEAcceleratorManager::last_manage(a, c, r); - - if (automatic) // for now we only show dialogs on F12 checks - return; - - if (c.isEmpty() && r.isEmpty() && (automatic || a.isEmpty())) - return; - - TQString s; - - if ( ! c.isEmpty() ) { - s += i18n("

Accelerators changed

"); - s += "" - + c + "
Old TextNew Text
"; - } - - if ( ! r.isEmpty() ) { - s += i18n("

Accelerators removed

"); - s += "" + r + "
Old Text
"; - } - - if ( ! a.isEmpty() ) { - s += i18n("

Accelerators added (just for your info)

"); - s += "" + a + "
New Text
"; - } - - createDialog(actWin, automatic); - drklash_view->setText(s); - drklash->show(); - drklash->raise(); - - // dlg will be destroyed before returning -} - -#include "kcheckaccelerators.moc" diff --git a/tdecore/kcheckaccelerators.h b/tdecore/kcheckaccelerators.h deleted file mode 100644 index 00adf4fd1..000000000 --- a/tdecore/kcheckaccelerators.h +++ /dev/null @@ -1,96 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) - Copyright (C) 1998, 1999, 2000 KDE Team - - This library 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. - - 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 KCHECKACCELERATORS_H_ -#define KCHECKACCELERATORS_H_ - -#include -#include -#include -#include -#include -#include - -class TQMenuData; -class TQTextView; - -#include "tdelibs_export.h" - -/** - @internal - This class allows translators (and application developers) to check for accelerator - conflicts in menu and widgets. Put the following in your kdeglobals (or the config - file for the application you're testing): - - \code - [Development] - CheckAccelerators=F12 - AutoCheckAccelerators=false - AlwaysShowCheckAccelerators=false - \endcode - - The checking can be either manual or automatic. To perform manual check, press - the keyboard shortcut set to 'CheckAccelerators' (here F12). If automatic checking - is enabled by setting 'AutoCheckAccelerators' to true, check will be performed every - time the GUI changes. It's possible that in certain cases the check will be - done also when no visible changes in the GUI happen or the check won't be done - even if the GUI changed (in the latter case, use manual check ). Automatic - checks can be anytime disabled by the checkbox in the dialog presenting - the results of the check. If you set 'AlwaysShowCheckAccelerators' to true, - the dialog will be shown even if the automatic check didn't find any conflicts, - and all submenus will be shown, even those without conflicts. - - The dialog first lists the name of the window, then all results for all menus - (if the window has a menubar) and then result for all controls in the active - window (if there are any checkboxes etc.). For every submenu and all controls - there are shown all conflicts grouped by accelerator, and a list of all used - accelerators. -*/ -class TDECORE_EXPORT KCheckAccelerators : public TQObject -{ - Q_OBJECT -public: - /** - * Creates a KCheckAccelerators instance for the given object. - * @param parent the parent to check - */ - KCheckAccelerators( TQObject* parent ); - /** - * Re-implemented to filter the parent's events. - */ - bool eventFilter( TQObject * , TQEvent * e); - -private: - void checkAccelerators( bool automatic ); - int key; - bool alwaysShow; - bool autoCheck; - bool block; - TQTimer autoCheckTimer; - void createDialog(TQWidget *parent, bool automatic); - TQGuardedPtr drklash; - TQTextView *drklash_view; - -private slots: - void autoCheckSlot(); - void slotDisableCheck(bool); -}; - -#endif diff --git a/tdecore/kchectdeaccelerators.cpp b/tdecore/kchectdeaccelerators.cpp new file mode 100644 index 000000000..ec11f50a8 --- /dev/null +++ b/tdecore/kchectdeaccelerators.cpp @@ -0,0 +1,216 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) + Copyright (C) 1998, 1999, 2000 KDE Team + + This library 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. + + 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. + */ + +// $Id$ + +#define INCLUDE_MENUITEM_DEF +#include + +#include "config.h" + +#include "kcheckaccelerators.h" +#include "kaccelmanager.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +/* + + HOWTO: + + This class allows translators (and application developers) to check for accelerator + conflicts in menu and widgets. Put the following in your kdeglobals (or the config + file for the application you're testing): + + [Development] + CheckAccelerators=F12 + AutoCheckAccelerators=false + AlwaysShowCheckAccelerators=false + + The checking can be either manual or automatic. To perform manual check, press + the keyboard shortcut set to 'CheckAccelerators' (here F12). If automatic checking + is enabled by setting 'AutoCheckAccelerators' to true, check will be performed every + time the GUI changes. It's possible that in certain cases the check will be + done also when no visible changes in the GUI happen or the check won't be done + even if the GUI changed (in the latter case, use manual check ). Automatic + checks can be anytime disabled by the checkbox in the dialog presenting + the results of the check. If you set 'AlwaysShowCheckAccelerators' to true, + the dialog will be shown even if the automatic check didn't find any conflicts, + and all submenus will be shown, even those without conflicts. + + The dialog first lists the name of the window, then all results for all menus + (if the window has a menubar) and then result for all controls in the active + window (if there are any checkboxes etc.). For every submenu and all controls + there are shown all conflicts grouped by accelerator, and a list of all used + accelerators. +*/ + +KCheckAccelerators::KCheckAccelerators( TQObject* parent ) + : TQObject( parent, "kapp_accel_filter" ), key(0), block( false ), drklash(0) +{ + parent->installEventFilter( this ); + TDEConfigGroupSaver saver( TDEGlobal::config(), "Development" ); + TQString sKey = TDEGlobal::config()->readEntry( "CheckAccelerators" ).stripWhiteSpace(); + if( !sKey.isEmpty() ) { + TDEShortcut cuts( sKey ); + if( cuts.count() > 0 ) + key = int(cuts.seq(0).qt()); + } + alwaysShow = TDEGlobal::config()->readBoolEntry( "AlwaysShowCheckAccelerators", false ); + autoCheck = TDEGlobal::config()->readBoolEntry( "AutoCheckAccelerators", true ); + connect( &autoCheckTimer, TQT_SIGNAL( timeout()), TQT_SLOT( autoCheckSlot())); +} + +bool KCheckAccelerators::eventFilter( TQObject * , TQEvent * e) +{ + if ( block ) + return false; + + switch ( e->type() ) { // just simplify debuggin + case TQEvent::Accel: + if ( key && (TQT_TQKEYEVENT(e)->key() == key) ) { + block = true; + checkAccelerators( false ); + block = false; + TQT_TQKEYEVENT(e)->accept(); + return true; + } + break; + case TQEvent::ChildInserted: + case TQEvent::ChildRemoved: + case TQEvent::Resize: + case TQEvent::LayoutHint: + case TQEvent::WindowActivate: + case TQEvent::WindowDeactivate: + if( autoCheck ) + autoCheckTimer.start( 20, true ); // 20 ms + break; + case TQEvent::Timer: + case TQEvent::MouseMove: + case TQEvent::Paint: + return false; + default: + // kdDebug(125) << "KCheckAccelerators::eventFilter " << e->type() << " " << autoCheck << endl; + break; + } + return false; +} + +void KCheckAccelerators::autoCheckSlot() +{ + if( block ) + { + autoCheckTimer.start( 20, true ); + return; + } + block = true; + checkAccelerators( !alwaysShow ); + block = false; +} + +void KCheckAccelerators::createDialog(TQWidget *actWin, bool automatic) +{ + if ( drklash ) + return; + + drklash = new TQDialog( actWin, "kapp_accel_check_dlg", false, (WFlags)TQt::WDestructiveClose); + drklash->setCaption( i18n( "Dr. Klash' Accelerator Diagnosis" )); + drklash->resize( 500, 460 ); + TQVBoxLayout* layout = new TQVBoxLayout( drklash, 11, 6 ); + layout->setAutoAdd( true ); + drklash_view = new TQTextView( drklash ); + TQCheckBox* disableAutoCheck = NULL; + if( automatic ) { + disableAutoCheck = new TQCheckBox( i18n( "&Disable automatic checking" ), drklash ); + connect(disableAutoCheck, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotDisableCheck(bool))); + } + TQPushButton* btnClose = new TQPushButton( i18n( "&Close" ), drklash ); + btnClose->setDefault( true ); + connect( btnClose, TQT_SIGNAL( clicked() ), drklash, TQT_SLOT( close() ) ); + if (disableAutoCheck) + disableAutoCheck->setFocus(); + else + drklash_view->setFocus(); +} + +void KCheckAccelerators::slotDisableCheck(bool on) +{ + autoCheck = !on; + if (!on) + autoCheckSlot(); +} + +void KCheckAccelerators::checkAccelerators( bool automatic ) +{ + TQWidget* actWin = TQT_TQWIDGET(tqApp->activeWindow()); + if ( !actWin ) + return; + + TDEAcceleratorManager::manage(actWin); + TQString a, c, r; + TDEAcceleratorManager::last_manage(a, c, r); + + if (automatic) // for now we only show dialogs on F12 checks + return; + + if (c.isEmpty() && r.isEmpty() && (automatic || a.isEmpty())) + return; + + TQString s; + + if ( ! c.isEmpty() ) { + s += i18n("

Accelerators changed

"); + s += "" + + c + "
Old TextNew Text
"; + } + + if ( ! r.isEmpty() ) { + s += i18n("

Accelerators removed

"); + s += "" + r + "
Old Text
"; + } + + if ( ! a.isEmpty() ) { + s += i18n("

Accelerators added (just for your info)

"); + s += "" + a + "
New Text
"; + } + + createDialog(actWin, automatic); + drklash_view->setText(s); + drklash->show(); + drklash->raise(); + + // dlg will be destroyed before returning +} + +#include "kcheckaccelerators.moc" diff --git a/tdecore/kchectdeaccelerators.h b/tdecore/kchectdeaccelerators.h new file mode 100644 index 000000000..00adf4fd1 --- /dev/null +++ b/tdecore/kchectdeaccelerators.h @@ -0,0 +1,96 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) + Copyright (C) 1998, 1999, 2000 KDE Team + + This library 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. + + 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 KCHECKACCELERATORS_H_ +#define KCHECKACCELERATORS_H_ + +#include +#include +#include +#include +#include +#include + +class TQMenuData; +class TQTextView; + +#include "tdelibs_export.h" + +/** + @internal + This class allows translators (and application developers) to check for accelerator + conflicts in menu and widgets. Put the following in your kdeglobals (or the config + file for the application you're testing): + + \code + [Development] + CheckAccelerators=F12 + AutoCheckAccelerators=false + AlwaysShowCheckAccelerators=false + \endcode + + The checking can be either manual or automatic. To perform manual check, press + the keyboard shortcut set to 'CheckAccelerators' (here F12). If automatic checking + is enabled by setting 'AutoCheckAccelerators' to true, check will be performed every + time the GUI changes. It's possible that in certain cases the check will be + done also when no visible changes in the GUI happen or the check won't be done + even if the GUI changed (in the latter case, use manual check ). Automatic + checks can be anytime disabled by the checkbox in the dialog presenting + the results of the check. If you set 'AlwaysShowCheckAccelerators' to true, + the dialog will be shown even if the automatic check didn't find any conflicts, + and all submenus will be shown, even those without conflicts. + + The dialog first lists the name of the window, then all results for all menus + (if the window has a menubar) and then result for all controls in the active + window (if there are any checkboxes etc.). For every submenu and all controls + there are shown all conflicts grouped by accelerator, and a list of all used + accelerators. +*/ +class TDECORE_EXPORT KCheckAccelerators : public TQObject +{ + Q_OBJECT +public: + /** + * Creates a KCheckAccelerators instance for the given object. + * @param parent the parent to check + */ + KCheckAccelerators( TQObject* parent ); + /** + * Re-implemented to filter the parent's events. + */ + bool eventFilter( TQObject * , TQEvent * e); + +private: + void checkAccelerators( bool automatic ); + int key; + bool alwaysShow; + bool autoCheck; + bool block; + TQTimer autoCheckTimer; + void createDialog(TQWidget *parent, bool automatic); + TQGuardedPtr drklash; + TQTextView *drklash_view; + +private slots: + void autoCheckSlot(); + void slotDisableCheck(bool); +}; + +#endif diff --git a/tdecore/kshortcut.cpp b/tdecore/kshortcut.cpp deleted file mode 100644 index ae568d5b7..000000000 --- a/tdecore/kshortcut.cpp +++ /dev/null @@ -1,671 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001,2002 Ellis Whitehead - - This library 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. - - 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. -*/ - -#include "kshortcut.h" -#include "kkeynative.h" -#include "kkeyserver.h" - -#include -#include - -#include -#include -#include -#include - -//---------------------------------------------------- - -static KKey* g_pspec = 0; -static KKeySequence* g_pseq = 0; -static TDEShortcut* g_pcut = 0; - -//---------------------------------------------------- -// KKey -//---------------------------------------------------- - -KKey::KKey() { clear(); } -KKey::KKey( uint key, uint modFlags ) { init( key, modFlags ); } -KKey::KKey( int keyQt ) { init( keyQt ); } -KKey::KKey( const TQKeySequence& seq ) { init( seq ); } -KKey::KKey( const TQKeyEvent* pEvent ) { init( pEvent ); } -KKey::KKey( const KKey& key ) { init( key ); } -KKey::KKey( const TQString& sKey ) { init( sKey ); } - -KKey::~KKey() -{ -} - -void KKey::clear() -{ - m_sym = 0; - m_mod = 0; -} - -bool KKey::init( uint key, uint modFlags ) -{ - m_sym = key; - m_mod = modFlags; - return true; -} - -bool KKey::init( int keyQt ) -{ - //KKeyServer::Sym sym; - - //if( sym.initQt( keyQt ) - if( KKeyServer::keyQtToSym( keyQt, m_sym ) - && KKeyServer::keyQtToMod( keyQt, m_mod ) ) - return true; - else { - m_sym = 0; - m_mod = 0; - return false; - } -} - -bool KKey::init( const TQKeySequence& key ) -{ - // TODO: if key.count() > 1, should we return failure? - return init( (int) key ); -} - -bool KKey::init( const TQKeyEvent* pEvent ) -{ - int keyQt = pEvent->key(); - if( pEvent->state() & TQt::ShiftButton ) keyQt |= Qt::SHIFT; - if( pEvent->state() & TQt::ControlButton ) keyQt |= Qt::CTRL; - if( pEvent->state() & TQt::AltButton ) keyQt |= Qt::ALT; - if( pEvent->state() & TQt::MetaButton ) keyQt |= Qt::META; - return init( keyQt ); -} - -bool KKey::init( const KKey& key ) -{ - m_sym = key.m_sym; - m_mod = key.m_mod; - return true; -} - -bool KKey::init( const TQString& sSpec ) -{ - clear(); - - TQString sKey = sSpec.stripWhiteSpace(); - if( sKey.startsWith( "default(" ) && sKey.endsWith( ")" ) ) - sKey = sKey.mid( 8, sKey.length() - 9 ); - // i.e., "Ctrl++" = "Ctrl+Plus" - if( sKey.endsWith( "++" ) ) - sKey = sKey.left( sKey.length() - 1 ) + "plus"; - TQStringList rgs = TQStringList::split( '+', sKey, true ); - - uint i; - // Check for modifier keys first. - for( i = 0; i < rgs.size(); i++ ) { - TQString s = rgs[i].lower(); - if( s == "shift" ) m_mod |= KKey::SHIFT; - else if( s == "ctrl" ) m_mod |= KKey::CTRL; - else if( s == "alt" ) m_mod |= KKey::ALT; - else if( s == "win" ) m_mod |= KKey::WIN; - else if( s == "meta" ) m_mod |= KKey::WIN; - else { - uint m = KKeyServer::stringUserToMod( s ); - if( m != 0 ) m_mod |= m; - else break; - } - } - // If there is one non-blank key left: - if( (i == rgs.size() - 1 && !rgs[i].isEmpty()) ) { - KKeyServer::Sym sym( rgs[i] ); - m_sym = sym.m_sym; - } - - if( m_sym == 0 ) - m_mod = 0; - - kdDebug(125) << "KKey::init( \"" << sSpec << "\" ):" - << " m_sym = " << TQString::number(m_sym, 16) - << ", m_mod = " << TQString::number(m_mod, 16) << endl; - - return m_sym != 0; -} - -bool KKey::isNull() const { return m_sym == 0; } -uint KKey::sym() const { return m_sym; } -uint KKey::modFlags() const { return m_mod; } - -int KKey::compare( const KKey& spec ) const -{ - if( m_sym != spec.m_sym ) - return m_sym - spec.m_sym; - if( m_mod != spec.m_mod ) - return m_mod - spec.m_mod; - return 0; -} - -int KKey::keyCodeQt() const -{ - return KKeyNative( *this ).keyCodeQt(); -} - -TQString KKey::toString() const -{ - TQString s; - - s = KKeyServer::modToStringUser( m_mod ); - if( !s.isEmpty() ) - s += '+'; - s += KKeyServer::Sym(m_sym).toString(); - - return s; -} - -TQString KKey::toStringInternal() const -{ - //kdDebug(125) << "KKey::toStringInternal(): this = " << this - // << " mod = " << TQString::number(m_mod, 16) - // << " key = " << TQString::number(m_sym, 16) << endl; - TQString s; - - s = KKeyServer::modToStringInternal( m_mod ); - if( !s.isEmpty() ) - s += '+'; - s += KKeyServer::Sym(m_sym).toStringInternal(); - return s; -} - -KKey& KKey::null() -{ - if( !g_pspec ) - g_pspec = new KKey; - if( !g_pspec->isNull() ) - g_pspec->clear(); - return *g_pspec; -} - -TQString KKey::modFlagLabel( ModFlag modFlag ) -{ - return KKeyServer::modToStringUser( modFlag ); -} - -//--------------------------------------------------------------------- -// KKeySequence -//--------------------------------------------------------------------- - -KKeySequence::KKeySequence() { clear(); } -KKeySequence::KKeySequence( const TQKeySequence& seq ) { init( seq ); } -KKeySequence::KKeySequence( const KKey& key ) { init( key ); } -KKeySequence::KKeySequence( const KKeySequence& seq ) { init( seq ); } -KKeySequence::KKeySequence( const TQString& s ) { init( s ); } - -KKeySequence::~KKeySequence() -{ -} - -void KKeySequence::clear() -{ - m_nKeys = 0; - m_bTriggerOnRelease = false; -} - -bool KKeySequence::init( const TQKeySequence& seq ) -{ - clear(); - if( !seq.isEmpty() ) { - for( uint i = 0; i < seq.count(); i++ ) { - m_rgvar[i].init( seq[i] ); - if( m_rgvar[i].isNull() ) - return false; - } - m_nKeys = seq.count(); - m_bTriggerOnRelease = false; - } - return true; -} - -bool KKeySequence::init( const KKey& key ) -{ - if( !key.isNull() ) { - m_nKeys = 1; - m_rgvar[0].init( key ); - m_bTriggerOnRelease = false; - } else - clear(); - return true; -} - -bool KKeySequence::init( const KKeySequence& seq ) -{ - m_bTriggerOnRelease = false; - m_nKeys = seq.m_nKeys; - for( uint i = 0; i < m_nKeys; i++ ) { - if( seq.m_rgvar[i].isNull() ) { - kdDebug(125) << "KKeySequence::init( seq ): key[" << i << "] is null." << endl; - m_nKeys = 0; - return false; - } - m_rgvar[i] = seq.m_rgvar[i]; - } - return true; -} - -bool KKeySequence::init( const TQString& s ) -{ - m_bTriggerOnRelease = false; - //kdDebug(125) << "KKeySequence::init( " << s << " )" << endl; - TQStringList rgs = TQStringList::split( ',', s ); - if( s == "none" || rgs.size() == 0 ) { - clear(); - return true; - } else if( rgs.size() <= MAX_KEYS ) { - m_nKeys = rgs.size(); - for( uint i = 0; i < m_nKeys; i++ ) { - m_rgvar[i].init( KKey(rgs[i]) ); - //kdDebug(125) << "\t'" << rgs[i] << "' => " << m_rgvar[i].toStringInternal() << endl; - } - return true; - } else { - clear(); - return false; - } -} - -uint KKeySequence::count() const -{ - return m_nKeys; -} - -const KKey& KKeySequence::key( uint i ) const -{ - if( i < m_nKeys ) - return m_rgvar[i]; - else - return KKey::null(); -} - -bool KKeySequence::isTriggerOnRelease() const - { return m_bTriggerOnRelease; } - -bool KKeySequence::setKey( uint iKey, const KKey& key ) -{ - if( iKey <= m_nKeys && iKey < MAX_KEYS ) { - m_rgvar[iKey].init( key ); - if( iKey == m_nKeys ) - m_nKeys++; - return true; - } else - return false; -} - -bool KKeySequence::isNull() const -{ - return m_nKeys == 0; -} - -bool KKeySequence::startsWith( const KKeySequence& seq ) const -{ - if( m_nKeys < seq.m_nKeys ) - return false; - - for( uint i = 0; i < seq.m_nKeys; i++ ) { - if( m_rgvar[i] != seq.m_rgvar[i] ) - return false; - } - - return true; -} - -int KKeySequence::compare( const KKeySequence& seq ) const -{ - for( uint i = 0; i < m_nKeys && i < seq.m_nKeys; i++ ) { - int ret = m_rgvar[i].compare( seq.m_rgvar[i] ); - if( ret != 0 ) - return ret; - } - if( m_nKeys != seq.m_nKeys ) - return m_nKeys - seq.m_nKeys; - else - return 0; -} - -TQKeySequence KKeySequence::qt() const -{ - int k[4] = { 0, 0, 0, 0 }; - - for( uint i = 0; i < count(); i++ ) - k[i] = KKeyNative(key(i)).keyCodeQt(); - TQKeySequence seq( k[0], k[1], k[2], k[3] ); - return seq; -} - -int KKeySequence::keyCodeQt() const -{ - return (count() == 1) ? KKeyNative(key(0)).keyCodeQt() : 0; -} - -TQString KKeySequence::toString() const -{ - if( m_nKeys < 1 ) return TQString::null; - - TQString s; - s = m_rgvar[0].toString(); - for( uint i = 1; i < m_nKeys; i++ ) { - s += ","; - s += m_rgvar[i].toString(); - } - - return s; -} - -TQString KKeySequence::toStringInternal() const -{ - if( m_nKeys < 1 ) return TQString::null; - - TQString s; - s = m_rgvar[0].toStringInternal(); - for( uint i = 1; i < m_nKeys; i++ ) { - s += ","; - s += m_rgvar[i].toStringInternal(); - } - - return s; -} - -KKeySequence& KKeySequence::null() -{ - if( !g_pseq ) - g_pseq = new KKeySequence; - if( !g_pseq->isNull() ) - g_pseq->clear(); - return *g_pseq; -} - -//--------------------------------------------------------------------- -// TDEShortcut -//--------------------------------------------------------------------- - -TDEShortcut::TDEShortcut() { clear(); } -TDEShortcut::TDEShortcut( int keyQt ) { init( keyQt ); } -TDEShortcut::TDEShortcut( const TQKeySequence& key ) { init( key ); } -TDEShortcut::TDEShortcut( const KKey& key ) { init( key ); } -TDEShortcut::TDEShortcut( const KKeySequence& seq ) { init( seq ); } -TDEShortcut::TDEShortcut( const TDEShortcut& cut ) { init( cut ); } -TDEShortcut::TDEShortcut( const char* ps ) { init( TQString(ps) ); } -TDEShortcut::TDEShortcut( const TQString& s ) { init( s ); } - -TDEShortcut::~TDEShortcut() -{ -} - -void TDEShortcut::clear() -{ - m_nSeqs = 0; -} - -bool TDEShortcut::init( int keyQt ) -{ - if( keyQt ) { - m_nSeqs = 1; - m_rgseq[0].init( TQKeySequence(keyQt) ); - } else - clear(); - return true; -} - -bool TDEShortcut::init( const TQKeySequence& key ) -{ - m_nSeqs = 1; - m_rgseq[0].init( key ); - return true; -} - -bool TDEShortcut::init( const KKey& spec ) -{ - m_nSeqs = 1; - m_rgseq[0].init( spec ); - return true; -} - -bool TDEShortcut::init( const KKeySequence& seq ) -{ - m_nSeqs = 1; - m_rgseq[0] = seq; - return true; -} - -bool TDEShortcut::init( const TDEShortcut& cut ) -{ - m_nSeqs = cut.m_nSeqs; - for( uint i = 0; i < m_nSeqs; i++ ) - m_rgseq[i] = cut.m_rgseq[i]; - return true; -} - -bool TDEShortcut::init( const TQString& s ) -{ - bool bRet = true; - TQStringList rgs = TQStringList::split( ';', s ); - - if( s == "none" || rgs.size() == 0 ) - clear(); - else if( rgs.size() <= MAX_SEQUENCES ) { - m_nSeqs = rgs.size(); - for( uint i = 0; i < m_nSeqs; i++ ) { - TQString& sSeq = rgs[i]; - if( sSeq.startsWith( "default(" ) ) - sSeq = sSeq.mid( 8, sSeq.length() - 9 ); - m_rgseq[i].init( sSeq ); - //kdDebug(125) << "*\t'" << sSeq << "' => " << m_rgseq[i].toStringInternal() << endl; - } - } else { - clear(); - bRet = false; - } - - if( !s.isEmpty() ) { - TQString sDebug; - TQTextStream os( &sDebug, IO_WriteOnly ); - os << "TDEShortcut::init( \"" << s << "\" ): "; - for( uint i = 0; i < m_nSeqs; i++ ) { - os << " m_rgseq[" << i << "]: "; - KKeyServer::Variations vars; - vars.init( m_rgseq[i].key(0), true ); - for( uint j = 0; j < vars.count(); j++ ) - os << TQString::number(vars.m_rgkey[j].keyCodeQt(),16) << ','; - } - kdDebug(125) << sDebug << endl; - } - - return bRet; -} - -uint TDEShortcut::count() const -{ - return m_nSeqs; -} - -const KKeySequence& TDEShortcut::seq( uint i ) const -{ - return (i < m_nSeqs) ? m_rgseq[i] : KKeySequence::null(); -} - -int TDEShortcut::keyCodeQt() const -{ - if( m_nSeqs >= 1 ) - return m_rgseq[0].keyCodeQt(); - return TQKeySequence(); -} - -bool TDEShortcut::isNull() const -{ - return m_nSeqs == 0; -} - -int TDEShortcut::compare( const TDEShortcut& cut ) const -{ - for( uint i = 0; i < m_nSeqs && i < cut.m_nSeqs; i++ ) { - int ret = m_rgseq[i].compare( cut.m_rgseq[i] ); - if( ret != 0 ) - return ret; - } - return m_nSeqs - cut.m_nSeqs; -} - -bool TDEShortcut::contains( const KKey& key ) const -{ - return contains( KKeySequence(key) ); -} - -bool TDEShortcut::contains( const KKeyNative& keyNative ) const -{ - KKey key = keyNative.key(); - key.simplify(); - - for( uint i = 0; i < count(); i++ ) { - if( !m_rgseq[i].isNull() - && m_rgseq[i].count() == 1 - && m_rgseq[i].key(0) == key ) - return true; - } - return false; -} - -bool TDEShortcut::contains( const KKeySequence& seq ) const -{ - for( uint i = 0; i < count(); i++ ) { - if( !m_rgseq[i].isNull() && m_rgseq[i] == seq ) - return true; - } - return false; -} - -bool TDEShortcut::setSeq( uint iSeq, const KKeySequence& seq ) -{ - // TODO: check if seq is null, and act accordingly. - if( iSeq <= m_nSeqs && iSeq < MAX_SEQUENCES ) { - m_rgseq[iSeq] = seq; - if( iSeq == m_nSeqs ) - m_nSeqs++; - return true; - } else - return false; -} - -void TDEShortcut::remove( const KKeySequence& seq ) -{ - if (seq.isNull()) return; - - for( uint iSeq = 0; iSeq < m_nSeqs; iSeq++ ) - { - if (m_rgseq[iSeq] == seq) - { - for( uint jSeq = iSeq + 1; jSeq < m_nSeqs; jSeq++) - m_rgseq[jSeq-1] = m_rgseq[jSeq]; - m_nSeqs--; - } - } -} - -bool TDEShortcut::append( const KKeySequence& seq ) -{ - if( m_nSeqs < MAX_SEQUENCES ) { - if( !seq.isNull() ) { - m_rgseq[m_nSeqs] = seq; - m_nSeqs++; - } - return true; - } else - return false; -} - -bool TDEShortcut::append( const KKey& spec ) -{ - if( m_nSeqs < MAX_SEQUENCES ) { - m_rgseq[m_nSeqs].init( spec ); - m_nSeqs++; - return true; - } else - return false; -} - -bool TDEShortcut::append( const TDEShortcut& cut ) -{ - uint seqs = m_nSeqs, co = cut.count(); - for( uint i=0; i MAX_SEQUENCES ) return false; - - for( uint i=0; i= 1 ) - return m_rgseq[0].qt(); - else - return TQKeySequence(); -} - -TQString TDEShortcut::toString() const -{ - TQString s; - - for( uint i = 0; i < count(); i++ ) { - s += m_rgseq[i].toString(); - if( i < count() - 1 ) - s += ';'; - } - - return s; -} - -TQString TDEShortcut::toStringInternal( const TDEShortcut* pcutDefault ) const -{ - TQString s; - - for( uint i = 0; i < count(); i++ ) { - const KKeySequence& seq = m_rgseq[i]; - if( pcutDefault && i < pcutDefault->count() && seq == (*pcutDefault).seq(i) ) { - s += "default("; - s += seq.toStringInternal(); - s += ")"; - } else - s += seq.toStringInternal(); - if( i < count() - 1 ) - s += ';'; - } - - return s; -} - -TDEShortcut& TDEShortcut::null() -{ - if( !g_pcut ) - g_pcut = new TDEShortcut; - if( !g_pcut->isNull() ) - g_pcut->clear(); - return *g_pcut; -} diff --git a/tdecore/kshortcut.h b/tdecore/kshortcut.h deleted file mode 100644 index e98a007b5..000000000 --- a/tdecore/kshortcut.h +++ /dev/null @@ -1,851 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001,2002 Ellis Whitehead - - This library 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. - - 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 __KSHORTCUT_H -#define __KSHORTCUT_H - -#include -#include -#include "tdelibs_export.h" - -class TQKeyEvent; -class KKeyNative; - -/** -* A KKey object represents a single key with possible modifiers -* (Shift, Ctrl, Alt, Win). It can represent both keys which are -* understood by Qt as well as those which are additionally supported -* by the underlying system (e.g. X11). -* @see KKeyNative -* @see KKeySequence -* @see TDEShortcut -*/ - -class TDECORE_EXPORT KKey -{ - public: - /** - * The number of flags. - * @see ModFlag - */ - enum { MOD_FLAG_COUNT = 4 }; - enum { QtWIN = (Qt::META) }; - /** - * Flags to represent the modifiers. You can combine modifiers - * by ORing them. - */ - enum ModFlag { - SHIFT = 0x01, - CTRL = 0x02, - ALT = 0x04, - WIN = 0x08 - }; - - /** - * Creates a new null KKey. - * @see clear() - * @see isNull() - * @see null() - */ - KKey(); - - /** - * Creates a new key for the given Qt key code. - * @param keyQt the qt keycode - * @see Qt::Key - */ - KKey( int keyQt ); - - /** - * Creates a new key from the first key code of the given key sequence. - * @param keySeq the key sequence that contains the key - */ - KKey( const TQKeySequence& keySeq ); - - /** - * Extracts the key from the given key event. - * @param keyEvent the key event to get the key from - */ - KKey( const TQKeyEvent* keyEvent ); - - /** - * Copy constructor. - */ - KKey( const KKey& key ); - - /** - * Creates a new key from the given description. The form of the description - * is "[modifier+[modifier+]]+key", for example "e", "CTRL+q" or - * "CTRL+ALT+DEL". Allowed modifiers are "SHIFT", "CTRL", "ALT", "WIN" and - * "META". "WIN" and "META" are equivalent. Modifiers are not case-sensitive. - * @param key the description of the key - * @see KKeyServer::Sym::init() - */ - KKey( const TQString& key ); - /** - * @internal - */ - KKey( uint key, uint mod ); - ~KKey(); - - // Initialization methods - /** - * Clears the key. The key is null after calling this function. - * @see isNull() - */ - void clear(); - - /** - * Initializes the key with the given Qt key code. - * @param keyQt the qt keycode - * @return true if successful, false otherwise - * @see Qt::Key - */ - bool init( int keyQt ); - - /** - * Initializes the key with the first key code of the given key sequence. - * @param keySeq the key sequence that contains the key - * @return true if successful, false otherwise - */ - bool init( const TQKeySequence& keySeq ); - - /** - * Initializes the key by extracting the code from the given key event. - * @param keyEvent the key event to get the key from - * @return true if successful, false otherwise - */ - bool init( const TQKeyEvent* keyEvent ); - - /** - * Copies the given key. - * @param key the key to copy - * @return true if successful, false otherwise - */ - bool init( const KKey& key ); - - /** - * Initializes the key with the given description. The form of the description - * is "[modifier+[modifier+]]+key", for example "e", "CTRL+q" or - * "CTRL+ALT+DEL". Allowed modifiers are "SHIFT", "CTRL", "ALT", "WIN" and - * "META". "WIN" and "META" are equivalent. Modifiers are not case-sensitive. - * @param key the description of the key - * @return true if successful, false otherwise - * @see KKeyServer::Sym::init() - */ - bool init( const TQString& key); - - /** - * @internal - */ - bool init( uint key, uint mod ); - - /** - * Copies the key. - */ - KKey& operator =( const KKey& key ) - { init( key ); return *this; } - - // Query methods. - /** - * Returns true if the key is null (after clear() or empty - * constructor). - * @return true if the key is null - * @see clear() - * @see null() - */ - bool isNull() const; - - /** - * @internal - */ - uint sym() const; - /** - * @internal - */ - uint modFlags() const; - - // Comparison Methods - /** - * Compares this key with the given KKey object. Returns a negative - * number if the given KKey is larger, 0 if they are equal and - * a positive number this KKey is larger. The returned value - * is the difference between the symbol or, if the symbols - * are equal, the difference between the encoded modifiers. - * @param key the key to compare with this key - * @return a negative number if the given KKey is larger, 0 if - * they are equal and a positive number this KKey is larger - */ - int compare( const KKey& key ) const; - - /** - * Compares the symbol and modifiers of both keys. - * @see compare() - */ - bool operator == ( const KKey& key ) const - { return compare( key ) == 0; } - /** - * Compares the symbol and modifiers of both keys. - * @see compare() - */ - bool operator != ( const KKey& key ) const - { return compare( key ) != 0; } - /** - * Compares the symbol and modifiers of both keys. - * @see compare() - */ - bool operator < ( const KKey& key ) const - { return compare( key ) < 0; } - - // Conversion methods. - /** - * Returns the qt key code. - * @return the qt key code or 0 if there is no key set. - * @see Qt::Key - */ - int keyCodeQt() const; - - /** - * Returns a human-readable representation of the key in the form - * "modifier+key". Note that the representation is localised, - * use toStringInternal() for cases like saving to configuration files. - * @return the string representation of the key - * @see toStringInternal() - */ - TQString toString() const; - - /** - * Returns an untranslated text representation of the key in the form - * "modifier+key", suitable e.g. for saving in configuration files. - */ - TQString toStringInternal() const; - - // Operation methods - /** - * @internal - */ - void simplify(); - - /** - * Returns a null key. - * @return the null key - * @see isNull() - * @see clear() - */ - static KKey& null(); - - /** - * Returns a user-readable representation of the given modifiers. - * @param f the modifiers to convert - * @return the string representation of the modifiers - */ - static TQString modFlagLabel( ModFlag f ); - - private: - /* - * Under X11, m_key will hold an X11 key symbol. - * For Qt/Embedded, it will hold the Qt key code. - */ - /** - * Returns the native key symbol value key. Under X11, this is the X - * keycode. Under Qt/Embedded, this is the Qt keycode. - * @see /usr/include/X11/keysymdef.h - * @see tqnamespace.h - */ - uint m_sym; - /** - * m_mod holds the - */ - uint m_mod; - - private: - friend class KKeyNative; -}; - -/** -* A KKeySequence object holds a sequence of up to 4 keys. -* Ex: Ctrl+X,I -* @see KKey -* @see TDEShortcut -*/ - -class TDECORE_EXPORT KKeySequence -{ - public: - /// Defines the maximum length of the key sequence - enum { MAX_KEYS = 4 }; - - /** - * Create a new null key sequence. - * @see isNull() - * @see null() - * @see clear() - */ - KKeySequence(); - - /** - * Copies the given qt key sequence. - * @param keySeq the qt key sequence to copy - */ - KKeySequence( const TQKeySequence& keySeq ); - - /** - * Create a new key sequence that only contains the given key. - * @param key the key to add - */ - KKeySequence( const KKey& key ); - - /** - * Create a new key sequence that only contains the given key. - * @param key the key to add - */ - KKeySequence( const KKeyNative& key ); - - /** - * Copies the given key sequence. - * @param keySeq the key sequence to copy - */ - KKeySequence( const KKeySequence& keySeq ); - - /** - * Creates a new key sequence that contains the given key sequence. - * The description consists of comma-separated keys as - * required by KKey::KKey(const TQString&). - * @param keySeq the description of the key - * @see KKeyServer::Sym::init() - * @see KKey::KKey(const TQString&) - */ - KKeySequence( const TQString& keySeq ); - - ~KKeySequence(); - - /** - * Clears the key sequence. The key sequence is null after calling this - * function. - * @see isNull() - */ - void clear(); - - /** - * Copies the given qt key sequence over this key sequence. - * @param keySeq the qt key sequence to copy - * @return true if successful, false otherwise - */ - bool init( const TQKeySequence& keySeq ); - - /** - * Initializes the key sequence to only contain the given key. - * @param key the key to set - * @return true if successful, false otherwise - */ - bool init( const KKey& key ); - - /** - * Initializes the key sequence to only contain the given key. - * @param key the key to set - * @return true if successful, false otherwise - */ - bool init( const KKeyNative& key ); - - /** - * Copies the given key sequence over this key sequence. - * @param keySeq the key sequence to copy - * @return true if successful, false otherwise - */ - bool init( const KKeySequence& keySeq ); - - /** - * Initializes this key sequence to contain the given key sequence. - * The description consists of comma-separated keys as - * required by KKey::KKey(const TQString&). - * @param key the description of the key - * @return true if successful, false otherwise - * @see KKeyServer::Sym::init() - * @see KKey::KKey(const TQString&) - */ - bool init( const TQString& key ); - - /** - * Copy the given key sequence into this sequence. - */ - KKeySequence& operator =( const KKeySequence& seq ) - { init( seq ); return *this; } - - /** - * Returns the number of key strokes of this sequence. - * @return the number of key strokes - * @see MAX_KEYS - */ - uint count() const; - - /** - * Return the @p i'th key of this sequence, or a null key if there - * are less then i keys. - * @param i the key to retrieve - * @return the @p i'th key, or KKey::null() if there are less - * than i keys - * @see MAX_KEYS - */ - const KKey& key( uint i ) const; - - /** - * @internal - */ - bool isTriggerOnRelease() const; - - /** - * Sets the @p i'th key of the sequence. You can not introduce gaps - * in a sequence, so you must use an @p i <= count(). Also note that - * the maximum length of a key sequence is MAX_KEYS. - * @param i the position of the new key (<= count(), <= MAX_KEYS) - * @param key the key to set - * @return true if successful, false otherwise - */ - bool setKey( uint i, const KKey& key ); - - /** - * Returns true if the key sequence is null (after clear() or empty - * constructor). - * @return true if the key sequence is null - * @see clear() - * @see null() - */ - bool isNull() const; - - /** - * Returns true if this key sequence begins with the given sequence. - * @param keySeq the key sequence to search - * @return true if this key sequence begins with the given sequence - */ - bool startsWith( const KKeySequence& keySeq ) const; - - /** - * Compares this object with the given key sequence. Returns a negative - * number if the given KKeySequence is larger, 0 if they are equal and - * a positive number this KKeySequence is larger. Key sequences are - * compared by comparing the individual keys, starting from the beginning - * until an unequal key has been found. If a sequence contains more - * keys, it is considered larger. - * @param keySeq the key sequence to compare to - * @return a negative number if the given KKeySequence is larger, 0 if - * they are equal and a positive number this KKeySequence is larger - * @see KKey::sequence - */ - int compare( const KKeySequence& keySeq ) const; - - /** - * Compares the keys of both sequences. - * @see compare() - */ - bool operator == ( const KKeySequence& seq ) const - { return compare( seq ) == 0; } - - /** - * Compares the keys of both sequences. - * @see compare() - */ - bool operator != ( const KKeySequence& seq ) const - { return compare( seq ) != 0; } - - /** - * Compares the keys of both sequences. - * @see compare() - */ - bool operator < ( const KKeySequence& seq ) const - { return compare( seq ) < 0; } - // TODO: consider adding Qt::SequenceMatch matches(...) methods for TQKeySequence equivalence - - /** - * Converts this key sequence to a TQKeySequence. - * @return the QKeySequence - */ - TQKeySequence qt() const; - - /** - * Returns the qt key code of the first key. - * @return the qt key code of the first key - * @see Qt::Key - * @see KKey::keyCodeQt() - */ - int keyCodeQt() const; - - /** - * Returns the key sequence as a number of key presses as - * returned by KKey::toString(), separated by commas. - * @return the string represenation of this key sequence - * @see KKey::toString() - */ - TQString toString() const; - - /** - * @internal - */ - TQString toStringInternal() const; - - /** - * Returns a null key sequence. - * @return the null key sequence - * @see isNull() - * @see clear() - */ - static KKeySequence& null(); - - protected: - uchar m_nKeys; - uchar m_bTriggerOnRelease; - // BCI: m_rgvar should be renamed to m_rgkey for KDE 4.0 - KKey m_rgvar[MAX_KEYS]; - - private: - class KKeySequencePrivate* d; - friend class KKeyNative; -}; - -/** -* The TDEShortcut class is used to represent a keyboard shortcut to an action. -* A shortcut is normally a single key with modifiers, such as Ctrl+V. -* A TDEShortcut object may also contain an alternate key which will also -* activate the action it's associated to, as long as no other actions have -* defined that key as their primary key. Ex: Ctrl+V;Shift+Insert. -* -* This can be used to add additional accelerators to a TDEAction. For example, -* the below code binds the escape key to the close action. -* -* \code -* TDEAction *closeAction = KStdAction::close( this, TQT_SLOT( close() ), actionCollection() ); -* TDEShortcut closeShortcut = closeAction->shortcut(); -* closeShortcut.append( KKey(Key_Escape)); -* closeAction->setShortcut(closeShortcut); -* \endcode -* -* Note that a shortcut cannot have more than 2 key combinations associated with it, so the above -* code would not do anything (and append() would return false) if the closeAction already had -* an key and alternate key. -* -*/ - -class TDECORE_EXPORT TDEShortcut -{ - public: - /** - * The maximum number of key sequences that can be contained in - * a TDEShortcut. - */ - enum { MAX_SEQUENCES = 2 }; - - /** - * Creates a new null shortcut. - * @see null() - * @see isNull() - * @see clear() - */ - TDEShortcut(); - - /** - * Creates a new shortcut with the given Qt key code - * as the only key sequence. - * @param keyQt the qt keycode - * @see Qt::Key - */ - TDEShortcut( int keyQt ); - - /** - * Creates a new shortcut that contains only the given qt key - * sequence. - * @param keySeq the qt key sequence to add - */ - TDEShortcut( const TQKeySequence& keySeq ); - - /** - * Creates a new shortcut that contains only the given key - * in its only sequence. - * @param key the key to add - */ - TDEShortcut( const KKey& key ); - - /** - * Creates a new shortcut that contains only the given key - * sequence. - * @param keySeq the key sequence to add - */ - TDEShortcut( const KKeySequence& keySeq ); - - /** - * Copies the given shortcut. - * @param shortcut the shortcut to add - */ - TDEShortcut( const TDEShortcut& shortcut ); - - /** - * Creates a new key sequence that contains the given key sequence. - * The description consists of semicolon-separated keys as - * used in KKeySequence::KKeySequence(const TQString&). - * @param shortcut the description of the key - * @see KKeySequence::KKeySequence(const TQString&) - */ - TDEShortcut( const char* shortcut ); - - /** - * Creates a new key sequence that contains the given key sequence. - * The description consists of semicolon-separated keys as - * used in KKeySequence::KKeySequence(const TQString&). - * @param shortcut the description of the key - * @see KKeySequence::KKeySequence(const TQString&) - */ - TDEShortcut( const TQString& shortcut ); - ~TDEShortcut(); - - /** - * Clears the shortcut. The shortcut is null after calling this - * function. - * @see isNull() - */ - void clear(); - - /** - * Initializes the shortcut with the given Qt key code - * as the only key sequence. - * @param keyQt the qt keycode - * @see Qt::Key - */ - bool init( int keyQt ); - - /** - * Initializes the shortcut with the given qt key sequence. - * @param keySeq the qt key sequence to add - */ - bool init( const TQKeySequence& keySeq ); - - /** - * Initializes the shortcut with the given key as its only sequence. - * @param key the key to add - */ - bool init( const KKey& key ); - - /** - * Initializes the shortcut with the given qt key sequence. - * @param keySeq the qt key sequence to add - */ - bool init( const KKeySequence& keySeq ); - - /** - * Copies the given shortcut. - * @param shortcut the shortcut to add - */ - bool init( const TDEShortcut& shortcut ); - - /** - * Initializes the key sequence with the given key sequence. - * The description consists of semicolon-separated keys as - * used in KKeySequence::KKeySequence(const TQString&). - * @param shortcut the description of the key - * @see KKeySequence::KKeySequence(const TQString&) - */ - bool init( const TQString& shortcut ); - - /** - * Copies the given shortcut over this shortcut. - */ - TDEShortcut& operator =( const TDEShortcut& cut ) - { init( cut ); return *this; } - - /** - * Returns the number of sequences that are in this - * shortcut. - * @return the number of sequences - * MAX_SEQUENCES - */ - uint count() const; - - /** - * Returns the @p i'th key sequence of this shortcut. - * @param i the number of the key sequence to retrieve - * @return the @p i'th sequence or KKeySequence::null() if - * there are less than @p i key sequences - * MAX_SEQUENCES - */ - const KKeySequence& seq( uint i ) const; - - /** - * Returns the key code of the first key sequence, or - * null if there is no first key sequence. - * @return the key code of the first sequence's first key - * @see Qt::Key - * @see KKeySequence::keyCodeQt() - */ - int keyCodeQt() const; - - /** - * Returns true if the shortcut is null (after clear() or empty - * constructor). - * @return true if the shortcut is null - * @see clear() - * @see null() - */ - bool isNull() const; - - /** - * Compares this object with the given shortcut. Returns a negative - * number if the given shortcut is larger, 0 if they are equal and - * a positive number this shortcut is larger. Shortcuts are - * compared by comparing the individual key sequences, starting from the - * beginning until an unequal key sequences has been found. If a shortcut - * contains more key sequences, it is considered larger. - * @param shortcut the shortcut to compare to - * @return a negative number if the given TDEShortcut is larger, 0 if - * they are equal and a positive number this TDEShortcut is larger - * @see KKey::compare() - * @see KKeyShortcut::compare() - */ - int compare( const TDEShortcut& shortcut ) const; - - /** - * Compares the sequences of both shortcuts. - * @see compare() - */ - bool operator == ( const TDEShortcut& cut ) const - { return compare( cut ) == 0; } - - /** - * Compares the sequences of both shortcuts. - * @see compare() - */ - bool operator != ( const TDEShortcut& cut ) const - { return compare( cut ) != 0; } - - /** - * Compares the sequences of both shortcuts. - * @see compare() - */ - bool operator < ( const TDEShortcut& cut ) const - { return compare( cut ) < 0; } - - /** - * Checks whether this shortcut contains a sequence that starts - * with the given key. - * @param key the key to check - * @return true if a key sequence starts with the key - */ - bool contains( const KKey& key ) const; - - /** - * Checks whether this shortcut contains a sequence that starts - * with the given key. - * @param key the key to check - * @return true if a key sequence starts with the key - */ - bool contains( const KKeyNative& key ) const; - - /** - * Checks whether this shortcut contains the given sequence. - * @param keySeq the key sequence to check - * @return true if the shortcut has the given key sequence - */ - bool contains( const KKeySequence& keySeq ) const; - - /** - * Sets the @p i 'th key sequence of the shortcut. You can not introduce - * gaps in the list of sequences, so you must use an @p i <= count(). - * Also note that the maximum number of key sequences is MAX_SEQUENCES. - * @param i the position of the new key sequence(0 <= i <= count(), 0 <= i < MAX_SEQUENCES) - * @param keySeq the key sequence to set - * @return true if successful, false otherwise - */ - bool setSeq( uint i, const KKeySequence& keySeq ); - - /** - * Appends the given key sequence. This sets it as either the keysequence or - * the alternate keysequence. If the shortcut already has MAX_SEQUENCES - * sequences then this call does nothing, and returns false. - * - * @param keySeq the key sequence to add - * @return true if successful, false otherwise - * @see setSeq() - */ - bool append( const KKeySequence& keySeq ); - - /** - * Removes the given key sequence from this shortcut - * @param keySeq the key sequence to remove - * @since 3.3 - */ - void remove( const KKeySequence& keySeq ); - - /** - * Appends the given key - * @param spec the key to add - * @return true if successful, false otherwise - * @see setSeq() - * @see MAX_SEQUENCES - * @since 3.2 - */ - bool append( const KKey& spec ); - - /** - * Appends the sequences from the given shortcut. - * @param cut the shortcut to append - * @return true if successful, false otherwise - * @see MAX_SEQUENCES - * @since 3.2 - */ - bool append( const TDEShortcut& cut ); - - /** - * Converts this shortcut to a key sequence. The first key sequence - * will be taken. - */ - operator TQKeySequence () const; - - /** - * Returns a description of the shortcut as semicolon-separated - * ket sequences, as returned by KKeySequence::toString(). - * @return the string represenation of this shortcut - * @see KKey::toString() - * @see KKeySequence::toString() - */ - TQString toString() const; - - /** - * @internal - */ - TQString toStringInternal( const TDEShortcut* pcutDefault = 0 ) const; - - /** - * Returns a null shortcut. - * @return the null shortcut - * @see isNull() - * @see clear() - */ - static TDEShortcut& null(); - - protected: - uint m_nSeqs; - KKeySequence m_rgseq[MAX_SEQUENCES]; - - private: - class TDEShortcutPrivate* d; - friend class KKeyNative; - -#ifndef KDE_NO_COMPAT - public: - operator int () const { return keyCodeQt(); } -#endif -}; - -#endif // __KSHORTCUT_H diff --git a/tdecore/kshortcutlist.cpp b/tdecore/kshortcutlist.cpp deleted file mode 100644 index d32df889d..000000000 --- a/tdecore/kshortcutlist.cpp +++ /dev/null @@ -1,220 +0,0 @@ -#include -#include - -#include -#include "kaccelaction.h" -#include -#include -#include -#include -#include -#include -#include "kshortcutlist.h" - -//--------------------------------------------------------------------- -// TDEShortcutList -//--------------------------------------------------------------------- - -TDEShortcutList::TDEShortcutList() -{ -} - -TDEShortcutList::~TDEShortcutList() -{ -} - -bool TDEShortcutList::isGlobal( uint ) const -{ - return false; -} - -int TDEShortcutList::index( const TQString& sName ) const -{ - uint nSize = count(); - for( uint i = 0; - i < nSize; - ++i ) - if( name( i ) == sName ) - return i; - return -1; -} - -int TDEShortcutList::index( const KKeySequence& seq ) const -{ - if( seq.isNull() ) - return -1; - - uint nSize = count(); - for( uint i = 0; i < nSize; i++ ) { - if( shortcut(i).contains( seq ) ) - return i; - } - - return -1; -} - -const TDEInstance* TDEShortcutList::instance() const -{ - return 0; -} - -TQVariant TDEShortcutList::getOther( Other, uint ) const -{ - return TQVariant(); -} - -bool TDEShortcutList::setOther( Other, uint, TQVariant ) -{ - return false; -} - -bool TDEShortcutList::readSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig ) -{ - kdDebug(125) << "TDEShortcutList::readSettings( \"" << sConfigGroup << "\", " << pConfig << " ) start" << endl; - if( !pConfig ) - pConfig = TDEGlobal::config(); - TQString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : TQString("Shortcuts"); - - // If the config file still has the old group name: - // FIXME: need to rename instead? -- and don't do this if hasGroup( "Shortcuts" ). - if( sGroup == "Shortcuts" && pConfig->hasGroup( "Keys" ) ) { - readSettings( "Keys", pConfig ); - } - - kdDebug(125) << "\treadSettings( \"" << sGroup << "\", " << pConfig << " )" << endl; - if( !pConfig->hasGroup( sGroup ) ) - return true; - TDEConfigGroupSaver cgs( pConfig, sGroup ); - - uint nSize = count(); - for( uint i = 0; i < nSize; i++ ) { - if( isConfigurable(i) ) { - TQString sEntry = pConfig->readEntry( name(i) ); - if( !sEntry.isEmpty() ) { - if( sEntry == "none" ) - setShortcut( i, TDEShortcut() ); - else - setShortcut( i, TDEShortcut(sEntry) ); - } - else // default shortcut - setShortcut( i, shortcutDefault(i) ); - kdDebug(125) << "\t" << name(i) << " = '" << sEntry << "'" << endl; - } - } - - kdDebug(125) << "TDEShortcutList::readSettings done" << endl; - return true; -} - -bool TDEShortcutList::writeSettings( const TQString &sConfigGroup, TDEConfigBase* pConfig, bool bWriteAll, bool bGlobal ) const -{ - kdDebug(125) << "TDEShortcutList::writeSettings( " << sConfigGroup << ", " << pConfig << ", " << bWriteAll << ", " << bGlobal << " )" << endl; - if( !pConfig ) - pConfig = TDEGlobal::config(); - - TQString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : TQString("Shortcuts"); - - // If it has the deprecated group [Keys], remove it - if( pConfig->hasGroup( "Keys" ) ) - pConfig->deleteGroup( "Keys", true ); - - TDEConfigGroupSaver cs( pConfig, sGroup ); - - uint nSize = count(); - for( uint i = 0; i < nSize; i++ ) { - if( isConfigurable(i) ) { - const TQString& sName = name(i); - bool bConfigHasAction = !pConfig->readEntry( sName ).isEmpty(); - bool bSameAsDefault = (shortcut(i) == shortcutDefault(i)); - // If we're using a global config or this setting - // differs from the default, then we want to write. - if( bWriteAll || !bSameAsDefault ) { - TQString s = shortcut(i).toStringInternal(); - if( s.isEmpty() ) - s = "none"; - kdDebug(125) << "\twriting " << sName << " = " << s << endl; - pConfig->writeEntry( sName, s, true, bGlobal ); - } - // Otherwise, this key is the same as default - // but exists in config file. Remove it. - else if( bConfigHasAction ) { - kdDebug(125) << "\tremoving " << sName << " because == default" << endl; - pConfig->deleteEntry( sName, false, bGlobal ); - } - } - } - - pConfig->sync(); - return true; -} - -//--------------------------------------------------------------------- -// TDEAccelShortcutList -//--------------------------------------------------------------------- - -class TDEAccelShortcutListPrivate -{ - public: - TQString m_configGroup; -}; - -TDEAccelShortcutList::TDEAccelShortcutList( TDEAccel* pAccel ) -: m_actions( pAccel->actions() ) -{ - d=new TDEAccelShortcutListPrivate; - m_bGlobal = false; - d->m_configGroup=pAccel->configGroup(); -} - -TDEAccelShortcutList::TDEAccelShortcutList( TDEGlobalAccel* pAccel ) -: m_actions( pAccel->actions() ) -{ - d=new TDEAccelShortcutListPrivate; - m_bGlobal = true; - d->m_configGroup=pAccel->configGroup(); -} - -TDEAccelShortcutList::TDEAccelShortcutList( TDEAccelActions& actions, bool bGlobal ) -: m_actions( actions ) -{ - d=new TDEAccelShortcutListPrivate; - m_bGlobal = bGlobal; -} - - -TDEAccelShortcutList::~TDEAccelShortcutList() - { delete d;} -uint TDEAccelShortcutList::count() const - { return m_actions.count(); } -TQString TDEAccelShortcutList::name( uint i ) const - { return m_actions.actionPtr(i)->name(); } -TQString TDEAccelShortcutList::label( uint i ) const - { return m_actions.actionPtr(i)->label(); } -TQString TDEAccelShortcutList::whatsThis( uint i ) const - { return m_actions.actionPtr(i)->whatsThis(); } -const TDEShortcut& TDEAccelShortcutList::shortcut( uint i ) const - { return m_actions.actionPtr(i)->shortcut(); } -const TDEShortcut& TDEAccelShortcutList::shortcutDefault( uint i ) const - { return m_actions.actionPtr(i)->shortcutDefault(); } -bool TDEAccelShortcutList::isConfigurable( uint i ) const - { return m_actions.actionPtr(i)->isConfigurable(); } -bool TDEAccelShortcutList::setShortcut( uint i, const TDEShortcut& cut ) - { return m_actions.actionPtr(i)->setShortcut( cut ); } -TQVariant TDEAccelShortcutList::getOther( Other, uint ) const - { return TQVariant(); } -bool TDEAccelShortcutList::isGlobal( uint ) const - { return m_bGlobal; } -bool TDEAccelShortcutList::setOther( Other, uint, TQVariant ) - { return false; } -bool TDEAccelShortcutList::save() const - { return writeSettings( d->m_configGroup ); } - -void TDEShortcutList::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -void TDEAccelShortcutList::virtual_hook( int id, void* data ) -{ TDEShortcutList::virtual_hook( id, data ); } - -void TDEStdAccel::ShortcutList::virtual_hook( int id, void* data ) -{ TDEShortcutList::virtual_hook( id, data ); } - diff --git a/tdecore/kshortcutlist.h b/tdecore/kshortcutlist.h deleted file mode 100644 index 99e83766b..000000000 --- a/tdecore/kshortcutlist.h +++ /dev/null @@ -1,295 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2002 Ellis Whitehead - - This library 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. - - 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 __KSHORTCUTLIST_H -#define __KSHORTCUTLIST_H - -#include // For uint -#include -#include "tdelibs_export.h" - -class TQVariant; -class TDEConfigBase; -class TDEInstance; -class KKeySequence; -class TDEShortcut; - -/********************************************************************** -* This is a wrapper class which allows a function to use one interface -* to TDEActionCollection, TDEAccelActions, and TDEActionPtrList. -**********************************************************************/ - -/** - * TDEShortcutList is an abstract base class for - * TDEAccelShortcutList and TDEStdAccel::ShortcutList. It gives - * you an unified interface for accessing the accelerator lists - * of TDEAccel (using TDEAccelShortcutList), - * TDEGlobalAccel (using TDEAccelShortcutList), and - * TDEStdAccel (using TDEStdAccel::ShortcutList). - * - * @short Base class for accessing accelerator lists - */ -class TDECORE_EXPORT TDEShortcutList -{ - public: - /** - * Default constructor. - */ - TDEShortcutList(); - virtual ~TDEShortcutList(); - - /** - * Returns the number of entries. - * @return the number of entries - */ - virtual uint count() const = 0; - - /** - * Returns the name of the shortcut with the given @p index. - * @param index the index of the shortcut (must be < count()) - * @return the name of the shortcut - */ - virtual TQString name( uint index ) const = 0; - - /** - * Returns the (i18n'd) label of the shortcut with the given @p index. - * @param index the index of the shortcut (must be < count()) - * @return the label (i18n'd) of the shortcut - */ - virtual TQString label( uint index ) const = 0; - - /** - * Returns the (i18n'd) What's This text of the shortcut with the given @p index. - * @param index the index of the shortcut (must be < count()) - * @return the What's This text (i18n'd) of the shortcut - */ - virtual TQString whatsThis( uint index ) const = 0; - - // TODO KDE4: add virtual TQString toolTip( uint index ) const = 0 - // Will then be used by the listview in kkeydialog - - /** - * Returns the shortcut with the given @p index. - * @param index the index of the shortcut (must be < count()) - * @return the shortcut - * @see shortcutDefault() - */ - virtual const TDEShortcut& shortcut( uint index ) const = 0; - - /** - * Returns default shortcut with the given @p index. - * @param index the index of the shortcut (must be < count()) - * @return the default shortcut - * @see shortcut() - */ - virtual const TDEShortcut& shortcutDefault( uint index ) const = 0; - - /** - * Checks whether the shortcut with the given @p index is configurable. - * @param index the index of the shortcut (must be < count()) - * @return true if configurable, false otherwise - */ - virtual bool isConfigurable( uint index ) const = 0; - - /** - * Sets the shortcut of the given entry - * @param index the index of the shortcut (must be < count()) - * @param shortcut the shortcut - */ - virtual bool setShortcut( uint index, const TDEShortcut &shortcut ) = 0; - - /** - * Checks whether the shortcut with the given @p index is saved in the - * global configuration. - * @param index the index of the shortcut (must be < count()) - * @return true if global, false otherwise - */ - virtual bool isGlobal( uint index ) const; - - /** - * Returns the index of the shortcut with he given name. - * @param sName the name of the shortcut to search - * @return the index of the shortcut, of -1 if not found - */ - virtual int index( const TQString& sName ) const; - - /** - * Returns the index of the shortcut with he given key sequence. - * @param keySeq the key sequence to search for - * @return the index of the shortcut, of -1 if not found - */ - virtual int index( const KKeySequence& keySeq ) const; - - /** - * The TDEInstance. - * @return the TDEInstance of the list, can be 0 if not available - */ - virtual const TDEInstance* instance() const; - - // These are here in order to handle expansion. - enum Other { }; - /** \internal */ - virtual TQVariant getOther( Other, uint index ) const = 0; - /** \internal */ - virtual bool setOther( Other, uint index, TQVariant ) = 0; - - /** - * Save the shortcut list. - * @return true if successful, false otherwise - */ - virtual bool save() const = 0; - - /** - * Loads the shortcuts from the given configuration file. - * - * @param sConfigGroup the group in the configuration file - * @param pConfig the configuration file to load from - * @return true if successful, false otherwise - */ - virtual bool readSettings( const TQString& sConfigGroup = TQString::null, TDEConfigBase* pConfig = 0 ); - - /** - * Writes the shortcuts to the given configuration file. - * - * @param sConfigGroup the group in the configuration file - * @param pConfig the configuration file to save to - * @param bWriteAll true to write all actions - * @param bGlobal true to write to the global configuration file - * @return true if successful, false otherwise - */ - virtual bool writeSettings( const TQString& sConfigGroup = TQString::null, TDEConfigBase* pConfig = 0, - bool bWriteAll = false, bool bGlobal = false ) const; - - protected: - /// used to extend the interface with virtuals without breaking binary compatibility - virtual void virtual_hook( int id, void* data ); - private: - class TDEShortcutListPrivate* d; -}; - -//--------------------------------------------------------------------- -// TDEAccelShortcutList -//--------------------------------------------------------------------- - -class TDEAccel; -class TDEAccelActions; -class TDEGlobalAccel; - -/** - * TDEShortcutList implementation to access TDEAccel and - * TDEGlobalAccel lists. - */ -class TDECORE_EXPORT TDEAccelShortcutList : public TDEShortcutList -{ - public: - /** - * Creates a new TDEShortcutList that accesses the given TDEAccel. - * @param accel the accelerators to access - */ - TDEAccelShortcutList( TDEAccel* accel ); - - /** - * Creates a new TDEShortcutList that accesses the given - * TDEGlobalAccel. - * @param accel the accelerators to access - */ - TDEAccelShortcutList( TDEGlobalAccel* accel ); - - /** - * @internal - * Creates a new TDEShortcutList that accesses the given - * TDEAccelActions collection. - * @param actions the actions to access - * @param bGlobal true to save the actions in the global - * configuration file - */ - TDEAccelShortcutList( TDEAccelActions &actions, bool bGlobal ); - virtual ~TDEAccelShortcutList(); - - virtual uint count() const; - virtual TQString name( uint index ) const; - virtual TQString label( uint index ) const; - virtual TQString whatsThis( uint index ) const; - virtual const TDEShortcut& shortcut( uint index ) const; - virtual const TDEShortcut& shortcutDefault( uint index ) const; - virtual bool isConfigurable( uint index ) const; - virtual bool setShortcut( uint index , const TDEShortcut& shortcut ); - virtual bool isGlobal( uint index ) const; - - /** \internal */ - virtual TQVariant getOther( Other, uint index ) const; - /** \internal */ - virtual bool setOther( Other, uint index, TQVariant ); - - virtual bool save() const; - - protected: - /** Actions (collection) for this shortcut list. Set by constructor. */ - TDEAccelActions& m_actions; - /** Is this shortcut list global? Access through isGlobal() */ - bool m_bGlobal; - - protected: - virtual void virtual_hook( int id, void* data ); - private: - class TDEAccelShortcutListPrivate* d; -}; - -namespace TDEStdAccel { -//--------------------------------------------------------------------- -// ShortcutList -//--------------------------------------------------------------------- - -/** - * TDEShortcutList implementation that accesses TDEStdAccel - * actions. - */ -class TDECORE_EXPORT ShortcutList : public TDEShortcutList -{ - public: - /** - * Creates a new ShortcutList. - */ - ShortcutList(); - virtual ~ShortcutList(); - - virtual uint count() const; - virtual TQString name( uint index ) const; - virtual TQString label( uint index ) const; - virtual TQString whatsThis( uint index ) const; - virtual const TDEShortcut& shortcut( uint index ) const; - virtual const TDEShortcut& shortcutDefault( uint index ) const; - virtual bool isConfigurable( uint index ) const; - virtual bool setShortcut( uint index , const TDEShortcut& shortcut ); - - /** \internal */ - virtual TQVariant getOther( Other, uint index ) const; - /** \internal */ - virtual bool setOther( Other, uint index, TQVariant ); - - virtual bool save() const; - - protected: - virtual void virtual_hook( int id, void* data ); - private: - class ShortcutListPrivate* d; -}; -} - -#endif // __KSHORTCUTLIST_H diff --git a/tdecore/kshortcutmenu.cpp b/tdecore/kshortcutmenu.cpp deleted file mode 100644 index be485fb7e..000000000 --- a/tdecore/kshortcutmenu.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - Copyright (c) 2002 Ellis Whitehead - - This library 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. - - 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. -*/ - -#include -#include -#include - -#include "kaccelaction.h" -#include -#include -#include "kshortcutmenu.h" -//#include - -TDEShortcutMenu::TDEShortcutMenu( TQWidget* pParent, TDEAccelActions* pActions, KKeySequence seq ) -: TQPopupMenu( pParent ), - m_pActions( pActions ), - m_seq( seq ) -{ - kdDebug() << seq.toStringInternal() << endl; - - TQFont fontTitle = TDEGlobalSettings::menuFont(); - fontTitle.setBold( true ); - - pTitle = new TQLabel( "", (TQWidget*)0 ); - pTitle->setFont( fontTitle ); - pTitle->setFrameShape( TQFrame::Panel ); - - insertItem( pTitle ); -} - -bool TDEShortcutMenu::insertAction( uint iAction, KKeySequence seq ) -{ - TDEAccelAction* pAction = m_pActions->actionPtr( iAction ); - - if( pAction ) { - insertItem( "", iAction ); - m_seqs[indexOf(iAction)] = seq; - return true; - } else - return false; -} - - -void TDEShortcutMenu::updateShortcuts() -{ - pTitle->setText( m_seq.toString() + ",..." ); - - for( uint iItem = 1; iItem < count(); iItem++ ) { - int iAction = idAt( iItem ); - if( iAction >= 0 ) { - TDEAccelAction* pAction = m_pActions->actionPtr( iAction ); - if( pAction ) { - KKeySequence seq = m_seqs[iItem]; - TQString sSeq = seq.key(m_seq.count()).toString(); - for( uint iKey = m_seq.count() + 1; iKey < seq.count(); iKey++ ) - sSeq += TQString(",") + seq.key(iKey).toString(); - - kdDebug(125) << "seq = " << seq.toStringInternal() << " sSeq = " << sSeq << endl; - changeItem( iAction, pAction->label() + "\t" + sSeq ); - } - } - } -} - -void TDEShortcutMenu::keyPressEvent( TQKeyEvent* pEvent ) -{ - kdDebug() << "keypress; " << pEvent->key() << endl; - KKey key( pEvent ); - - switch( pEvent->key() ) { - case TQ_Key_Shift: - case TQ_Key_Control: - case TQ_Key_Alt: - case TQ_Key_Meta: - case TQ_Key_Super_L: - case TQ_Key_Super_R: - case TQ_Key_Hyper_L: - case TQ_Key_Hyper_R: - break; - default: - int iItem = searchForKey( key ); - // If key not found, look for unmodified version. - if( iItem == -1 ) { - key = pEvent->key(); - iItem = searchForKey( key ); - } - - if( iItem == -1 ) { - // Let Up and Down keys navigate menu, - // And permit Enter, Return to select the item. - if( pEvent->key() == Qt::Key_Up || pEvent->key() == Qt::Key_Down || - pEvent->key() == Qt::Key_Enter || pEvent->key() == Qt::Key_Return ) - TQPopupMenu::keyPressEvent( pEvent ); - else - close(); - } - else if( iItem == 0 ) - keepItemsMatching( key ); - else - activateItemAt( iItem ); - } -} - -int TDEShortcutMenu::searchForKey( KKey key ) -{ - int iItemFound = -1; // -1 indicates no match - uint iKey = m_seq.count(); - - for( uint iItem = 1; iItem < count(); iItem++ ) { - if( m_seqs.contains( iItem ) ) { - KKey keyItem = m_seqs[iItem].key( iKey ); - //kdDebug(125) << "iItem = " << iItem << " key = " << key.toStringInternal() << " keyItem = " << keyItem.toStringInternal() << endl; - if( key == keyItem ) { - if( iItemFound == -1 ) - iItemFound = iItem; - else - return 0; // 0 indicates duplicate matches - } - } - } - - return iItemFound; -} - -void TDEShortcutMenu::keepItemsMatching( KKey key ) -{ - kdDebug(125) << "MyAccel::keepItemsMatching( " << key.toStringInternal() << " )" << endl; - - uint iKey = m_seq.count(); - m_seq.setKey( iKey, key ); - - for( uint iItem = 1; iItem < count(); iItem++ ) { - if( m_seqs.contains( iItem ) ) { - KKey keyItem = m_seqs[iItem].key( iKey ); - if( key != keyItem ) { - m_seqs.remove( iItem ); - removeItemAt( iItem-- ); - } - } - } - - updateShortcuts(); -} - -#include "kshortcutmenu.moc" diff --git a/tdecore/kshortcutmenu.h b/tdecore/kshortcutmenu.h deleted file mode 100644 index 6e01cdd95..000000000 --- a/tdecore/kshortcutmenu.h +++ /dev/null @@ -1,61 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2002 Ellis Whitehead - - This library 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. - - 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 __KSHORTCUTMENU_H -#define __KSHORTCUTMENU_H - -#include -#include - -#include "kshortcut.h" - -class TQLabel; - -class TDEAccelActions; - -/** - * @internal - */ -class TDECORE_EXPORT TDEShortcutMenu : public TQPopupMenu -{ - Q_OBJECT - public: - TDEShortcutMenu( TQWidget* pParent, TDEAccelActions* pActions, KKeySequence seq ); - - bool insertAction( uint iAction, KKeySequence seq ); - - void updateShortcuts(); - - protected: - void keyPressEvent( TQKeyEvent* pEvent ); - - private: - int searchForKey( KKey key ); - void keepItemsMatching( KKey key ); - - private: - typedef TQMap IndexToKKeySequence; - - TDEAccelActions* m_pActions; - KKeySequence m_seq; - TQLabel* pTitle; - IndexToKKeySequence m_seqs; -}; - -#endif // __KSHORTCUTMENU_H diff --git a/tdecore/kstdaccel.cpp b/tdecore/kstdaccel.cpp deleted file mode 100644 index ac1381c88..000000000 --- a/tdecore/kstdaccel.cpp +++ /dev/null @@ -1,396 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997 Stefan Taferner (taferner@alpin.or.at) - Copyright (C) 2000 Nicolas Hadacek (haadcek@kde.org) - Copyright (C) 2001,2002 Ellis Whitehead (ellis@kde.org) - - 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. -*/ -#define __KSTDACCEL_CPP_ 1 - -#include "kstdaccel.h" - -#include "kaccelaction.h" -#include "kaccelbase.h" -#include -#include -#include -#include -#include -#include - -namespace TDEStdAccel -{ - -struct TDEStdAccelInfo -{ - StdAccel id; - const char* psName; - const char* psDesc; - int cutDefault, cutDefault4, cutDefault3B, cutDefault4B; - TDEShortcut cut; - bool bInitialized; -}; - -/** Array of predefined TDEStdAccelInfo objects, which cover all - the "standard" accelerators. Each enum value from StdAccel - should appear in this table. -*/ -static TDEStdAccelInfo g_infoStdAccel[] = -{ - {AccelNone, "Group:File", I18N_NOOP("File"), 0, 0, 0, 0, TDEShortcut(), false }, - { Open, I18N_NOOP("Open"), 0, Qt::CTRL+Qt::Key_O, 0, 0, 0, TDEShortcut(), false }, - { New, I18N_NOOP("New"), 0, Qt::CTRL+Qt::Key_N, 0, 0, 0, TDEShortcut(), false }, - { Close, I18N_NOOP("Close"), 0, Qt::CTRL+Qt::Key_W, Qt::CTRL+Qt::Key_Escape, 0, Qt::CTRL+Qt::Key_W, TDEShortcut(), false }, - { Save, I18N_NOOP("Save"), 0, Qt::CTRL+Qt::Key_S, 0, 0, 0, TDEShortcut(), false }, - { Print, I18N_NOOP("Print"), 0, Qt::CTRL+Qt::Key_P, 0, 0, 0, TDEShortcut(), false }, - { Quit, I18N_NOOP("Quit"), 0, Qt::CTRL+Qt::Key_Q, 0, 0, 0, TDEShortcut(), false }, - {AccelNone, "Group:Edit", I18N_NOOP("Edit"), 0, 0, 0, 0, TDEShortcut(), false }, - { Undo, I18N_NOOP("Undo"), 0, Qt::CTRL+Qt::Key_Z, 0, 0, 0, TDEShortcut(), false }, - { Redo, I18N_NOOP("Redo"), 0, Qt::CTRL+Qt::SHIFT+Qt::Key_Z, 0, 0, 0, TDEShortcut(), false }, - { Cut, I18N_NOOP("Cut"), 0, Qt::CTRL+Qt::Key_X, 0, Qt::SHIFT+Qt::Key_Delete, 0, TDEShortcut(), false }, - { Copy, I18N_NOOP("Copy"), 0, Qt::CTRL+Qt::Key_C, 0, Qt::CTRL+Qt::Key_Insert, 0, TDEShortcut(), false }, - { Paste, I18N_NOOP("Paste"), 0, Qt::CTRL+Qt::Key_V, 0, Qt::SHIFT+Qt::Key_Insert, 0, TDEShortcut(), false }, - { PasteSelection, I18N_NOOP("Paste Selection"), 0, 0, 0, Qt::CTRL+Qt::SHIFT+Qt::Key_Insert, 0, TDEShortcut(), false }, - { SelectAll, "SelectAll", I18N_NOOP("Select All"), Qt::CTRL+Qt::Key_A, 0, 0, 0, TDEShortcut(), false }, - { Deselect, I18N_NOOP("Deselect"), 0, Qt::CTRL+Qt::SHIFT+Qt::Key_A, 0, 0, 0, TDEShortcut(), false }, - { DeleteWordBack, "DeleteWordBack", I18N_NOOP("Delete Word Backwards"), Qt::CTRL+Qt::Key_Backspace, 0, 0, 0, TDEShortcut(), false }, - { DeleteWordForward, "DeleteWordForward", I18N_NOOP("Delete Word Forward"), Qt::CTRL+Qt::Key_Delete, 0, 0, 0, TDEShortcut(), false }, - { Find, I18N_NOOP("Find"), 0, Qt::CTRL+Qt::Key_F, 0, 0, 0, TDEShortcut(), false }, - { FindNext, "FindNext", I18N_NOOP("Find Next"), Qt::Key_F3, 0, 0, 0, TDEShortcut(), false }, - { FindPrev, "FindPrev", I18N_NOOP("Find Prev"), Qt::SHIFT+Qt::Key_F3, 0, 0, 0, TDEShortcut(), false }, - { Replace, I18N_NOOP("Replace"), 0, Qt::CTRL+Qt::Key_R, 0, 0, 0, TDEShortcut(), false }, - {AccelNone, "Group:Navigation", I18N_NOOP("Navigation"), 0, 0, 0, 0, TDEShortcut(), false }, - { Home, I18N_NOOP2("Opposite to End","Home"), 0, Qt::CTRL+Qt::Key_Home, 0, Qt::Key_HomePage, 0, TDEShortcut(), false }, - { End, I18N_NOOP("End"), 0, Qt::CTRL+Qt::Key_End, 0, 0, 0, TDEShortcut(), false }, - { BeginningOfLine, "BeginningOfLine", I18N_NOOP("Beginning of Line"), Qt::Key_Home, 0, 0, 0, TDEShortcut(), false}, - { EndOfLine, "EndOfLine", I18N_NOOP("End of Line"), Qt::Key_End, 0, 0, 0, TDEShortcut(), false}, - { Prior, I18N_NOOP("Prior"), 0, TQt::Key_Prior, 0, 0, 0, TDEShortcut(), false }, - { Next, I18N_NOOP2("Opposite to Prior","Next"), 0, TQt::Key_Next, 0, 0, 0, TDEShortcut(), false }, - { GotoLine, "GotoLine", I18N_NOOP("Go to Line"), Qt::CTRL+Qt::Key_G, 0, 0, 0, TDEShortcut(), false }, - { AddBookmark, "AddBookmark", I18N_NOOP("Add Bookmark"), Qt::CTRL+Qt::Key_B, 0, 0, 0, TDEShortcut(), false }, - { ZoomIn, "ZoomIn", I18N_NOOP("Zoom In"), Qt::CTRL+Qt::Key_Plus, 0, 0, 0, TDEShortcut(), false }, - { ZoomOut, "ZoomOut", I18N_NOOP("Zoom Out"), Qt::CTRL+Qt::Key_Minus, 0, 0, 0, TDEShortcut(), false }, - { Up, I18N_NOOP("Up"), 0, Qt::ALT+Qt::Key_Up, 0, 0, 0, TDEShortcut(), false }, - { Back, I18N_NOOP("Back"), 0, Qt::ALT+Qt::Key_Left, 0, Qt::Key_Back, 0, TDEShortcut(), false }, - { Forward, I18N_NOOP("Forward"), 0, Qt::ALT+Qt::Key_Right, 0, Qt::Key_Forward, 0, TDEShortcut(), false }, - { Reload, I18N_NOOP("Reload"), 0, Qt::Key_F5, 0, Qt::Key_Refresh, 0, TDEShortcut(), false }, - { PopupMenuContext, "PopupMenuContext", I18N_NOOP("Popup Menu Context"), Qt::Key_Menu, 0, 0, 0, TDEShortcut(), false }, - { ShowMenubar, "ShowMenubar", I18N_NOOP("Show Menu Bar"), Qt::CTRL+Qt::Key_M, 0, 0, 0, TDEShortcut(), false }, - { BackwardWord, "BackwardWord", I18N_NOOP("Backward Word"), Qt::CTRL+Qt::Key_Left, 0, 0, 0, TDEShortcut(), false }, - { ForwardWord, "ForwardWord", I18N_NOOP("Forward Word"), Qt::CTRL+Qt::Key_Right, 0, 0, 0, TDEShortcut(), false }, - { TabNext, I18N_NOOP("Activate Next Tab"), 0, Qt::CTRL+Qt::Key_Period, 0, Qt::CTRL+Qt::Key_BracketRight, 0, TDEShortcut(), false }, - { TabPrev, I18N_NOOP("Activate Previous Tab"), 0, Qt::CTRL+Qt::Key_Comma, 0, Qt::CTRL+Qt::Key_BracketLeft, 0, TDEShortcut(), false }, - { FullScreen, "FullScreen", I18N_NOOP("Full Screen Mode"), Qt::CTRL+Qt::SHIFT+Qt::Key_F, 0, 0, 0, TDEShortcut(), false }, - {AccelNone, "Group:Help", I18N_NOOP("Help"), 0, 0, 0, 0, TDEShortcut(), false }, - { Help, I18N_NOOP("Help"), 0, Qt::Key_F1, 0, 0, 0, TDEShortcut(), false }, - { WhatsThis, "WhatsThis", I18N_NOOP("What's This"), Qt::SHIFT+Qt::Key_F1, 0, 0, 0, TDEShortcut(), false }, - {AccelNone, "Group:TextCompletion", I18N_NOOP("Text Completion"), 0, 0, 0, 0, TDEShortcut(), false }, - { TextCompletion, "TextCompletion", I18N_NOOP("Text Completion"), Qt::CTRL+Qt::Key_E, 0, 0, 0, TDEShortcut(), false }, - { PrevCompletion, "PrevCompletion", I18N_NOOP("Previous Completion Match"), Qt::CTRL+Qt::Key_Up, 0, 0, 0, TDEShortcut(), false }, - { NextCompletion, "NextCompletion", I18N_NOOP("Next Completion Match"), Qt::CTRL+Qt::Key_Down, 0, 0, 0, TDEShortcut(), false }, - { SubstringCompletion, "SubstringCompletion", I18N_NOOP("Substring Completion"), Qt::CTRL+Qt::Key_T, 0, 0, 0, TDEShortcut(), false }, - { RotateUp, "RotateUp", I18N_NOOP("Previous Item in List"), Qt::Key_Up, 0, 0, 0, TDEShortcut(), false }, - { RotateDown, "RotateDown", I18N_NOOP("Next Item in List"), Qt::Key_Down, 0, 0, 0, TDEShortcut(), false }, - { AccelNone, 0, 0, 0, 0, 0, 0, TDEShortcut(), false } -}; - -/** Search for the TDEStdAccelInfo object associated with the given @p id. */ -static TDEStdAccelInfo* infoPtr( StdAccel id ) -{ - if( id != AccelNone ) { - // Linear search. Changing the data structure doesn't seem possible - // (since we need groups for the config stuff), but maybe a little - // additional hashtable wouldn't hurt. - for( uint i = 0; g_infoStdAccel[i].psName != 0; i++ ) { - if( g_infoStdAccel[i].id == id ) - return &g_infoStdAccel[i]; - } - } - return 0; -} - -/** Initialize the accelerator @p id by checking if it is overridden - in the configuration file (and if it isn't, use the default). -*/ -static void initialize( StdAccel id ) -{ - TDEConfigGroupSaver saver( TDEGlobal::config(), "Shortcuts" ); - TDEStdAccelInfo* pInfo = infoPtr( id ); - - if( !pInfo ) { - kdWarning(125) << "TDEStdAccel: id not found!" << endl; // -- ellis - return; - } - - if( saver.config()->hasKey( pInfo->psName ) ) { - TQString s = saver.config()->readEntry( pInfo->psName ); - if( s != "none" ) - pInfo->cut.init( s ); - else - pInfo->cut.clear(); - } else - pInfo->cut = shortcutDefault( id ); - pInfo->bInitialized = true; -} - -TQString name( StdAccel id ) -{ - TDEStdAccelInfo* pInfo = infoPtr( id ); - if( !pInfo ) - return TQString::null; - return pInfo->psName; -} - -TQString label( StdAccel id ) -{ - TDEStdAccelInfo* pInfo = infoPtr( id ); - if( !pInfo ) - return TQString::null; - return i18n((pInfo->psDesc) ? pInfo->psDesc : pInfo->psName); -} - -// TODO: Add psWhatsThis entry to TDEStdAccelInfo -TQString whatsThis( StdAccel /*id*/ ) -{ -// TDEStdAccelInfo* pInfo = infoPtr( id ); -// if( pInfo && pInfo->psWhatsThis ) -// return i18n(pInfo->psWhatsThis); -// else - return TQString::null; -} - -const TDEShortcut& shortcut( StdAccel id ) -{ - TDEStdAccelInfo* pInfo = infoPtr( id ); - if( !pInfo ) - return TDEShortcut::null(); - - if( !pInfo->bInitialized ) - initialize( id ); - - return pInfo->cut; -} - -StdAccel findStdAccel( const KKeySequence& seq ) -{ - if( !seq.isNull() ) { - for( uint i = 0; g_infoStdAccel[i].psName != 0; i++ ) { - StdAccel id = g_infoStdAccel[i].id; - if( id != AccelNone ) { - if( !g_infoStdAccel[i].bInitialized ) - initialize( id ); - if( g_infoStdAccel[i].cut.contains( seq ) ) - return id; - } - } - } - return AccelNone; -} - -TDEShortcut shortcutDefault( StdAccel id ) -{ - return (TDEAccelAction::useFourModifierKeys()) - ? shortcutDefault4(id) : shortcutDefault3(id); -} - -TDEShortcut shortcutDefault3( StdAccel id ) -{ - TDEShortcut cut; - - TDEStdAccelInfo* pInfo = infoPtr( id ); - if( pInfo ) { - if( pInfo->cutDefault ) - cut.init( pInfo->cutDefault ); - // FIXME: if there is no cutDefault, then this we be made the primary - // instead of alternate shortcut. - if( pInfo->cutDefault3B ) - cut.append( KKey(pInfo->cutDefault3B) ); - } - - return cut; -} - -TDEShortcut shortcutDefault4( StdAccel id ) -{ - TDEShortcut cut; - - TDEStdAccelInfo* pInfo = infoPtr( id ); - if( pInfo ) { - TDEStdAccelInfo& info = *pInfo; - KKeySequence key2; - - cut.init( (info.cutDefault4) ? - TQKeySequence(info.cutDefault) : TQKeySequence(info.cutDefault4) ); - - if( info.cutDefault4B ) - key2.init( TQKeySequence(info.cutDefault4B) ); - else if( info.cutDefault3B ) - key2.init( TQKeySequence(info.cutDefault3B) ); - - if( key2.count() ) - cut.append( key2 ); - } - - return cut; -} - -#if 0 // unused -void createAccelActions( TDEAccelActions& actions ) -{ - actions.clear(); - - for( uint i = 0; g_infoStdAccel[i].psName != 0; i++ ) { - StdAccel id = g_infoStdAccel[i].id; - TDEStdAccelInfo* pInfo = &g_infoStdAccel[i]; - - if( id != AccelNone ) { - actions.insert( pInfo->psName, - i18n((pInfo->psDesc) ? pInfo->psDesc : pInfo->psName), - TQString::null, // pInfo->psWhatsThis, - shortcutDefault3(id), - shortcutDefault4(id) ); - } else - actions.insert( pInfo->psName, i18n(pInfo->psDesc) ); - } -} -#endif - -const TDEShortcut& open() { return shortcut( Open ); } -const TDEShortcut& openNew() { return shortcut( New ); } -const TDEShortcut& close() { return shortcut( Close ); } -const TDEShortcut& save() { return shortcut( Save ); } -const TDEShortcut& print() { return shortcut( Print ); } -const TDEShortcut& quit() { return shortcut( Quit ); } -const TDEShortcut& cut() { return shortcut( Cut ); } -const TDEShortcut& copy() { return shortcut( Copy ); } -const TDEShortcut& paste() { return shortcut( Paste ); } -const TDEShortcut& pasteSelection() { return shortcut( PasteSelection ); } -const TDEShortcut& deleteWordBack() { return shortcut( DeleteWordBack ); } -const TDEShortcut& deleteWordForward() { return shortcut( DeleteWordForward ); } -const TDEShortcut& undo() { return shortcut( Undo ); } -const TDEShortcut& redo() { return shortcut( Redo ); } -const TDEShortcut& find() { return shortcut( Find ); } -const TDEShortcut& findNext() { return shortcut( FindNext ); } -const TDEShortcut& findPrev() { return shortcut( FindPrev ); } -const TDEShortcut& replace() { return shortcut( Replace ); } -const TDEShortcut& home() { return shortcut( Home ); } -const TDEShortcut& end() { return shortcut( End ); } -const TDEShortcut& beginningOfLine() { return shortcut( BeginningOfLine ); } -const TDEShortcut& endOfLine() { return shortcut( EndOfLine ); } -const TDEShortcut& prior() { return shortcut( Prior ); } -const TDEShortcut& next() { return shortcut( Next ); } -const TDEShortcut& backwardWord() { return shortcut( BackwardWord ); } -const TDEShortcut& forwardWord() { return shortcut( ForwardWord ); } -const TDEShortcut& gotoLine() { return shortcut( GotoLine ); } -const TDEShortcut& addBookmark() { return shortcut( AddBookmark ); } -const TDEShortcut& tabNext() { return shortcut( TabNext ); } -const TDEShortcut& tabPrev() { return shortcut( TabPrev ); } -const TDEShortcut& fullScreen() { return shortcut( FullScreen ); } -const TDEShortcut& zoomIn() { return shortcut( ZoomIn ); } -const TDEShortcut& zoomOut() { return shortcut( ZoomOut ); } -const TDEShortcut& help() { return shortcut( Help ); } -const TDEShortcut& completion() { return shortcut( TextCompletion ); } -const TDEShortcut& prevCompletion() { return shortcut( PrevCompletion ); } -const TDEShortcut& nextCompletion() { return shortcut( NextCompletion ); } -const TDEShortcut& rotateUp() { return shortcut( RotateUp ); } -const TDEShortcut& rotateDown() { return shortcut( RotateDown ); } -const TDEShortcut& substringCompletion() { return shortcut( SubstringCompletion ); } -const TDEShortcut& popupMenuContext() { return shortcut( PopupMenuContext ); } -const TDEShortcut& whatsThis() { return shortcut( WhatsThis ); } -const TDEShortcut& reload() { return shortcut( Reload ); } -const TDEShortcut& selectAll() { return shortcut( SelectAll ); } -const TDEShortcut& up() { return shortcut( Up ); } -const TDEShortcut& back() { return shortcut( Back ); } -const TDEShortcut& forward() { return shortcut( Forward ); } -const TDEShortcut& showMenubar() { return shortcut( ShowMenubar ); } - -//--------------------------------------------------------------------- -// ShortcutList -//--------------------------------------------------------------------- - -ShortcutList::ShortcutList() - { } - -ShortcutList::~ShortcutList() - { } - -uint ShortcutList::count() const -{ - static uint g_nAccels = 0; - if( g_nAccels == 0 ) { - for( ; g_infoStdAccel[g_nAccels].psName != 0; g_nAccels++ ) - ; - } - return g_nAccels; -} - -TQString ShortcutList::name( uint i ) const - { return g_infoStdAccel[i].psName; } - -TQString ShortcutList::label( uint i ) const - { return i18n((g_infoStdAccel[i].psDesc) ? g_infoStdAccel[i].psDesc : g_infoStdAccel[i].psName); } - -TQString ShortcutList::whatsThis( uint ) const - { return TQString::null; } - -const TDEShortcut& ShortcutList::shortcut( uint i ) const -{ - if( !g_infoStdAccel[i].bInitialized ) - initialize( g_infoStdAccel[i].id ); - return g_infoStdAccel[i].cut; -} - -const TDEShortcut& ShortcutList::shortcutDefault( uint i ) const -{ - static TDEShortcut cut; - cut = TDEStdAccel::shortcutDefault( g_infoStdAccel[i].id ); - return cut; -} - -bool ShortcutList::isConfigurable( uint i ) const - { return (g_infoStdAccel[i].id != AccelNone); } - -bool ShortcutList::setShortcut( uint i, const TDEShortcut& cut ) - { g_infoStdAccel[i].cut = cut; return true; } - -TQVariant ShortcutList::getOther( Other, uint ) const - { return TQVariant(); } - -bool ShortcutList::setOther( Other, uint, TQVariant ) - { return false; } - -bool ShortcutList::save() const -{ - return writeSettings( TQString::null, 0, false, true ); -} - -TDECORE_EXPORT TQString action(StdAccel id) - { return name(id); } -TDECORE_EXPORT TQString description(StdAccel id) - { return label(id); } -TDECORE_EXPORT int key(StdAccel id) - { return shortcut(id).keyCodeQt(); } -TDECORE_EXPORT int defaultKey(StdAccel id) - { return shortcutDefault(id).keyCodeQt(); } - -TDECORE_EXPORT bool isEqual(const TQKeyEvent* ev, int keyQt) -{ - KKey key1( ev ), key2( keyQt ); - return key1 == key2; -} - -} - -#undef __KSTDACCEL_CPP_ diff --git a/tdecore/kstdaccel.h b/tdecore/kstdaccel.h deleted file mode 100644 index 580204673..000000000 --- a/tdecore/kstdaccel.h +++ /dev/null @@ -1,492 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997 Stefan Taferner (taferner@kde.org) - Copyright (C) 2000 Nicolas Hadacek (hadacek@kde.org) - Copyright (C) 2001,2002 Ellis Whitehead (ellis@kde.org) - - 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 KSTDACCEL_H -#define KSTDACCEL_H - -#include -#include -#include "tdelibs_export.h" - -class TQKeyEvent; -class TDEAccelActions; - -/** - * \namespace TDEStdAccel - * Convenient methods for access to the common accelerator keys in - * the key configuration. These are the standard keybindings that should - * be used in all KDE applications. They will be configurable, - * so do not hardcode the default behavior. - * - * If you want real configurable keybindings in your applications, - * please checkout the class TDEAccel in kaccel.h - * @see TDEAccelShortcutList - */ -namespace TDEStdAccel -{ - // Always add new std-accels to the end of this enum, never in the middle! - /** - * Defines the identifier of all standard accelerators. - */ - enum StdAccel { - AccelNone, - // File menu - Open, New, Close, Save, - // The Print item - Print, - Quit, - // Edit menu - Undo, Redo, Cut, Copy, Paste, SelectAll, Deselect, DeleteWordBack, - DeleteWordForward, Find, FindNext, FindPrev, Replace, - // Navigation - Home, End, Prior, Next, GotoLine, AddBookmark, ZoomIn, ZoomOut, - Up, Back, Forward, Reload, PopupMenuContext, ShowMenubar, - // Help menu - Help, WhatsThis, - // Text completion - TextCompletion, PrevCompletion, NextCompletion, SubstringCompletion, - RotateUp, RotateDown, - - // Tabular navigation - TabNext, ///< @since 3.2 - TabPrev, ///< @since 3.2 - - // Full screen mode - FullScreen, ///< @since 3.2 - - // Text Navigation - BackwardWord, ///< @since 3.3 - ForwardWord, ///< @since 3.3 - BeginningOfLine, ///< @since 3.3 - EndOfLine, ///< @since 3.3 - - PasteSelection ///< @since 3.4 - -#ifndef KDE_NO_COMPAT - , WhatThis = WhatsThis -#endif - }; - - /** - * Returns the keybinding for @p accel. - * @param id the id of the accelerator - */ - TDECORE_EXPORT const TDEShortcut& shortcut(StdAccel id); - - /** - * Returns a unique name for the given accel. - * @param id the id of the accelerator - * @return the unique name of the accelerator - */ - TDECORE_EXPORT TQString name(StdAccel id); - - /** - * Returns a localized label for user-visible display. - * @param id the id of the accelerator - * @return a localized label for the accelerator - */ - TDECORE_EXPORT TQString label(StdAccel id); - - /** - * Returns an extended WhatsThis description for the given accelerator. - * @param id the id of the accelerator - * @return a localized description of the accelerator - */ - TDECORE_EXPORT TQString whatsThis(StdAccel id); - - /** - * Return the StdAccel id of the standard accel action which - * uses this key sequence, or AccelNone if none of them do. - * This is used by class KKeyChooser. - * @param keySeq the key sequence to search - * @return the id of the standard accelerator, or AccelNone if there - * is none - */ - TDECORE_EXPORT StdAccel findStdAccel( const KKeySequence &keySeq ); - - /** - * Returns the hardcoded default shortcut for @p id. - * This does not take into account the user's configuration. - * @param id the id of the accelerator - * @return the default shortcut of the accelerator - */ - TDECORE_EXPORT TDEShortcut shortcutDefault(StdAccel id); - /** - * Returns the hardcoded default 3 modifier shortcut for @p id. - * This does not take into account the user's configuration. - * @param id the id of the accelerator - * @return the default 3 modifier shortcut - */ - TDECORE_EXPORT TDEShortcut shortcutDefault3(StdAccel id); - /** - * Returns the hardcoded default 4 modifier shortcut for @p id. - * This does not take into account the user's configuration. - * @param id the id of the accelerator - * @return the default 4 modifier shortcut - */ - TDECORE_EXPORT TDEShortcut shortcutDefault4(StdAccel id); - - /** - * Open file. Default: Ctrl-o - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& open(); - - /** - * Create a new document (or whatever). Default: Ctrl-n - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& openNew(); - - /** - * Close current document. Default: Ctrl-w - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& close(); - - /** - * Save current document. Default: Ctrl-s - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& save(); - - /** - * Print current document. Default: Ctrl-p - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& print(); - - /** - * Quit the program. Default: Ctrl-q - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& quit(); - - /** - * Undo last operation. Default: Ctrl-z - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& undo(); - - /** - * Redo. Default: Shift-Ctrl-z - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& redo(); - - /** - * Cut selected area and store it in the clipboard. Default: Ctrl-x - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& cut(); - - /** - * Copy selected area into the clipboard. Default: Ctrl-c - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& copy(); - - /** - * Paste contents of clipboard at mouse/cursor position. Default: Ctrl-v - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& paste(); - - /** - * Paste the selection at mouse/cursor position. Default: Ctrl-Shift-Insert - * @return the shortcut of the standard accelerator - * @since 3.4 - */ - TDECORE_EXPORT const TDEShortcut& pasteSelection(); - - /** - * Reload. Default: Ctrl-A - * @return the shortcut of the standard accelerator - **/ - TDECORE_EXPORT const TDEShortcut& selectAll(); - - /** - * Delete a word back from mouse/cursor position. Default: Ctrl-Backspace - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& deleteWordBack(); - - /** - * Delete a word forward from mouse/cursor position. Default: Ctrl-Delete - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& deleteWordForward(); - - /** - * Find, search. Default: Ctrl-f - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& find(); - - /** - * Find/search next. Default: F3 - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& findNext(); - - /** - * Find/search previous. Default: Shift-F3 - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& findPrev(); - - /** - * Find and replace matches. Default: Ctrl-r - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& replace(); - - /** - * Zoom in. Default: Ctrl-Plus - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& zoomIn(); - - /** - * Zoom out. Default: Ctrl-Minus - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& zoomOut(); - - /** - * Toggle insert/overwrite (with visual feedback, e.g. in the statusbar). Default: Insert - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& insert(); - - /** - * Goto beginning of the document. Default: Ctrl-Home - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& home(); - - /** - * Goto end of the document. Default: Ctrl-End - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& end(); - - /** - * Goto beginning of current line. Default: Home - * @return the shortcut of the standard accelerator - * @since 3.3 - */ - TDECORE_EXPORT const TDEShortcut& beginningOfLine(); - - /** - * Goto end of current line. Default: End - * @return the shortcut of the standard accelerator - * @since 3.3 - */ - TDECORE_EXPORT const TDEShortcut& endOfLine(); - - /** - * Scroll up one page. Default: Prior - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& prior(); - - /** - * Scroll down one page. Default: Next - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& next(); - - /** - * Go to line. Default: Ctrl+G - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& gotoLine(); - - /** - * Add current page to bookmarks. Default: Ctrl+B - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& addBookmark(); - - /** - * Next Tab. Default: Ctrl-< - * @return the shortcut of the standard accelerator - * @since 3.2 - */ - TDECORE_EXPORT const TDEShortcut& tabNext(); - - /** - * Previous Tab. Default: Ctrl-> - * @return the shortcut of the standard accelerator - * @since 3.2 - */ - TDECORE_EXPORT const TDEShortcut& tabPrev(); - - /** - * Full Screen Mode. Default: Ctrl+Shift+F - * @return the shortcut of the standard accelerator - * @since 3.2 - */ - TDECORE_EXPORT const TDEShortcut& fullScreen(); - - /** - * Help the user in the current situation. Default: F1 - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& help(); - - /** - * Complete text in input widgets. Default Ctrl+E - * @return the shortcut of the standard accelerator - **/ - TDECORE_EXPORT const TDEShortcut& completion(); - - /** - * Iterate through a list when completion returns - * multiple items. Default: Ctrl+Up - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& prevCompletion(); - - /** - * Iterate through a list when completion returns - * multiple items. Default: Ctrl+Down - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& nextCompletion(); - - /** - * Find a string within another string or list of strings. - * Default: Ctrl-T - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& substringCompletion(); - - /** - * Help users iterate through a list of entries. Default: Up - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& rotateUp(); - - /** - * Help users iterate through a list of entries. Default: Down - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& rotateDown(); - - /** - * popup a context menu. Default: Menu - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& popupMenuContext(); - - /** - * What's This button. Default: Shift+F1 - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& whatsThis(); - - /** - * Reload. Default: F5 - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& reload(); - - /** - * Up. Default: Alt+Up - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& up(); - - /** - * Back. Default: Alt+Left - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& back(); - - /** - * Forward. Default: ALT+Right - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& forward(); - - /** - * BackwardWord. Default: Ctrl+Left - * @return the shortcut of the standard accelerator - * @since 3.3 - */ - TDECORE_EXPORT const TDEShortcut& backwardWord(); - - /** - * ForwardWord. Default: Ctrl+Right - * @return the shortcut of the standard accelerator - * @since 3.3 - */ - TDECORE_EXPORT const TDEShortcut& forwardWord(); - - /** - * Show Menu Bar. Default: Ctrl-M - * @return the shortcut of the standard accelerator - */ - TDECORE_EXPORT const TDEShortcut& showMenubar(); - -#if !defined(KDE_NO_COMPAT) && !defined(__KSTDACCEL_CPP_) - /** - * @deprecated - * Obsolete. Use name(). Returns a string representation for @p accel. - */ - TDECORE_EXPORT TQString action(StdAccel id) KDE_DEPRECATED; - /** - * @deprecated - * Obsolete. Use desc(). Returns a localized description of @p accel. - */ - TDECORE_EXPORT TQString description(StdAccel id) KDE_DEPRECATED; - /** - * @deprecated - * Obsolete. Use shortcut(). Returns the keybinding for @p accel. - */ - TDECORE_EXPORT int key(StdAccel) KDE_DEPRECATED; - /** - * @deprecated - * Obsolete. Use shortcutDefault(). - */ - TDECORE_EXPORT int defaultKey(StdAccel accel) KDE_DEPRECATED; - - /** - * @deprecated. Use KKey(const TQKeyEvent*) == KKey(int). - * - * Compare the keys generated by the key event with - * the value of the integer. - * - * If a modifier (Shift, Alt, Ctrl) key is present in - * TQKeyEvent, its sum with the actual key value - * is used for comparing it with the integer parameter. - * - * @param pEvent the key event to be used in the comparison. - * @param keyQt the int value to be compared to the key event. - * - * @return true if the int value matches the integer representation of the QKeyEvent - */ - TDECORE_EXPORT bool isEqual(const TQKeyEvent* pEvent, int keyQt) KDE_DEPRECATED; -#endif // !KDE_NO_COMPAT - -} - -#endif diff --git a/tdecore/network/ipv6blacklist b/tdecore/network/ipv6blacklist deleted file mode 100644 index f4d4d1252..000000000 --- a/tdecore/network/ipv6blacklist +++ /dev/null @@ -1,3 +0,0 @@ -.doubleclick.net -.linebourse.fr -.banquepopulaire.fr diff --git a/tdecore/network/ipv6blactdelist b/tdecore/network/ipv6blactdelist new file mode 100644 index 000000000..f4d4d1252 --- /dev/null +++ b/tdecore/network/ipv6blactdelist @@ -0,0 +1,3 @@ +.doubleclick.net +.linebourse.fr +.banquepopulaire.fr diff --git a/tdecore/tdeaccel.cpp b/tdecore/tdeaccel.cpp new file mode 100644 index 000000000..9dde93e7a --- /dev/null +++ b/tdecore/tdeaccel.cpp @@ -0,0 +1,663 @@ +/* + Copyright (c) 2001,2002 Ellis Whitehead + + This library 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. + + 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. +*/ + +#include "kaccel.h" + +#include +#include +#include +#include +#include +#include + +#include "kaccelbase.h" +#include +#include +#include +#include + +#include "kaccelprivate.h" + +#ifdef Q_WS_X11 +# include +# ifdef KeyPress // needed for --enable-final + // defined by X11 headers + const int XKeyPress = KeyPress; +# undef KeyPress +# endif +#endif + +// TODO: Put in kaccelbase.cpp +//--------------------------------------------------------------------- +// TDEAccelEventHandler +//--------------------------------------------------------------------- +// +// In TDEAccelEventHandler::x11Event we do our own X11 keyboard event handling +// This allows us to map the Win key to Qt::MetaButton, Qt does not know about +// the Win key. +// +// TDEAccelEventHandler::x11Event will generate an AccelOverride event. The +// AccelOverride event is abused a bit to ensure that TDEAccelPrivate::eventFilter +// (as an event filter on the toplevel widget) will get the key event first +// (in the form of AccelOverride) before any of the intermediate widgets are +// able to process it. +// +// Qt normally sends an AccelOverride, Accel and then a KeyPress event. +// A widget can accept the AccelOverride event in which case the Accel event will be +// skipped and the KeyPress is followed immediately. +// If the Accel event is accepted, no KeyPress event will follow. +// +// TDEAccelEventHandler::x11Event converts a X11 keyboard event into an AccelOverride +// event, there are now two possibilities: +// +// 1) If TDEAccel intercepts the AccelOverride we are done and can consider the X11 +// keyboard event as handled. +// 2) If another widget accepts the AccelOverride, it will expect to get a normal +// Qt generated KeyPress event afterwards. So we let Qt handle the X11 keyboard event +// again. However, this will first generate an AccelOverride event, and we already +// had send that one. To compnesate for this, the global event filter in TDEApplication +// is instructed to eat the next AccelOveride event. Qt will then send a normal KeyPress +// event and from then on everything is normal again. +// +// kde_g_bKillAccelOverride is used to tell TDEApplication::notify to eat the next +// AccelOverride event. + +bool kde_g_bKillAccelOverride = false; + +class TDEAccelEventHandler : public TQWidget +{ + public: + static TDEAccelEventHandler* self() + { + if( !g_pSelf ) + g_pSelf = new TDEAccelEventHandler; + return g_pSelf; + } + + static void accelActivated( bool b ) { g_bAccelActivated = b; } + + private: + TDEAccelEventHandler(); + +# ifdef Q_WS_X11 + bool x11Event( XEvent* pEvent ); +# endif + + static TDEAccelEventHandler* g_pSelf; + static bool g_bAccelActivated; +}; + +TDEAccelEventHandler* TDEAccelEventHandler::g_pSelf = 0; +bool TDEAccelEventHandler::g_bAccelActivated = false; + +TDEAccelEventHandler::TDEAccelEventHandler() + : TQWidget( 0, "TDEAccelEventHandler" ) +{ +# ifdef Q_WS_X11 + if ( kapp ) + kapp->installX11EventFilter( TQT_TQWIDGET(this) ); +# endif +} + +#ifdef Q_WS_X11 +bool tqt_try_modal( TQWidget *, XEvent * ); + +bool TDEAccelEventHandler::x11Event( XEvent* pEvent ) +{ + if( TQWidget::keyboardGrabber() || !kapp->focusWidget() ) + return false; + + if ( !tqt_try_modal(kapp->focusWidget(), pEvent) ) + return false; + + if( pEvent->type == XKeyPress ) { + unsigned int tmp = pEvent->xkey.state; + pEvent->xkey.state &= ~0x2000; + KKeyNative keyNative( pEvent ); + pEvent->xkey.state = tmp; + KKey key( keyNative ); + key.simplify(); + int keyCodeQt = key.keyCodeQt(); + int state = 0; + if( key.modFlags() & KKey::SHIFT ) state |= TQt::ShiftButton; + if( key.modFlags() & KKey::CTRL ) state |= TQt::ControlButton; + if( key.modFlags() & KKey::ALT ) state |= TQt::AltButton; + if( key.modFlags() & KKey::WIN ) state |= TQt::MetaButton; + + TQKeyEvent ke( TQEvent::AccelOverride, keyCodeQt, 0, state ); + ke.ignore(); + + g_bAccelActivated = false; + kapp->sendEvent( kapp->focusWidget(), &ke ); + + // If the Override event was accepted from a non-TDEAccel widget, + // then kill the next AccelOverride in TDEApplication::notify. + if( ke.isAccepted() && !g_bAccelActivated ) + kde_g_bKillAccelOverride = true; + + // Stop event processing if a KDE accelerator was activated. + return g_bAccelActivated; + } + + return false; +} +#endif // Q_WS_X11 + +//--------------------------------------------------------------------- +// TDEAccelPrivate +//--------------------------------------------------------------------- + +TDEAccelPrivate::TDEAccelPrivate( TDEAccel* pParent, TQWidget* pWatch ) +: TDEAccelBase( TDEAccelBase::QT_KEYS ) +{ + //kdDebug(125) << "TDEAccelPrivate::TDEAccelPrivate( pParent = " << pParent << " ): this = " << this << endl; + m_pAccel = pParent; + m_pWatch = pWatch; + m_bAutoUpdate = true; + connect( (TQAccel*)m_pAccel, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotKeyPressed(int)) ); + +#ifdef Q_WS_X11 //only makes sense if TDEAccelEventHandler is working + if( m_pWatch ) + m_pWatch->installEventFilter( this ); +#endif + TDEAccelEventHandler::self(); +} + +void TDEAccelPrivate::setEnabled( bool bEnabled ) +{ + m_bEnabled = bEnabled; + ((TQAccel*)m_pAccel)->setEnabled( bEnabled ); +} + +bool TDEAccelPrivate::setEnabled( const TQString& sAction, bool bEnable ) +{ + kdDebug(125) << "TDEAccelPrivate::setEnabled( \"" << sAction << "\", " << bEnable << " ): this = " << this << endl; + TDEAccelAction* pAction = actionPtr( sAction ); + if( !pAction ) + return false; + if( pAction->isEnabled() == bEnable ) + return true; + + pAction->setEnabled( bEnable ); + + TQMap::const_iterator it = m_mapIDToAction.begin(); + for( ; it != m_mapIDToAction.end(); ++it ) { + if( *it == pAction ) + ((TQAccel*)m_pAccel)->setItemEnabled( it.key(), bEnable ); + } + return true; +} + +bool TDEAccelPrivate::removeAction( const TQString& sAction ) +{ + // FIXME: getID() doesn't contains any useful + // information! Use mapIDToAction. --ellis, 2/May/2002 + // Or maybe TDEAccelBase::remove() takes care of TQAccel indirectly... + TDEAccelAction* pAction = actions().actionPtr( sAction ); + if( pAction ) { + int nID = pAction->getID(); + //bool b = actions().removeAction( sAction ); + bool b = TDEAccelBase::remove( sAction ); + ((TQAccel*)m_pAccel)->removeItem( nID ); + return b; + } else + return false; +} + +bool TDEAccelPrivate::emitSignal( TDEAccelBase::Signal signal ) +{ + if( signal == TDEAccelBase::KEYCODE_CHANGED ) { + m_pAccel->emitKeycodeChanged(); + return true; + } + return false; +} + +bool TDEAccelPrivate::connectKey( TDEAccelAction& action, const KKeyServer::Key& key ) +{ + uint keyQt = key.keyCodeQt(); + int nID = ((TQAccel*)m_pAccel)->insertItem( keyQt ); + m_mapIDToAction[nID] = &action; + m_mapIDToKey[nID] = keyQt; + + if( action.objSlotPtr() && action.methodSlotPtr() ) { +#ifdef Q_WS_WIN /** @todo TEMP: new implementation (commit #424926) didn't work */ + ((TQAccel*)m_pAccel)->connectItem( nID, action.objSlotPtr(), action.methodSlotPtr() ); +#else + ((TQAccel*)m_pAccel)->connectItem( nID, this, TQT_SLOT(slotKeyPressed(int))); +#endif + if( !action.isEnabled() ) + ((TQAccel*)m_pAccel)->setItemEnabled( nID, false ); + } + + kdDebug(125) << "TDEAccelPrivate::connectKey( \"" << action.name() << "\", " << key.key().toStringInternal() << " = 0x" << TQString::number(keyQt,16) << " ): id = " << nID << " m_pObjSlot = " << action.objSlotPtr() << endl; + //kdDebug(125) << "m_pAccel = " << m_pAccel << endl; + return nID != 0; +} + +bool TDEAccelPrivate::connectKey( const KKeyServer::Key& key ) +{ + uint keyQt = key.keyCodeQt(); + int nID = ((TQAccel*)m_pAccel)->insertItem( keyQt ); + + m_mapIDToKey[nID] = keyQt; + + kdDebug(125) << "TDEAccelPrivate::connectKey( " << key.key().toStringInternal() << " = 0x" << TQString::number(keyQt,16) << " ): id = " << nID << endl; + return nID != 0; +} + +bool TDEAccelPrivate::disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ) +{ + int keyQt = key.keyCodeQt(); + TQMap::iterator it = m_mapIDToKey.begin(); + for( ; it != m_mapIDToKey.end(); ++it ) { + //kdDebug(125) << "m_mapIDToKey[" << it.key() << "] = " << TQString::number(*it,16) << " == " << TQString::number(keyQt,16) << endl; + if( *it == keyQt ) { + int nID = it.key(); + kdDebug(125) << "TDEAccelPrivate::disconnectKey( \"" << action.name() << "\", 0x" << TQString::number(keyQt,16) << " ) : id = " << nID << " m_pObjSlot = " << action.objSlotPtr() << endl; + ((TQAccel*)m_pAccel)->removeItem( nID ); + m_mapIDToAction.remove( nID ); + m_mapIDToKey.remove( it ); + return true; + } + } + //kdWarning(125) << kdBacktrace() << endl; + kdWarning(125) << "Didn't find key in m_mapIDToKey." << endl; + return false; +} + +bool TDEAccelPrivate::disconnectKey( const KKeyServer::Key& key ) +{ + int keyQt = key.keyCodeQt(); + kdDebug(125) << "TDEAccelPrivate::disconnectKey( 0x" << TQString::number(keyQt,16) << " )" << endl; + TQMap::iterator it = m_mapIDToKey.begin(); + for( ; it != m_mapIDToKey.end(); ++it ) { + if( *it == keyQt ) { + ((TQAccel*)m_pAccel)->removeItem( it.key() ); + m_mapIDToKey.remove( it ); + return true; + } + } + //kdWarning(125) << kdBacktrace() << endl; + kdWarning(125) << "Didn't find key in m_mapIDTokey." << endl; + return false; +} + +void TDEAccelPrivate::slotKeyPressed( int id ) +{ + kdDebug(125) << "TDEAccelPrivate::slotKeyPressed( " << id << " )" << endl; + + if( m_mapIDToKey.contains( id ) ) { + KKey key = m_mapIDToKey[id]; + KKeySequence seq( key ); + TQPopupMenu* pMenu = createPopupMenu( m_pWatch, seq ); + + // If there was only one action mapped to this key, + // and that action is not a multi-key shortcut, + // then activated it without popping up the menu. + // This is needed for when there are multiple actions + // with the same shortcut where all but one is disabled. + // pMenu->count() also counts the menu title, so one shortcut will give count = 2. + if( pMenu->count() == 2 && pMenu->accel(1).isEmpty() ) { + int iAction = pMenu->idAt(1); + slotMenuActivated( iAction ); + } else { + connect( pMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotMenuActivated(int)) ); + pMenu->exec( m_pWatch->mapToGlobal( TQPoint( 0, 0 ) ) ); + disconnect( pMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotMenuActivated(int)) ); + } + delete pMenu; + } +} + +void TDEAccelPrivate::slotShowMenu() +{ +} + +void TDEAccelPrivate::slotMenuActivated( int iAction ) +{ + kdDebug(125) << "TDEAccelPrivate::slotMenuActivated( " << iAction << " )" << endl; + TDEAccelAction* pAction = actions().actionPtr( iAction ); +#ifdef Q_WS_WIN /** @todo TEMP: new implementation (commit #424926) didn't work */ + if( pAction ) { + connect( this, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() ); + emit menuItemActivated(); + disconnect( this, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() ); + } +#else + emitActivatedSignal( pAction ); +#endif +} + +bool TDEAccelPrivate::eventFilter( TQObject* /*pWatched*/, TQEvent* pEvent ) +{ + if( pEvent->type() == TQEvent::AccelOverride && m_bEnabled ) { + TQKeyEvent* pKeyEvent = (TQKeyEvent*) pEvent; + KKey key( pKeyEvent ); + kdDebug(125) << "TDEAccelPrivate::eventFilter( AccelOverride ): this = " << this << ", key = " << key.toStringInternal() << endl; + int keyCodeQt = key.keyCodeQt(); + TQMap::iterator it = m_mapIDToKey.begin(); + for( ; it != m_mapIDToKey.end(); ++it ) { + if( (*it) == keyCodeQt ) { + int nID = it.key(); + kdDebug(125) << "shortcut found!" << endl; + if( m_mapIDToAction.contains( nID ) ) { + // TODO: reduce duplication between here and slotMenuActivated + TDEAccelAction* pAction = m_mapIDToAction[nID]; + if( !pAction->isEnabled() ) + continue; +#ifdef Q_WS_WIN /** @todo TEMP: new implementation (commit #424926) didn't work */ + TQGuardedPtr me = this; + connect( this, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() ); + emit menuItemActivated(); + if (me) { + disconnect( me, TQT_SIGNAL(menuItemActivated()), pAction->objSlotPtr(), pAction->methodSlotPtr() ); + } +#else + emitActivatedSignal( pAction ); +#endif + } else + slotKeyPressed( nID ); + + pKeyEvent->accept(); + TDEAccelEventHandler::accelActivated( true ); + return true; + } + } + } + return false; +} + +#ifndef Q_WS_WIN /** @todo TEMP: new implementation (commit #424926) didn't work */ +void TDEAccelPrivate::emitActivatedSignal( TDEAccelAction* pAction ) +{ + if( pAction ) { + TQGuardedPtr me = this; + TQRegExp reg( "([ ]*TDEAccelAction.*)" ); + if( reg.search( pAction->methodSlotPtr()) >= 0 ) { + connect( this, TQT_SIGNAL(menuItemActivated(TDEAccelAction*)), + pAction->objSlotPtr(), pAction->methodSlotPtr() ); + emit menuItemActivated( pAction ); + if (me) + disconnect( me, TQT_SIGNAL(menuItemActivated(TDEAccelAction*)), + pAction->objSlotPtr(), pAction->methodSlotPtr() ); + } else { + connect( this, TQT_SIGNAL(menuItemActivated()), + pAction->objSlotPtr(), pAction->methodSlotPtr() ); + emit menuItemActivated(); + if (me) + disconnect( me, TQT_SIGNAL(menuItemActivated()), + pAction->objSlotPtr(), pAction->methodSlotPtr() ); + + } + } +} +#endif + +//--------------------------------------------------------------------- +// TDEAccel +//--------------------------------------------------------------------- + +TDEAccel::TDEAccel( TQWidget* pParent, const char* psName ) +: TQAccel( pParent, (psName) ? psName : "TDEAccel-TQAccel" ) +{ + kdDebug(125) << "TDEAccel( pParent = " << pParent << ", psName = " << psName << " ): this = " << this << endl; + d = new TDEAccelPrivate( this, pParent ); +} + +TDEAccel::TDEAccel( TQWidget* watch, TQObject* pParent, const char* psName ) +: TQAccel( watch, pParent, (psName) ? psName : "TDEAccel-TQAccel" ) +{ + kdDebug(125) << "TDEAccel( watch = " << watch << ", pParent = " << pParent << ", psName = " << psName << " ): this = " << this << endl; + if( !watch ) + kdDebug(125) << kdBacktrace() << endl; + d = new TDEAccelPrivate( this, watch ); +} + +TDEAccel::~TDEAccel() +{ + kdDebug(125) << "~TDEAccel(): this = " << this << endl; + delete d; +} + +TDEAccelActions& TDEAccel::actions() { return d->actions(); } +const TDEAccelActions& TDEAccel::actions() const { return d->actions(); } +bool TDEAccel::isEnabled() { return d->isEnabled(); } +void TDEAccel::setEnabled( bool bEnabled ) { d->setEnabled( bEnabled ); } +bool TDEAccel::setAutoUpdate( bool bAuto ) { return d->setAutoUpdate( bAuto ); } + +TDEAccelAction* TDEAccel::insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, + const TDEShortcut& cutDef, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ) +{ + return d->insert( sAction, sLabel, sWhatsThis, + cutDef, cutDef, + pObjSlot, psMethodSlot, + bConfigurable, bEnabled ); +} + +TDEAccelAction* TDEAccel::insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, + const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ) +{ + return d->insert( sAction, sLabel, sWhatsThis, + cutDef3, cutDef4, + pObjSlot, psMethodSlot, + bConfigurable, bEnabled ); +} + +TDEAccelAction* TDEAccel::insert( const char* psAction, const TDEShortcut& cutDef, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ) +{ + return d->insert( psAction, i18n(psAction), TQString::null, + cutDef, cutDef, + pObjSlot, psMethodSlot, + bConfigurable, bEnabled ); +} + +TDEAccelAction* TDEAccel::insert( TDEStdAccel::StdAccel id, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ) +{ + TQString sAction = TDEStdAccel::name( id ); + if( sAction.isEmpty() ) + return 0; + + TDEAccelAction* pAction = d->insert( sAction, TDEStdAccel::label( id ), TDEStdAccel::whatsThis( id ), + TDEStdAccel::shortcutDefault3( id ), TDEStdAccel::shortcutDefault4( id ), + pObjSlot, psMethodSlot, + bConfigurable, bEnabled ); + if( pAction ) + pAction->setShortcut( TDEStdAccel::shortcut( id ) ); + + return pAction; +} + +bool TDEAccel::remove( const TQString& sAction ) + { return d->removeAction( sAction ); } +bool TDEAccel::updateConnections() + { return d->updateConnections(); } + +const TDEShortcut& TDEAccel::shortcut( const TQString& sAction ) const +{ + const TDEAccelAction* pAction = actions().actionPtr( sAction ); + return (pAction) ? pAction->shortcut() : TDEShortcut::null(); +} + +bool TDEAccel::setSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ) + { return d->setActionSlot( sAction, pObjSlot, psMethodSlot ); } + +bool TDEAccel::setEnabled( const TQString& sAction, bool bEnable ) + { return d->setEnabled( sAction, bEnable ); } + +bool TDEAccel::setShortcut( const TQString& sAction, const TDEShortcut& cut ) +{ + kdDebug(125) << "TDEAccel::setShortcut( \"" << sAction << "\", " << cut.toStringInternal() << " )" << endl; + TDEAccelAction* pAction = actions().actionPtr( sAction ); + if( pAction ) { + if( pAction->shortcut() != cut ) + return d->setShortcut( sAction, cut ); + return true; + } + return false; +} + +const TQString& TDEAccel::configGroup() const + { return d->configGroup(); } +// for tdegames/ksirtet +void TDEAccel::setConfigGroup( const TQString& s ) + { d->setConfigGroup( s ); } + +bool TDEAccel::readSettings( TDEConfigBase* pConfig ) +{ + d->readSettings( pConfig ); + return true; +} + +bool TDEAccel::writeSettings( TDEConfigBase* pConfig ) const + { d->writeSettings( pConfig ); return true; } + +void TDEAccel::emitKeycodeChanged() +{ + kdDebug(125) << "TDEAccel::emitKeycodeChanged()" << endl; + emit keycodeChanged(); +} + +#ifndef KDE_NO_COMPAT +//------------------------------------------------------------ +// Obsolete methods -- for backward compatibility +//------------------------------------------------------------ + +bool TDEAccel::insertItem( const TQString& sLabel, const TQString& sAction, + const char* cutsDef, + int /*nIDMenu*/, TQPopupMenu *, bool bConfigurable ) +{ + TDEShortcut cut( cutsDef ); + bool b = d->insert( sAction, sLabel, TQString::null, + cut, cut, + 0, 0, + bConfigurable ) != 0; + return b; +} + +bool TDEAccel::insertItem( const TQString& sLabel, const TQString& sAction, + int key, + int /*nIDMenu*/, TQPopupMenu*, bool bConfigurable ) +{ + TDEShortcut cut; + cut.init( TQKeySequence(key) ); + TDEAccelAction* pAction = d->insert( sAction, sLabel, TQString::null, + cut, cut, + 0, 0, + bConfigurable ); + return pAction != 0; +} + +// Used in tdeutils/kjots +bool TDEAccel::insertStdItem( TDEStdAccel::StdAccel id, const TQString& sLabel ) +{ + TDEAccelAction* pAction = d->insert( TDEStdAccel::name( id ), sLabel, TQString::null, + TDEStdAccel::shortcutDefault3( id ), TDEStdAccel::shortcutDefault4( id ), + 0, 0 ); + if( pAction ) + pAction->setShortcut( TDEStdAccel::shortcut( id ) ); + + return true; +} + +bool TDEAccel::connectItem( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot, bool bActivate ) +{ + kdDebug(125) << "TDEAccel::connectItem( " << sAction << ", " << pObjSlot << ", " << psMethodSlot << " )" << endl; + if( bActivate == false ) + d->setActionEnabled( sAction, false ); + bool b = setSlot( sAction, pObjSlot, psMethodSlot ); + if( bActivate == true ) + d->setActionEnabled( sAction, true ); + return b; +} + +bool TDEAccel::removeItem( const TQString& sAction ) + { return d->removeAction( sAction ); } + +bool TDEAccel::setItemEnabled( const TQString& sAction, bool bEnable ) + { return setEnabled( sAction, bEnable ); } + +void TDEAccel::changeMenuAccel( TQPopupMenu *menu, int id, const TQString& action ) +{ + TDEAccelAction* pAction = actions().actionPtr( action ); + TQString s = menu->text( id ); + if( !pAction || s.isEmpty() ) + return; + + int i = s.find( '\t' ); + + TQString k = pAction->shortcut().seq(0).toString(); + if( k.isEmpty() ) + return; + + if ( i >= 0 ) + s.replace( i+1, s.length()-i, k ); + else { + s += '\t'; + s += k; + } + + TQPixmap *pp = menu->pixmap(id); + if( pp && !pp->isNull() ) + menu->changeItem( *pp, s, id ); + else + menu->changeItem( s, id ); +} + +void TDEAccel::changeMenuAccel( TQPopupMenu *menu, int id, TDEStdAccel::StdAccel accel ) +{ + changeMenuAccel( menu, id, TDEStdAccel::name( accel ) ); +} + +int TDEAccel::stringToKey( const TQString& sKey ) +{ + return KKey( sKey ).keyCodeQt(); +} + +int TDEAccel::currentKey( const TQString& sAction ) const +{ + TDEAccelAction* pAction = d->actionPtr( sAction ); + if( pAction ) + return pAction->shortcut().keyCodeQt(); + return 0; +} + +TQString TDEAccel::findKey( int key ) const +{ + TDEAccelAction* pAction = d->actionPtr( KKey(key) ); + if( pAction ) + return pAction->name(); + else + return TQString::null; +} +#endif // !KDE_NO_COMPAT + +void TDEAccel::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +#include "kaccel.moc" +#include "kaccelprivate.moc" diff --git a/tdecore/tdeaccel.h b/tdecore/tdeaccel.h new file mode 100644 index 000000000..8a3f2d499 --- /dev/null +++ b/tdecore/tdeaccel.h @@ -0,0 +1,390 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001,2002 Ellis Whitehead + + This library 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. + + 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 _KACCEL_H +#define _KACCEL_H + +#include +#include +#include +#include "tdelibs_export.h" + +class TQPopupMenu; // for obsolete insertItem() methods below +class TQWidget; +class TDEAccelAction; +class TDEAccelActions; +class TDEConfigBase; + +class TDEAccelPrivate; +/** + * Handle shortcuts. + * + * Allow a user to configure shortcuts + * through application configuration files or through the + * KKeyChooser GUI. + * + * A TDEAccel contains a list of accelerator actions. + * + * For example, CTRL+Key_P could be a shortcut for printing a document. The key + * codes are listed in tqnamespace.h. "Print" could be the action name for printing. + * The action name identifies the shortcut in configuration files and the + * KKeyChooser GUI. + * + * A TDEAccel object handles key events sent to its parent widget and to all + * children of this parent widget. The most recently created TDEAccel object + * has precedence over any TDEAccel objects created before it. + * When a shortcut pressed, TDEAccel calls the slot to which it has been + * connected. If you want to set global accelerators, independent of the window + * which has the focus, use TDEGlobalAccel. + * + * Reconfiguration of a given shortcut can be prevented by specifying + * that an accelerator item is not configurable when it is inserted. A special + * group of non-configurable key bindings are known as the + * standard accelerators. + * + * The standard accelerators appear repeatedly in applications for + * standard document actions such as printing and saving. A convenience method is + * available to insert and connect these accelerators which are configurable on + * a desktop-wide basis. + * + * It is possible for a user to choose to have no key associated with + * an action. + * + * The translated first argument for insertItem() is used only + * in the configuration dialog. + *\code + * TDEAccel* pAccel = new TDEAccel( this ); + * + * // Insert an action "Scroll Up" which is associated with the "Up" key: + * pAccel->insert( "Scroll Up", i18n("Scroll up"), + * i18n("Scroll up the current document by one line."), + * Qt::Key_Up, this, TQT_SLOT(slotScrollUp()) ); + * // Insert an standard acclerator action. + * pAccel->insert( TDEStdAccel::Print, this, TQT_SLOT(slotPrint()) ); + * + * // Update the shortcuts by read any user-defined settings from the + * // application's config file. + * pAccel->readSettings(); + * \endcode + * + * @short Configurable shortcut support for widgets. + * @see TDEGlobalAccel + * @see TDEAccelShortcutList + * @see KKeyChooser + * @see KKeyDialog + */ + +class TDECORE_EXPORT TDEAccel : public TQAccel +{ + Q_OBJECT + public: + /** + * Creates a new TDEAccel that watches @p pParent, which is also + * the QObject's parent. + * + * @param pParent the parent and widget to watch for key strokes + * @param psName the name of the QObject + */ + TDEAccel( TQWidget* pParent, const char* psName = 0 ); + + /** + * Creates a new TDEAccel that watches @p watch. + * + * @param watch the widget to watch for key strokes + * @param parent the parent of the QObject + * @param psName the name of the QObject + */ + TDEAccel( TQWidget* watch, TQObject* parent, const char* psName = 0 ); + virtual ~TDEAccel(); + + /** + * @internal + * Returns the TDEAccel's @p TDEAccelActions, a list of @p TDEAccelAction. + * @return the TDEAccelActions of the TDEAccel + */ + TDEAccelActions& actions(); + + /** + * @internal + * Returns the TDEAccel's @p TDEAccelActions, a list of @p TDEAccelAction. + * @return the TDEAccelActions of the TDEAccel + */ + const TDEAccelActions& actions() const; + + /** + * Checks whether the TDEAccel is active. + * @return true if the TQAccel is enabled + */ + bool isEnabled(); + + /** + * Enables or disables the TDEAccel. + * @param bEnabled true to enable, false to disable + */ + void setEnabled( bool bEnabled ); + + /** + * Enable auto-update of connections. This means that the signals + * are automatically disconnected when you disable an action, and + * re-enabled when you enable it. By default auto update is turned + * on. If you disable auto-update, you need to call + * updateConnections() after changing actions. + * + * @param bAuto true to enable, false to disable + * @return the value of the flag before this call + */ + bool setAutoUpdate( bool bAuto ); + + /** + * Create an accelerator action. + * + * Usage: + *\code + * insert( "Do Something", i18n("Do Something"), + * i18n("This action allows you to do something really great with this program to " + * "the currently open document."), + * ALT+Key_D, this, TQT_SLOT(slotDoSomething()) ); + *\endcode + * + * @param sAction The internal name of the action. + * @param sLabel An i18n'ized short description of the action displayed when + * using KKeyChooser to reconfigure the shortcuts. + * @param sWhatsThis An extended description of the action. + * @param cutDef The default shortcut. + * @param pObjSlot Pointer to the slot object. + * @param psMethodSlot Pointer to the slot method. + * @param bConfigurable Allow the user to change this shortcut if set to 'true'. + * @param bEnabled The action will be activated by the shortcut if set to 'true'. + */ + TDEAccelAction* insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, + const TDEShortcut& cutDef, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable = true, bool bEnabled = true ); + /** + * Same as first insert(), but with separate shortcuts defined for + * 3- and 4- modifier defaults. + */ + TDEAccelAction* insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, + const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable = true, bool bEnabled = true ); + /** + * This is an overloaded function provided for convenience. + * The advantage of this is when you want to use the same text for the name + * of the action as for the user-visible label. + * + * Usage: + * \code + * insert( i18n("Do Something"), ALT+Key_D, this, TQT_SLOT(slotDoSomething()) ); + * \endcode + * + * @param psAction The name AND label of the action. + * @param cutDef The default shortcut for this action. + * @param pObjSlot Pointer to the slot object. + * @param psMethodSlot Pointer to the slot method. + * @param bConfigurable Allow the user to change this shortcut if set to 'true'. + * @param bEnabled The action will be activated by the shortcut if set to 'true'. + */ + TDEAccelAction* insert( const char* psAction, const TDEShortcut& cutDef, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable = true, bool bEnabled = true ); + /** + * Similar to the first insert() method, but with the action + * name, short description, help text, and default shortcuts all + * set according to one of the standard accelerators. + * @see TDEStdAccel. + */ + TDEAccelAction* insert( TDEStdAccel::StdAccel id, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable = true, bool bEnabled = true ); + + /** + * Removes the accelerator action identified by the name. + * Remember to also call updateConnections(). + * @param sAction the name of the action to remove + * @return true if successful, false otherwise + */ + bool remove( const TQString& sAction ); + + /** + * Updates the connections of the accelerations after changing them. + * This is only necessary if you have disabled auto updates which are + * on by default. + * @return true if successful, false otherwise + * @see setAutoUpdate() + * @see getAutoUpdate() + */ + bool updateConnections(); + + /** + * Return the shortcut associated with the action named by @p sAction. + * @param sAction the name of the action + * @return the action's shortcut, or a null shortcut if not found + */ + const TDEShortcut& shortcut( const TQString& sAction ) const; + + /** + * Set the shortcut to be associated with the action named by @p sAction. + * @param sAction the name of the action + * @param shortcut the shortcut to set + * @return true if successful, false otherwise + */ + bool setShortcut( const TQString& sAction, const TDEShortcut &shortcut ); + + /** + * Set the slot to be called when the shortcut of the action named + * by @p sAction is pressed. + * @param sAction the name of the action + * @param pObjSlot the owner of the slot + * @param psMethodSlot the name of the slot + * @return true if successful, false otherwise + */ + bool setSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ); + /** + * Enable or disable the action named by @p sAction. + * @param sAction the action to en-/disable + * @param bEnabled true to enable, false to disable + * @return true if successful, false otherwise + */ + bool setEnabled( const TQString& sAction, bool bEnabled ); + + /** + * Returns the configuration group of the settings. + * @return the configuration group + * @see TDEConfig + */ + const TQString& configGroup() const; + + /** + * Returns the configuration group of the settings. + * @param name the new configuration group + * @see TDEConfig + */ + void setConfigGroup( const TQString &name ); + + /** + * Read all shortcuts from @p pConfig, or (if @p pConfig + * is zero) from the application's configuration file + * TDEGlobal::config(). + * + * The group in which the configuration is stored can be + * set with setConfigGroup(). + * @param pConfig the configuration file, or 0 for the application + * configuration file + * @return true if successful, false otherwise + */ + bool readSettings( TDEConfigBase* pConfig = 0 ); + /** + * Write the current shortcuts to @p pConfig, + * or (if @p pConfig is zero) to the application's + * configuration file. + * @param pConfig the configuration file, or 0 for the application + * configuration file + * @return true if successful, false otherwise + */ + bool writeSettings( TDEConfigBase* pConfig = 0 ) const; + + /** + * Emits the keycodeChanged() signal. + */ + void emitKeycodeChanged(); + + signals: + /** + * Emitted when one of the key codes has changed. + */ + void keycodeChanged(); + +#ifndef KDE_NO_COMPAT + public: + // Source compatibility to KDE 2.x + /** + * @deprecated use insert + */ + bool insertItem( const TQString& sLabel, const TQString& sAction, + const char* psKey, + int nIDMenu = 0, TQPopupMenu* pMenu = 0, bool bConfigurable = true ) KDE_DEPRECATED; + /** + * @deprecated use insert + */ + bool insertItem( const TQString& sLabel, const TQString& sAction, + int key, + int nIDMenu = 0, TQPopupMenu* pMenu = 0, bool bConfigurable = true ) KDE_DEPRECATED; + /** + * @deprecated use insert + */ + bool insertStdItem( TDEStdAccel::StdAccel id, const TQString& descr = TQString::null ) KDE_DEPRECATED; + /** + * @deprecated use insert + */ + bool connectItem( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot, bool bActivate = true ) KDE_DEPRECATED; + /** + * @deprecated use insert( accel, pObjSlot, psMethodSlot ); + * + */ + KDE_DEPRECATED bool connectItem( TDEStdAccel::StdAccel accel, const TQObject* pObjSlot, const char* psMethodSlot ) + { return insert( accel, pObjSlot, psMethodSlot ); } + /** + * @deprecated use remove + */ + bool removeItem( const TQString& sAction ) KDE_DEPRECATED; + /** + * @deprecated + */ + bool setItemEnabled( const TQString& sAction, bool bEnable ) KDE_DEPRECATED; + /** + * @deprecated see KDE3PORTING.html + */ + void changeMenuAccel( TQPopupMenu *menu, int id, const TQString& action ) KDE_DEPRECATED; + /** + * @deprecated see KDE3PORTING.html + */ + void changeMenuAccel( TQPopupMenu *menu, int id, TDEStdAccel::StdAccel accel ) KDE_DEPRECATED; + /** + * @deprecated + */ + static int stringToKey( const TQString& ) KDE_DEPRECATED; + + /** + * @deprecated Use shortcut(). + * + * Retrieve the key code of the accelerator item with the action name + * @p action, or zero if either the action name cannot be + * found or the current key is set to no key. + */ + int currentKey( const TQString& action ) const KDE_DEPRECATED; + + /** + * @deprecated Use actions().actionPtr(). + * + * Return the name of the accelerator item with the keycode @p key, + * or TQString::null if the item cannot be found. + */ + TQString findKey( int key ) const KDE_DEPRECATED; +#endif // !KDE_NO_COMPAT + + protected: + /** \internal */ + virtual void virtual_hook( int id, void* data ); + private: + class TDEAccelPrivate* d; + friend class TDEAccelPrivate; +}; + +#endif // _KACCEL_H diff --git a/tdecore/tdeaccelaction.cpp b/tdecore/tdeaccelaction.cpp new file mode 100644 index 000000000..d3ec59be3 --- /dev/null +++ b/tdecore/tdeaccelaction.cpp @@ -0,0 +1,565 @@ +/* + Copyright (C) 1998 Mark Donohoe + Copyright (C) 1997-2000 Nicolas Hadacek + Copyright (C) 1998 Matthias Ettrich + Copyright (c) 2001,2002 Ellis Whitehead + + This library 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. + + 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. +*/ + +#include "kaccelaction.h" +#include "kaccelbase.h" // for TDEAccelBase::slotRemoveAction() & emitSignal() + +#include + +#include +#include "kckey.h" +#include +#include +#include +#include +#include + +//--------------------------------------------------------------------- +// TDEAccelAction +//--------------------------------------------------------------------- + +class TDEAccelActionPrivate +{ + public: + uint m_nConnections; +}; + +TDEAccelAction::TDEAccelAction() +{ + //kdDebug(125) << "TDEAccelAction(): this = " << this << endl; + d = new TDEAccelActionPrivate; + m_pObjSlot = 0; + m_psMethodSlot = 0; + m_bConfigurable = true; + m_bEnabled = true; + m_nIDAccel = 0; + d->m_nConnections = 0; +} + +TDEAccelAction::TDEAccelAction( const TDEAccelAction& action ) +{ + //kdDebug(125) << "TDEAccelAction( copy from \"" << action.m_sName << "\" ): this = " << this << endl; + d = new TDEAccelActionPrivate; + *this = action; +} + +TDEAccelAction::TDEAccelAction( const TQString& sName, const TQString& sLabel, const TQString& sWhatsThis, + const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ) +{ + //kdDebug(125) << "TDEAccelAction( \"" << sName << "\" ): this = " << this << endl; + d = new TDEAccelActionPrivate; + init( sName, sLabel, sWhatsThis, + cutDef3, cutDef4, + pObjSlot, psMethodSlot, + bConfigurable, bEnabled ); +} + +TDEAccelAction::~TDEAccelAction() +{ + //kdDebug(125) << "\t\t\tTDEAccelAction::~TDEAccelAction( \"" << m_sName << "\" ): this = " << this << endl; + delete d; +} + +void TDEAccelAction::clear() +{ + m_cut.clear(); + m_pObjSlot = 0; + m_psMethodSlot = 0; + m_bConfigurable = true; + m_bEnabled = true; + m_nIDAccel = 0; + d->m_nConnections = 0; +} + +bool TDEAccelAction::init( const TQString& sName, const TQString& sLabel, const TQString& sWhatsThis, + const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ) +{ + m_sName = sName; + m_sLabel = sLabel; + m_sWhatsThis = sWhatsThis; + m_cutDefault3 = rgCutDefaults3; + m_cutDefault4 = rgCutDefaults4; + m_pObjSlot = pObjSlot; + m_psMethodSlot = psMethodSlot; + m_bConfigurable = bConfigurable; + m_bEnabled = bEnabled; + m_nIDAccel = 0; + m_cut = shortcutDefault(); + d->m_nConnections = 0; + if( !m_bEnabled ) + kdDebug(125) << "TDEAccelAction::init( \"" << sName << "\" ): created with enabled = false" << endl; + return true; +} + +TDEAccelAction& TDEAccelAction::operator =( const TDEAccelAction& action ) +{ + m_sName = action.m_sName; + m_sLabel = action.m_sLabel; + m_sWhatsThis = action.m_sWhatsThis; + m_cutDefault3 = action.m_cutDefault3; + m_cutDefault4 = action.m_cutDefault4; + m_pObjSlot = action.m_pObjSlot; + m_psMethodSlot = action.m_psMethodSlot; + m_bConfigurable = action.m_bConfigurable; + m_bEnabled = action.m_bEnabled; + m_nIDAccel = action.m_nIDAccel; + m_cut = action.m_cut; + d->m_nConnections = action.d->m_nConnections; + + return *this; +} + +void TDEAccelAction::setName( const TQString& s ) + { m_sName = s; } +void TDEAccelAction::setLabel( const TQString& s ) + { m_sLabel = s; } +void TDEAccelAction::setWhatsThis( const TQString& s ) + { m_sWhatsThis = s; } + +bool TDEAccelAction::setShortcut( const TDEShortcut& cut ) +{ + m_cut = cut; + return true; +} + +void TDEAccelAction::setSlot( const TQObject* pObjSlot, const char* psMethodSlot ) +{ + m_pObjSlot = pObjSlot; + m_psMethodSlot = psMethodSlot; +} + +void TDEAccelAction::setConfigurable( bool b ) + { m_bConfigurable = b; } +void TDEAccelAction::setEnabled( bool b ) + { m_bEnabled = b; } + +TQString TDEAccelAction::toString() const + { return m_cut.toString(); } + +TQString TDEAccelAction::toStringInternal() const + { return m_cut.toStringInternal( &shortcutDefault() ); } + +bool TDEAccelAction::setKeySequence( uint i, const KKeySequence& seq ) +{ + if( i < m_cut.count() ) { + m_cut.setSeq( i, seq ); + return true; + } else if( i == m_cut.count() ) + return m_cut.append( seq ); + return false; +} + +void TDEAccelAction::clearShortcut() +{ + m_cut.clear(); +} + +bool TDEAccelAction::contains( const KKeySequence& seq ) +{ + return m_cut.contains( seq ); + for( uint i = 0; i < m_cut.count(); i++ ) { + if( m_cut.seq(i) == seq ) + return true; + } + return false; +} + +const TDEShortcut& TDEAccelAction::shortcutDefault() const + { return (useFourModifierKeys()) ? m_cutDefault4 : m_cutDefault3; } +bool TDEAccelAction::isConnected() const + { return d->m_nConnections; } +void TDEAccelAction::incConnections() + { d->m_nConnections++; } +void TDEAccelAction::decConnections() + { if( d->m_nConnections > 0 ) d->m_nConnections--; } + +// Indicate whether to default to the 3- or 4- modifier keyboard schemes +int TDEAccelAction::g_bUseFourModifierKeys = -1; + +bool TDEAccelAction::useFourModifierKeys() +{ + if( TDEAccelAction::g_bUseFourModifierKeys == -1 ) { + // Read in whether to use 4 modifier keys + TDEConfigGroupSaver cgs( TDEGlobal::config(), "Keyboard" ); + bool b = TDEGlobal::config()->readBoolEntry( "Use Four Modifier Keys", false ); + TDEAccelAction::g_bUseFourModifierKeys = b && KKeyNative::keyboardHasWinKey(); + } + return TDEAccelAction::g_bUseFourModifierKeys == 1; +} + +void TDEAccelAction::useFourModifierKeys( bool b ) +{ + if( TDEAccelAction::g_bUseFourModifierKeys != (int)b ) { + TDEAccelAction::g_bUseFourModifierKeys = b && KKeyNative::keyboardHasWinKey(); + // If we're 'turning off' the meta key or, if we're turning it on, + // the keyboard must actually have a meta key. + if( b && !KKeyNative::keyboardHasWinKey() ) + kdDebug(125) << "Tried to use four modifier keys on a keyboard layout without a Meta key.\n"; + } + TDEConfigGroupSaver cgs( TDEGlobal::config(), "Keyboard" ); + TDEGlobal::config()->writeEntry( "Use Four Modifier Keys", TDEAccelAction::g_bUseFourModifierKeys, true, true); + + kdDebug(125) << "bUseFourModifierKeys = " << TDEAccelAction::g_bUseFourModifierKeys << endl; +} + +//--------------------------------------------------------------------- +// TDEAccelActions +//--------------------------------------------------------------------- + +class TDEAccelActionsPrivate +{ + public: +}; + +TDEAccelActions::TDEAccelActions() +{ + kdDebug(125) << "TDEAccelActions(): this = " << this << endl; + initPrivate( 0 ); +} + +TDEAccelActions::TDEAccelActions( const TDEAccelActions& actions ) +{ + kdDebug(125) << "TDEAccelActions( actions = " << &actions << " ): this = " << this << endl; + initPrivate( 0 ); + init( actions ); +} + +TDEAccelActions::TDEAccelActions( TDEAccelBase* pTDEAccelBase ) +{ + kdDebug(125) << "TDEAccelActions( TDEAccelBase = " << pTDEAccelBase << " ): this = " << this << endl; + initPrivate( pTDEAccelBase ); +} + +TDEAccelActions::~TDEAccelActions() +{ + //kdDebug(125) << "TDEAccelActions::~TDEAccelActions(): this = " << this << endl; + clear(); + //delete d; +} + +void TDEAccelActions::initPrivate( TDEAccelBase* pTDEAccelBase ) +{ + m_pTDEAccelBase = pTDEAccelBase; + m_nSizeAllocated = m_nSize = 0; + m_prgActions = 0; + //d = new TDEAccelActionsPrivate; +} + +void TDEAccelActions::clear() +{ + kdDebug(125) << "\tTDEAccelActions::clear()" << endl; + for( uint i = 0; i < m_nSize; i++ ) + delete m_prgActions[i]; + delete[] m_prgActions; + + m_nSizeAllocated = m_nSize = 0; + m_prgActions = 0; +} + +bool TDEAccelActions::init( const TDEAccelActions& actions ) +{ + clear(); + resize( actions.count() ); + for( uint i = 0; i < m_nSize; i++ ) { + TDEAccelAction* pAction = actions.m_prgActions[i]; + if( pAction ) + m_prgActions[i] = new TDEAccelAction( *pAction ); + else + m_prgActions[i] = 0; + } + + return true; +} + +bool TDEAccelActions::init( TDEConfigBase& config, const TQString& sGroup ) +{ + kdDebug(125) << "TDEAccelActions::init( " << sGroup << " )" << endl; + TQMap mapEntry = config.entryMap( sGroup ); + resize( mapEntry.count() ); + + TQMap::Iterator it( mapEntry.begin() ); + for( uint i = 0; it != mapEntry.end(); ++it, i++ ) { + TQString sShortcuts = *it; + TDEShortcut cuts; + + kdDebug(125) << it.key() << " = " << sShortcuts << endl; + if( !sShortcuts.isEmpty() && sShortcuts != "none" ) + cuts.init( sShortcuts ); + + m_prgActions[i] = new TDEAccelAction( it.key(), it.key(), it.key(), + cuts, cuts, + 0, 0, // pObjSlot, psMethodSlot, + true, false ); // bConfigurable, bEnabled + } + + return true; +} + +void TDEAccelActions::resize( uint nSize ) +{ + if( nSize > m_nSizeAllocated ) { + uint nSizeAllocated = ((nSize/10) + 1) * 10; + TDEAccelAction** prgActions = new TDEAccelAction* [nSizeAllocated]; + + // Copy pointers over to new array + for( uint i = 0; i < m_nSizeAllocated; i++ ) + prgActions[i] = m_prgActions[i]; + + // Null out new pointers + for( uint i = m_nSizeAllocated; i < nSizeAllocated; i++ ) + prgActions[i] = 0; + + delete[] m_prgActions; + m_prgActions = prgActions; + m_nSizeAllocated = nSizeAllocated; + } + + m_nSize = nSize; +} + +void TDEAccelActions::insertPtr( TDEAccelAction* pAction ) +{ + resize( m_nSize + 1 ); + m_prgActions[m_nSize-1] = pAction; +} + +void TDEAccelActions::updateShortcuts( TDEAccelActions& actions2 ) +{ + kdDebug(125) << "TDEAccelActions::updateShortcuts()" << endl; + bool bChanged = false; + + for( uint i = 0; i < m_nSize; i++ ) { + TDEAccelAction* pAction = m_prgActions[i]; + if( pAction && pAction->m_bConfigurable ) { + TDEAccelAction* pAction2 = actions2.actionPtr( pAction->m_sName ); + if( pAction2 ) { + TQString sOld = pAction->m_cut.toStringInternal(); + pAction->m_cut = pAction2->m_cut; + kdDebug(125) << "\t" << pAction->m_sName + << " found: " << sOld + << " => " << pAction2->m_cut.toStringInternal() + << " = " << pAction->m_cut.toStringInternal() << endl; + bChanged = true; + } + } + } + + if( bChanged ) + emitKeycodeChanged(); +} + +int TDEAccelActions::actionIndex( const TQString& sAction ) const +{ + for( uint i = 0; i < m_nSize; i++ ) { + if( m_prgActions[i] == 0 ) + kdWarning(125) << "TDEAccelActions::actionPtr( " << sAction << " ): encountered null pointer at m_prgActions[" << i << "]" << endl; + else if( m_prgActions[i]->m_sName == sAction ) + return (int) i; + } + return -1; +} + +TDEAccelAction* TDEAccelActions::actionPtr( uint i ) +{ + return m_prgActions[i]; +} + +const TDEAccelAction* TDEAccelActions::actionPtr( uint i ) const +{ + return m_prgActions[i]; +} + +TDEAccelAction* TDEAccelActions::actionPtr( const TQString& sAction ) +{ + int i = actionIndex( sAction ); + return (i >= 0) ? m_prgActions[i] : 0; +} + +const TDEAccelAction* TDEAccelActions::actionPtr( const TQString& sAction ) const +{ + int i = actionIndex( sAction ); + return (i >= 0) ? m_prgActions[i] : 0; +} + +TDEAccelAction* TDEAccelActions::actionPtr( KKeySequence cut ) +{ + for( uint i = 0; i < m_nSize; i++ ) { + if( m_prgActions[i] == 0 ) + kdWarning(125) << "TDEAccelActions::actionPtr( " << cut.toStringInternal() << " ): encountered null pointer at m_prgActions[" << i << "]" << endl; + else if( m_prgActions[i]->contains( cut ) ) + return m_prgActions[i]; + } + return 0; +} + +TDEAccelAction& TDEAccelActions::operator []( uint i ) +{ + return *actionPtr( i ); +} + +const TDEAccelAction& TDEAccelActions::operator []( uint i ) const +{ + return *actionPtr( i ); +} + +TDEAccelAction* TDEAccelActions::insert( const TQString& sName, const TQString& sLabel ) +{ + if( actionPtr( sName ) ) { + kdWarning(125) << "TDEAccelActions::insertLabel( " << sName << ", " << sLabel << " ): action with same name already present." << endl; + return 0; + } + + TDEAccelAction* pAction = new TDEAccelAction; + pAction->m_sName = sName; + pAction->m_sLabel = sLabel; + pAction->m_bConfigurable = false; + pAction->m_bEnabled = false; + + insertPtr( pAction ); + return pAction; +} + +TDEAccelAction* TDEAccelActions::insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, + const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ) +{ + //kdDebug(125) << "TDEAccelActions::insert()2 begin" << endl; + if( actionPtr( sAction ) ) { + kdWarning(125) << "TDEAccelActions::insert( " << sAction << " ): action with same name already present." << endl; + return 0; + } + + TDEAccelAction* pAction = new TDEAccelAction( + sAction, sLabel, sWhatsThis, + rgCutDefaults3, rgCutDefaults4, + pObjSlot, psMethodSlot, + bConfigurable, bEnabled ); + insertPtr( pAction ); + + //kdDebug(125) << "TDEAccelActions::insert()2 end" << endl; + return pAction; +} + +bool TDEAccelActions::remove( const TQString& sAction ) +{ + kdDebug(125) << "TDEAccelActions::remove( \"" << sAction << "\" ): this = " << this << " m_pTDEAccelBase = " << m_pTDEAccelBase << endl; + + int iAction = actionIndex( sAction ); + if( iAction < 0 ) + return false; + + if( m_pTDEAccelBase ) + m_pTDEAccelBase->slotRemoveAction( m_prgActions[iAction] ); + delete m_prgActions[iAction]; + + for( uint i = iAction; i < m_nSize - 1; i++ ) + m_prgActions[i] = m_prgActions[i+1]; + m_nSize--; + + return true; +} + +bool TDEAccelActions::readActions( const TQString& sConfigGroup, TDEConfigBase* pConfig ) +{ + TDEAccelShortcutList accelList(*this, false); + return accelList.readSettings( sConfigGroup, pConfig ); +} + +/* + 1) TDEAccelAction = "Something" + 1) KKeySequence = "Meta+X,Asterisk" + 1) TDEAccelSequence = "Meta+X" + 1) KKeySequence = Meta+X + 2) TDEAccelSequence = "Asterisk" + 1) KKeySequence = Shift+8 (English layout) + 2) KKeySequence = Keypad_Asterisk + 2) KKeySequence = "Alt+F2" + 1) TDEAccelSequence = "Alt+F2" + 1) KKeySequence = Alt+F2 + -> "Something=Meta+X,Asterisk;Alt+F2" +*/ +bool TDEAccelActions::writeActions( const TQString &sGroup, TDEConfigBase* pConfig, + bool bWriteAll, bool bGlobal ) const +{ + kdDebug(125) << "TDEAccelActions::writeActions( " << sGroup << ", " << pConfig << ", " << bWriteAll << ", " << bGlobal << " )" << endl; + if( !pConfig ) + pConfig = TDEGlobal::config(); + TDEConfigGroupSaver cs( pConfig, sGroup ); + + for( uint i = 0; i < m_nSize; i++ ) { + if( m_prgActions[i] == 0 ) { + kdWarning(125) << "TDEAccelActions::writeActions(): encountered null pointer at m_prgActions[" << i << "]" << endl; + continue; + } + const TDEAccelAction& action = *m_prgActions[i]; + + TQString s; + bool bConfigHasAction = !pConfig->readEntry( action.m_sName ).isEmpty(); + bool bSameAsDefault = true; + bool bWriteAction = false; + + if( action.m_bConfigurable ) { + s = action.toStringInternal(); + bSameAsDefault = (action.m_cut == action.shortcutDefault()); + + //if( bWriteAll && s.isEmpty() ) + if( s.isEmpty() ) + s = "none"; + + // If we're using a global config or this setting + // differs from the default, then we want to write. + if( bWriteAll || !bSameAsDefault ) + bWriteAction = true; + + if( bWriteAction ) { + kdDebug(125) << "\twriting " << action.m_sName << " = " << s << endl; + // Is passing bGlobal irrelevant, since if it's true, + // then we're using the global config anyway? --ellis + pConfig->writeEntry( action.m_sName, s, true, bGlobal ); + } + // Otherwise, this key is the same as default + // but exists in config file. Remove it. + else if( bConfigHasAction ) { + kdDebug(125) << "\tremoving " << action.m_sName << " because == default" << endl; + pConfig->deleteEntry( action.m_sName, bGlobal ); + } + + } + } + + pConfig->sync(); + return true; +} + +void TDEAccelActions::emitKeycodeChanged() +{ + if( m_pTDEAccelBase ) + m_pTDEAccelBase->emitSignal( TDEAccelBase::KEYCODE_CHANGED ); +} + +uint TDEAccelActions::count() const + { return m_nSize; } diff --git a/tdecore/tdeaccelaction.h b/tdecore/tdeaccelaction.h new file mode 100644 index 000000000..809533ff8 --- /dev/null +++ b/tdecore/tdeaccelaction.h @@ -0,0 +1,576 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001,2002 Ellis Whitehead + + This library 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. + + 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 _KACCELACTION_H +#define _KACCELACTION_H + +#include +#include +#include +#include + +#include + +class TDEAccelBase; + +class TQObject; +class TDEConfig; +class TDEConfigBase; + +/** + * @internal + * A TDEAccelAction prepresents an action that can be executed using + * an accelerator key. Each TDEAccelAction has a name, a label, a + * "What's this" string and a TDEShortcut. The user can configure and + * enable/disable them using KKeyDialog. + * + * \code + * 1) TDEAccelAction = "Run Command" + * Default3 = "Alt+F2" + * Default4 = "Meta+Enter;Alt+F2" + * 1) TDEShortcut = "Meta+Enter" + * 1) KKeySequence = "Meta+Enter" + * 1) KKey = "Meta+Enter" + * 1) Meta+Enter + * 2) Meta+Keypad_Enter + * 2) TDEShortcut = "Alt+F2" + * 1) KKeySequence = "Alt+F2" + * 1) Alt+F2 + * 2) TDEAccelAction = "Something" + * Default3 = "" + * Default4 = "" + * 1) TDEShortcut = "Meta+X,Asterisk" + * 1) KKeySequence = "Meta+X,Asterisk" + * 1) KKey = "Meta+X" + * 1) Meta+X + * 2) KKey = "Asterisk" + * 1) Shift+8 (English layout) + * 2) Keypad_Asterisk + * \endcode + * @short An accelerator action + * @see TDEAccel + * @see TDEGlobalAccel + * @see KKeyChooser + * @see KKeyDialog + */ +class TDECORE_EXPORT TDEAccelAction +{ + public: + /** + * Creates an empty TDEAccelAction. + * @see clear() + */ + TDEAccelAction(); + + /** + * Copy constructor. + */ + TDEAccelAction( const TDEAccelAction& ); + + /** + * Creates a new TDEAccelAction. + * @param sName the name of the accelerator + * @param sLabel the label of the accelerator (i18n!) + * @param sWhatsThis the What's This text (18n!) + * @param cutDef3 the default shortcut for 3 modifier systems + * @param cutDef4 the default shortcut for 4 modifier systems + * @param pObjSlot the receiver of a signal when the key has been + * pressed + * @param psMethodSlot the slot to connect for key presses. Receives + * an int, as set by setID(), as only argument + * @param bConfigurable if true the user can configure the shortcut + * @param bEnabled true if the accelerator should be enabled + */ + TDEAccelAction( const TQString& sName, const TQString& sLabel, const TQString& sWhatsThis, + const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ); + ~TDEAccelAction(); + + /** + * Clears the accelerator. + */ + void clear(); + + /** + * Re-initialized the TDEAccelAction. + * @param sName the name of the accelerator + * @param sLabel the label of the accelerator (i18n!) + * @param sWhatsThis the What's This text (18n!) + * @param cutDef3 the default shortcut for 3 modifier systems + * @param cutDef4 the default shortcut for 4 modifier systems + * @param pObjSlot the receiver of a signal when the key has been + * pressed + * @param psMethodSlot the slot to connect for key presses. Receives + * an int, as set by setID(), as only argument + * @param bConfigurable if true the user can configure the shortcut + * @param bEnabled true if the accelerator should be enabled + * @return true if successful, false otherwise + */ + bool init( const TQString& sName, const TQString& sLabel, const TQString& sWhatsThis, + const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ); + + /** + * Copies this TDEAccelAction. + */ + TDEAccelAction& operator=( const TDEAccelAction& ); + + /** + * Returns the name of the accelerator action. + * @return the name of the accelerator action, can be null if not + * set + */ + const TQString& name() const { return m_sName; } + + /** + * Returns the label of the accelerator action. + * @return the label of the accelerator action, can be null if + * not set + */ + const TQString& label() const { return m_sLabel; } + + /** + * Returns the What's This text of the accelerator action. + * @return the What's This text of the accelerator action, can be + * null if not set + */ + const TQString& whatsThis() const { return m_sWhatsThis; } + + /** + * The shortcut that is actually used (may be used configured). + * @return the shortcut of the TDEAccelAction, can be null if not set + * @see shortcutDefault() + */ + const TDEShortcut& shortcut() const { return m_cut; } + + /** + * The default shortcut for this system. + * @return the default shortcut on this system, can be null if not set + * @see shortcut() + * @see shortcutDefault3() + * @see shortcutDefault4() + */ + const TDEShortcut& shortcutDefault() const; + + /** + * The default shortcut for 3 modifier systems. + * @return the default shortcut for 3 modifier systems, can be null + * if not set + * @see shortcutDefault() + * @see shortcutDefault4() + * @see useFourModifierKeys() + */ + const TDEShortcut& shortcutDefault3() const { return m_cutDefault3; } + + /** + * The default shortcut for 4 modifier systems. + * @return the default shortcut for 4 modifier systems, can be null + * if not set + * @see shortcutDefault() + * @see shortcutDefault3() + * @see useFourModifierKeys() + */ + const TDEShortcut& shortcutDefault4() const { return m_cutDefault4; } + + /** + * Returns the receiver of signals. + * @return the receiver of signals (can be 0 if not set) + */ + const TQObject* objSlotPtr() const { return m_pObjSlot; } + + /** + * Returns the slot for the signal. + * @return the slot for the signal + */ + const char* methodSlotPtr() const { return m_psMethodSlot; } + + /** + * Checks whether the user can configure the action. + * @return true if configurable, false otherwise + */ + bool isConfigurable() const { return m_bConfigurable; } + + /** + * Checks whether the action is enabled. + * @return true if enabled, false otherwise + */ + bool isEnabled() const { return m_bEnabled; } + + /** + * Sets the name of the accelerator action. + * @param name the new name + */ + void setName( const TQString& name ); + + /** + * Sets the user-readable label of the accelerator action. + * @param label the new label (i18n!) + */ + void setLabel( const TQString& label ); + + /** + * Sets the What's This text for the accelerator action. + * @param whatsThis the new What's This text (i18n!) + */ + void setWhatsThis( const TQString& whatsThis ); + + /** + * Sets the new shortcut of the accelerator action. + * @param rgCuts the shortcut to set + * @return true if successful, false otherwise + */ + bool setShortcut( const TDEShortcut& rgCuts ); + + /** + * Sets the slot of the accelerator action. + * @param pObjSlot the receiver object of the signal + * @param psMethodSlot the slot for the signal + */ + void setSlot( const TQObject* pObjSlot, const char* psMethodSlot ); + + /** + * Enables or disabled configuring the action. + * @param configurable true to enable configurability, false to disable + */ + void setConfigurable( bool configurable ); + + /** + * Enables or disabled the action. + * @param enable true to enable the action, false to disable + */ + void setEnabled( bool enable ); + + /** + * Retrieves the id set using setID. + * @return the id of the accelerator action + */ + int getID() const { return m_nIDAccel; } + + /** + * Allows you to set an id that will be used as the action + * signal's argument. + * + * @param n the new id + * @see getID() + */ + void setID( int n ) { m_nIDAccel = n; } + + /** + * Checkes whether the action is connected (emits signals). + * @return true if connected, false otherwise + */ + bool isConnected() const; + + /** + * Sets a key sequence of the action's shortcut. + * @param i the position of the sequence + * @param keySeq the new new sequence + * @return true if successful, false otherwise + * @see TDEShortcut::setSeq() + */ + bool setKeySequence( uint i, const KKeySequence &keySeq ); + + /** + * Clears the action's shortcut. It will not contain any sequences after + * calling this method. + * @see TDEShortcut::clear() + */ + void clearShortcut(); + + /** + * Checks whether the action's shortcut contains the given key sequence. + * @param keySeq the key sequence to check + * @return true if the shortcut contains the given sequence + * @see TDEShortcut::contains() + */ + bool contains( const KKeySequence &keySeq ); + + /** + * Returns the string representation of the action's shortcut. + * @return the string representation of the action's shortcut. + * @see TDEShortcut::toString() + */ + TQString toString() const; + + /** + * @internal + */ + TQString toStringInternal() const; + + /** + * Returns true if four modifier keys will be used. + * @return true if four modifier keys will be used. + */ + static bool useFourModifierKeys(); + + /** + * Selects 3 or 4 modifier default shortcuts. + * @param use true to use 4 modifier shortcuts, false to use + * 3 modifier shortcuts + */ + static void useFourModifierKeys( bool use ); + + protected: + TQString m_sName /**< Name of accel. @sa setName() */, + m_sLabel /**< Label of accel. User-visible. */, + m_sWhatsThis /**< WhatsThis help for accel. User-visible. */; + TDEShortcut m_cut /**< Shortcut actually assigned. */; + TDEShortcut m_cutDefault3 /**< Default shortcut in 3-modifier layout */, + m_cutDefault4 /**< Default shortcur in 4-modifier layout */; + const TQObject* m_pObjSlot /**< Object we will send signals to. */; + const char* m_psMethodSlot /**< Slot we send signals to, in m_pObjSlot */; + bool m_bConfigurable /**< Can this accel be configured by the user? */, + m_bEnabled /**< Is this accel enabled? */; + int m_nIDAccel /**< Id of this accel, from the list of IDs */; + uint m_nConnections /**< Number of connections to this accel. */ ; + + /** @internal Increment the number of connections to this accel. */ + void incConnections(); + /** @internal Decrement the number of connections to this accel (bouded by zero). */ + void decConnections(); + + private: + static int g_bUseFourModifierKeys; + class TDEAccelActionPrivate* d; + + friend class TDEAccelActions; + friend class TDEAccelBase; +}; + +//--------------------------------------------------------------------- +// TDEAccelActions +//--------------------------------------------------------------------- + +/** + * @internal + * This class represents a collection of TDEAccelAction objects. + * + * @short A collection of accelerator actions + * @see TDEAccelAction + */ +class TDECORE_EXPORT TDEAccelActions +{ + public: + /** + * Creates a new, empty TDEAccelActions object. + */ + TDEAccelActions(); + + /** + * Copy constructor (deep copy). + */ + TDEAccelActions( const TDEAccelActions& ); + virtual ~TDEAccelActions(); + + /** + * Removes all items from this collection. + */ + void clear(); + + /** + * Initializes this object with the given actions. + * It will make a deep copy of all actions. + * @param actions the actions to copy + * @return true if successful, false otherwise + */ + bool init( const TDEAccelActions &actions ); + + /** + * Loads the actions from the given configuration file. + * + * @param config the configuration file to load from + * @param sGroup the group in the configuration file + * @return true if successful, false otherwise + */ + bool init( TDEConfigBase& config, const TQString& sGroup ); + + /** + * Updates the shortcuts of all actions in this object + * with the shortcuts from the given object. + * @param shortcuts the collection that contains the new + * shortcuts + */ + void updateShortcuts( TDEAccelActions &shortcuts ); + + /** + * Retrieves the index of the action with the given name. + * @param sAction the action to search + * @return the index of the action, or -1 if not found + */ + int actionIndex( const TQString& sAction ) const; + + /** + * Returns the action with the given @p index. + * @param index the index of an action. You must not + * use an index that is too high. + * @return the TDEAccelAction with the given index + * @see count() + */ + TDEAccelAction* actionPtr( uint index ); + + /** + * Returns the action with the given @p index. + * @param index the index of an action. You must not + * use an index that is too high. + * @return the TDEAccelAction with the given index + * @see count() + */ + const TDEAccelAction* actionPtr( uint index ) const; + + /** + * Returns the action with the given name. + * @param sAction the name of the action to search + * @return the TDEAccelAction with the given name, or 0 + * if not found + */ + TDEAccelAction* actionPtr( const TQString& sAction ); + + /** + * Returns the action with the given name. + * @param sAction the name of the action to search + * @return the TDEAccelAction with the given name, or 0 + * if not found + */ + const TDEAccelAction* actionPtr( const TQString& sAction ) const; + + /** + * Returns the action with the given key sequence. + * @param cut the sequence to search for + * @return the TDEAccelAction with the given sequence, or 0 + * if not found + */ + TDEAccelAction* actionPtr( KKeySequence cut ); + + /** + * Returns the action with the given @p index. + * @param index the index of an action. You must not + * use an index that is too high. + * @return the TDEAccelAction with the given index + * @see actionPtr() + * @see count() + */ + TDEAccelAction& operator []( uint index ); + + /** + * Returns the action with the given @p index. + * @param index the index of an action. You must not + * use an index that is too high. + * @return the TDEAccelAction with the given index + * @see actionPtr() + * @see count() + */ + const TDEAccelAction& operator []( uint index ) const; + + /** + * Inserts an action into the collection. + * @param sAction the name of the accelerator + * @param sLabel the label of the accelerator (i18n!) + * @param sWhatsThis the What's This text (18n!) + * @param rgCutDefaults3 the default shortcut for 3 modifier systems + * @param rgCutDefaults4 the default shortcut for 4 modifier systems + * @param pObjSlot the receiver of a signal when the key has been + * pressed + * @param psMethodSlot the slot to connect for key presses. Receives + * an int, as set by setID(), as only argument + * @param bConfigurable if true the user can configure the shortcut + * @param bEnabled if true the accelerator should be enabled + * @return the new action + */ + TDEAccelAction* insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, + const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4, + const TQObject* pObjSlot = 0, const char* psMethodSlot = 0, + bool bConfigurable = true, bool bEnabled = true ); + + /** + * Inserts an action into the collection. + * @param sName the name of the accelerator + * @param sLabel the label of the accelerator (i18n!) + * @return the new action + */ + TDEAccelAction* insert( const TQString& sName, const TQString& sLabel ); + + /** + * Removes the given action. + * @param sAction the name of the action. + * @return true if successful, false otherwise + */ + bool remove( const TQString& sAction ); + + /** + * Loads the actions from the given configuration file. + * + * @param sConfigGroup the group in the configuration file + * @param pConfig the configuration file to load from + * @return true if successful, false otherwise + */ + bool readActions( const TQString& sConfigGroup = "Shortcuts", TDEConfigBase* pConfig = 0 ); + + /** + * Writes the actions to the given configuration file. + * + * @param sConfigGroup the group in the configuration file + * @param pConfig the configuration file to save to + * @param bWriteAll true to write all actions + * @param bGlobal true to write to the global configuration file + * @return true if successful, false otherwise + */ + bool writeActions( const TQString& sConfigGroup = "Shortcuts", TDEConfigBase* pConfig = 0, + bool bWriteAll = false, bool bGlobal = false ) const; + + /** + * Emit a keycodeChanged signal. + */ + void emitKeycodeChanged(); + + /** + * Returns the number of actions in the collection. + * @return the number of actions + */ + uint count() const; + + protected: + /** Base object that proxies signals from us. */ + TDEAccelBase* m_pTDEAccelBase; + /** Array of actions we're hanging on to. */ + TDEAccelAction** m_prgActions; + uint m_nSizeAllocated /**< Allocated size of the array. */, + m_nSize /**< Amount in use. */ ; + + /** + * Resize the list to the given number @p new_size of entries. + * @todo Can you make it smaller? + * @todo Implementation seems to break m_nSize. + */ + void resize( uint new_size ); + /** Add a action to this collection. @todo Document ownership. */ + void insertPtr( TDEAccelAction* ); + + private: + class TDEAccelActionsPrivate* d; + + TDEAccelActions( TDEAccelBase* ); + void initPrivate( TDEAccelBase* ); + TDEAccelActions& operator =( TDEAccelActions& ); + + friend class TDEAccelBase; +}; + +#endif // _KACCELACTION_H diff --git a/tdecore/tdeaccelbase.cpp b/tdecore/tdeaccelbase.cpp new file mode 100644 index 000000000..235803134 --- /dev/null +++ b/tdecore/tdeaccelbase.cpp @@ -0,0 +1,616 @@ +/* + Copyright (C) 1997-2000 Nicolas Hadacek + Copyright (C) 1998 Mark Donohoe + Copyright (C) 1998 Matthias Ettrich + Copyright (c) 2001,2002 Ellis Whitehead + + This library 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. + + 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. +*/ + +#include "kaccelbase.h" + +#include +#include +#include + +#include +#include "kckey.h" +#include +#include +#include +#include "kkeyserver.h" +#include +#include "kshortcutmenu.h" + +//--------------------------------------------------------------------- +// class TDEAccelBase::ActionInfo +//--------------------------------------------------------------------- + +//--------------------------------------------------------------------- +// class TDEAccelBase +//--------------------------------------------------------------------- + +TDEAccelBase::TDEAccelBase( int fInitCode ) +: m_rgActions( this ) +{ + kdDebug(125) << "TDEAccelBase(): this = " << this << endl; + m_bNativeKeys = fInitCode & NATIVE_KEYS; + m_bEnabled = true; + m_sConfigGroup = "Shortcuts"; + m_bConfigIsGlobal = false; + m_bAutoUpdate = false; + mtemp_pActionRemoving = 0; +} + +TDEAccelBase::~TDEAccelBase() +{ + kdDebug(125) << "~TDEAccelBase(): this = " << this << endl; +} + +uint TDEAccelBase::actionCount() const { return m_rgActions.count(); } +TDEAccelActions& TDEAccelBase::actions() { return m_rgActions; } +bool TDEAccelBase::isEnabled() const { return m_bEnabled; } +// see TDEGlobalAccel::blockShortcuts() stuff - it's to temporarily block +// all global shortcuts, so that the key grabs are released, but from the app's +// point of view the TDEGlobalAccel is still enabled, so TDEGlobalAccel needs +// to disable key grabbing even if enabled +bool TDEAccelBase::isEnabledInternal() const { return isEnabled(); } + +TDEAccelAction* TDEAccelBase::actionPtr( const TQString& sAction ) + { return m_rgActions.actionPtr( sAction ); } + +const TDEAccelAction* TDEAccelBase::actionPtr( const TQString& sAction ) const + { return m_rgActions.actionPtr( sAction ); } + +TDEAccelAction* TDEAccelBase::actionPtr( const KKeyServer::Key& key ) +{ + if( !m_mapKeyToAction.contains( key ) ) + return 0; + // Note: If more than one action is connected to a single key, nil will be returned. + return m_mapKeyToAction[key].pAction; +} + +TDEAccelAction* TDEAccelBase::actionPtr( const KKey& key ) +{ + KKeyServer::Key k2; + k2.init( key, !m_bNativeKeys ); + return actionPtr( k2 ); +} + +void TDEAccelBase::setConfigGroup( const TQString& sConfigGroup ) + { m_sConfigGroup = sConfigGroup; } + +void TDEAccelBase::setConfigGlobal( bool global ) + { m_bConfigIsGlobal = global; } + +bool TDEAccelBase::setActionEnabled( const TQString& sAction, bool bEnable ) +{ + TDEAccelAction* pAction = actionPtr( sAction ); + if( pAction ) { + if( pAction->m_bEnabled != bEnable ) { + kdDebug(125) << "TDEAccelBase::setActionEnabled( " << sAction << ", " << bEnable << " )" << endl; + pAction->m_bEnabled = bEnable; + if( m_bAutoUpdate ) { + // FIXME: the action may already have it's connections inserted! + if( bEnable ) + insertConnection( pAction ); + else if( pAction->isConnected() ) + removeConnection( pAction ); + } + } + return true; + } + return false; +} + +bool TDEAccelBase::setAutoUpdate( bool bAuto ) +{ + kdDebug(125) << "TDEAccelBase::setAutoUpdate( " << bAuto << " ): m_bAutoUpdate on entrance = " << m_bAutoUpdate << endl; + bool b = m_bAutoUpdate; + if( !m_bAutoUpdate && bAuto ) + updateConnections(); + m_bAutoUpdate = bAuto; + return b; +} + +TDEAccelAction* TDEAccelBase::insert( const TQString& sAction, const TQString& sDesc, const TQString& sHelp, + const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable, bool bEnabled ) +{ + //kdDebug(125) << "TDEAccelBase::insert() begin" << endl; + TDEAccelAction* pAction = m_rgActions.insert( + sAction, sDesc, sHelp, + rgCutDefaults3, rgCutDefaults4, + pObjSlot, psMethodSlot, + bConfigurable, bEnabled ); + + if( pAction && m_bAutoUpdate ) + insertConnection( pAction ); + + //kdDebug(125) << "TDEAccelBase::insert() end" << endl; + return pAction; +} + +TDEAccelAction* TDEAccelBase::insert( const TQString& sName, const TQString& sDesc ) + { return m_rgActions.insert( sName, sDesc ); } + +bool TDEAccelBase::remove( const TQString& sAction ) +{ + return m_rgActions.remove( sAction ); +} + +void TDEAccelBase::slotRemoveAction( TDEAccelAction* pAction ) +{ + removeConnection( pAction ); +} + +bool TDEAccelBase::setActionSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ) +{ + kdDebug(125) << "TDEAccelBase::setActionSlot( " << sAction << ", " << pObjSlot << ", " << psMethodSlot << " )\n"; + TDEAccelAction* pAction = m_rgActions.actionPtr( sAction ); + if( pAction ) { + // If there was a previous connection, remove it. + if( m_bAutoUpdate && pAction->isConnected() ) { + kdDebug(125) << "\tm_pObjSlot = " << pAction->m_pObjSlot << " m_psMethodSlot = " << pAction->m_psMethodSlot << endl; + removeConnection( pAction ); + } + + pAction->m_pObjSlot = pObjSlot; + pAction->m_psMethodSlot = psMethodSlot; + + // If we're setting a connection, + if( m_bAutoUpdate && pObjSlot && psMethodSlot ) + insertConnection( pAction ); + + return true; + } else + return false; +} + +/* +TDEAccelBase + Run Command=Meta+Enter;Alt+F2 + TDEAccelAction = "Run Command" + 1) TDEAccelKeySeries = "Meta+Enter" + 1a) Meta+Enter + 1b) Meta+Keypad_Enter + 2) TDEAccelKeySeries = "Alt+F2" + 1a) Alt+F2 + + Konqueror=Meta+I,I + TDEAccelAction = "Konqueror" + 1) TDEAccelKeySeries = "Meta+I,I" + 1a) Meta+I + 2a) I + + Something=Meta+Asterisk,X + TDEAccelAction = "Something" + 1) TDEAccelKeySeries = "Meta+Asterisk,X" + 1a) Meta+Shift+8 + 1b) Meta+Keypad_8 + 2a) X + +read in a config entry + split by ';' + find key sequences to disconnect + find new key sequences to connect +check for conflicts with implicit keys + disconnect conflicting implicit keys +connect new key sequences +*/ +/* +{ + For { + for( TDEAccelAction::iterator itAction = m_rgActions.begin(); itAction != m_rgActions.end(); ++itAction ) { + TDEAccelAction& action = *itAction; + for( TDEAccelSeries::iterator itSeries = action.m_rgSeries.begin(); itSeries != action.m_rgSeries.end(); ++itSeries ) { + TDEAccelSeries& series = *itSeries; + if( + } + } + } + Sort by: iVariation, iSequence, iSeries, iAction + + 1) TDEAccelAction = "Run Command" + 1) TDEAccelKeySeries = "Meta+Enter" + 1a) Meta+Enter + 1b) Meta+Keypad_Enter + 2) TDEAccelKeySeries = "Alt+F2" + 1a) Alt+F2 + + 2) TDEAccelAction = "Enter Calculation" + 1) TDEAccelKeySeries = "Meta+Keypad_Enter" + 1a) Meta+Keypad_Enter + + List = + Meta+Enter -> 1, 1, 1a + Meta+Keypad_Enter -> 2, 1, 1a + Alt+F2 -> 1, 2, 1a + [Meta+Keypad_Enter] -> [1, 1, 1b] + +} +*/ + +#ifdef Q_WS_X11 +struct TDEAccelBase::X +{ + uint iAction, iSeq, iVari; + KKeyServer::Key key; + + X() {} + X( uint _iAction, uint _iSeq, uint _iVari, const KKeyServer::Key& _key ) + { iAction = _iAction; iSeq = _iSeq; iVari = _iVari; key = _key; } + + int compare( const X& x ) + { + int n = key.compare( x.key ); + if( n != 0 ) return n; + if( iVari != x.iVari ) return iVari - x.iVari; + if( iSeq != x.iSeq ) return iSeq - x.iSeq; + return 0; + } + + bool operator <( const X& x ) { return compare( x ) < 0; } + bool operator >( const X& x ) { return compare( x ) > 0; } + bool operator <=( const X& x ) { return compare( x ) <= 0; } +}; +#endif //Q_WS_X11 + +/* +#1 Ctrl+A +#2 Ctrl+A +#3 Ctrl+B + ------ + Ctrl+A => Null + Ctrl+B => #3 + +#1 Ctrl+A +#1 Ctrl+B;Ctrl+A + ------ + Ctrl+A => #1 + Ctrl+B => #2 + +#1 Ctrl+A +#1 Ctrl+B,C +#1 Ctrl+B,D + ------ + Ctrl+A => #1 + Ctrl+B => Null + +#1 Ctrl+A +#2 Ctrl+Plus(Ctrl+KP_Add) + ------ + Ctrl+A => #1 + Ctrl+Plus => #2 + Ctrl+KP_Add => #2 + +#1 Ctrl+Plus(Ctrl+KP_Add) +#2 Ctrl+KP_Add + ------ + Ctrl+Plus => #1 + Ctrl+KP_Add => #2 + +#1 Ctrl+Plus(Ctrl+KP_Add) +#2 Ctrl+A;Ctrl+KP_Add + ------ + Ctrl+A => #2 + Ctrl+Plus => #1 + Ctrl+KP_Add => #2 +*/ + +bool TDEAccelBase::updateConnections() +{ +#ifdef Q_WS_X11 + kdDebug(125) << "TDEAccelBase::updateConnections() this = " << this << endl; + // Retrieve the list of keys to be connected, sorted by priority. + // (key, variation, seq) + TQValueVector rgKeys; + createKeyList( rgKeys ); + m_rgActionsNonUnique.clear(); + + KKeyToActionMap mapKeyToAction; + for( uint i = 0; i < rgKeys.size(); i++ ) { + X& x = rgKeys[i]; + KKeyServer::Key& key = x.key; + ActionInfo info; + bool bNonUnique = false; + + info.pAction = m_rgActions.actionPtr( x.iAction ); + info.iSeq = x.iSeq; + info.iVariation = x.iVari; + + // If this is a multi-key shortcut, + if( info.pAction->shortcut().seq(info.iSeq).count() > 1 ) + bNonUnique = true; + // If this key is requested by more than one action, + else if( i < rgKeys.size() - 1 && key == rgKeys[i+1].key ) { + // If multiple actions requesting this key + // have the same priority as the first one, + if( info.iVariation == rgKeys[i+1].iVari && info.iSeq == rgKeys[i+1].iSeq ) + bNonUnique = true; + + kdDebug(125) << "key conflict = " << key.key().toStringInternal() + << " action1 = " << info.pAction->name() + << " action2 = " << m_rgActions.actionPtr( rgKeys[i+1].iAction )->name() + << " non-unique = " << bNonUnique << endl; + + // Skip over the other records with this same key. + while( i < rgKeys.size() - 1 && key == rgKeys[i+1].key ) + i++; + } + + if( bNonUnique ) { + // Remove connection to single action if there is one + if( m_mapKeyToAction.contains( key ) ) { + TDEAccelAction* pAction = m_mapKeyToAction[key].pAction; + if( pAction ) { + m_mapKeyToAction.remove( key ); + disconnectKey( *pAction, key ); + pAction->decConnections(); + m_rgActionsNonUnique.append( pAction ); + } + } + // Indicate that no single action is associated with this key. + m_rgActionsNonUnique.append( info.pAction ); + info.pAction = 0; + } + + //kdDebug(125) << "mapKeyToAction[" << key.toStringInternal() << "] = " << info.pAction << endl; + mapKeyToAction[key] = info; + } + + // Disconnect keys which no longer have bindings: + for( KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); it != m_mapKeyToAction.end(); ++it ) { + const KKeyServer::Key& key = it.key(); + TDEAccelAction* pAction = (*it).pAction; + // If this key is longer used or it points to a different action now, + if( !mapKeyToAction.contains( key ) || mapKeyToAction[key].pAction != pAction ) { + if( pAction ) { + disconnectKey( *pAction, key ); + pAction->decConnections(); + } else + disconnectKey( key ); + } + } + + // Connect any unconnected keys: + // In other words, connect any keys which are present in the + // new action map, but which are _not_ present in the old one. + for( KKeyToActionMap::iterator it = mapKeyToAction.begin(); it != mapKeyToAction.end(); ++it ) { + const KKeyServer::Key& key = it.key(); + TDEAccelAction* pAction = (*it).pAction; + if( !m_mapKeyToAction.contains( key ) || m_mapKeyToAction[key].pAction != pAction ) { + // TODO: Decide what to do if connect fails. + // Probably should remove this item from map. + if( pAction ) { + if( connectKey( *pAction, key ) ) + pAction->incConnections(); + } else + connectKey( key ); + } + } + + // Store new map. + m_mapKeyToAction = mapKeyToAction; + +#ifndef NDEBUG + for( KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); it != m_mapKeyToAction.end(); ++it ) { + kdDebug(125) << "Key: " << it.key().key().toStringInternal() << " => '" + << (((*it).pAction) ? (*it).pAction->name() : TQString::null) << "'" << endl; + } +#endif +#endif //Q_WS_X11 + return true; +} + +#ifdef Q_WS_X11 +// Construct a list of keys to be connected, sorted highest priority first. +void TDEAccelBase::createKeyList( TQValueVector& rgKeys ) +{ + //kdDebug(125) << "TDEAccelBase::createKeyList()" << endl; + if( !isEnabledInternal()) + return; + + // create the list + // For each action + for( uint iAction = 0; iAction < m_rgActions.count(); iAction++ ) { + TDEAccelAction* pAction = m_rgActions.actionPtr( iAction ); + if( pAction && pAction->m_pObjSlot && pAction->m_psMethodSlot && pAction != mtemp_pActionRemoving ) { + // For each key sequence associated with action + for( uint iSeq = 0; iSeq < pAction->shortcut().count(); iSeq++ ) { + const KKeySequence& seq = pAction->shortcut().seq(iSeq); + if( seq.count() > 0 ) { + KKeyServer::Variations vars; + vars.init( seq.key(0), !m_bNativeKeys ); + for( uint iVari = 0; iVari < vars.count(); iVari++ ) { + if( vars.key(iVari).code() && vars.key(iVari).sym() ) + rgKeys.push_back( X( iAction, iSeq, iVari, vars.key( iVari ) ) ); + //kdDebug(125) << "\t" << pAction->name() << ": " << vars.key(iVari).toStringInternal() << endl; + } + } + //else + // kdDebug(125) << "\t*" << pAction->name() << ":" << endl; + } + } + } + + // sort by priority: iVariation[of first key], iSequence, iAction + qHeapSort( rgKeys.begin(), rgKeys.end() ); +} +#endif //Q_WS_X11 + +bool TDEAccelBase::insertConnection( TDEAccelAction* pAction ) +{ + if( !pAction->m_pObjSlot || !pAction->m_psMethodSlot ) + return true; + + kdDebug(125) << "TDEAccelBase::insertConnection( " << pAction << "=\"" << pAction->m_sName << "\"; shortcut = " << pAction->shortcut().toStringInternal() << " ) this = " << this << endl; + + // For each sequence associated with the given action: + for( uint iSeq = 0; iSeq < pAction->shortcut().count(); iSeq++ ) { + // Get the first key of the sequence. + KKeyServer::Variations vars; + vars.init( pAction->shortcut().seq(iSeq).key(0), !m_bNativeKeys ); + for( uint iVari = 0; iVari < vars.count(); iVari++ ) { + const KKeyServer::Key& key = vars.key( iVari ); + + //if( !key.isNull() ) { + if( key.sym() ) { + if( !m_mapKeyToAction.contains( key ) ) { + // If this is a single-key shortcut, + if( pAction->shortcut().seq(iSeq).count() == 1 ) { + m_mapKeyToAction[key] = ActionInfo( pAction, iSeq, iVari ); + if( connectKey( *pAction, key ) ) + pAction->incConnections(); + } + // Else this is a multi-key shortcut, + else { + m_mapKeyToAction[key] = ActionInfo( 0, 0, 0 ); + // Insert into non-unique list if it's not already there. + if( m_rgActionsNonUnique.findIndex( pAction ) == -1 ) + m_rgActionsNonUnique.append( pAction ); + if( connectKey( key ) ) + pAction->incConnections(); + } + } else { + // There is a key conflict. A full update + // check is necessary. + // TODO: make this more efficient where possible. + if( m_mapKeyToAction[key].pAction != pAction + && m_mapKeyToAction[key].pAction != 0 ) { + kdDebug(125) << "Key conflict with action = " << m_mapKeyToAction[key].pAction->name() + << " key = " << key.key().toStringInternal() << " : call updateConnections()" << endl; + return updateConnections(); + } + } + } + } + } + + //kdDebug(125) << "\tActions = " << m_rgActions.size() << endl; + //for( TDEAccelActions::const_iterator it = m_rgActions.begin(); it != m_rgActions.end(); ++it ) { + // kdDebug(125) << "\t" << &(*it) << " '" << (*it).m_sName << "'" << endl; + //} + + //kdDebug(125) << "\tKeys = " << m_mapKeyToAction.size() << endl; + //for( KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); it != m_mapKeyToAction.end(); ++it ) { + // //kdDebug(125) << "\tKey: " << it.key().toString() << " => '" << (*it)->m_sName << "'" << endl; + // kdDebug(125) << "\tKey: " << it.key().toString() << " => '" << *it << "'" << endl; + // kdDebug(125) << "\t\t'" << (*it)->m_sName << "'" << endl; + //} + + return true; +} + +bool TDEAccelBase::removeConnection( TDEAccelAction* pAction ) +{ + kdDebug(125) << "TDEAccelBase::removeConnection( " << pAction << " = \"" << pAction->m_sName << "\"; shortcut = " << pAction->m_cut.toStringInternal() << " ): this = " << this << endl; + + //for( KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); it != m_mapKeyToAction.end(); ++it ) + // kdDebug(125) << "\tKey: " << it.key().toString() << " => '" << (*it)->m_sName << "'" << " " << *it << endl; + + if( m_rgActionsNonUnique.findIndex( pAction ) >= 0 ) { + mtemp_pActionRemoving = pAction; + bool b = updateConnections(); + mtemp_pActionRemoving = 0; + return b; + } + + KKeyToActionMap::iterator it = m_mapKeyToAction.begin(); + while( it != m_mapKeyToAction.end() ) { + KKeyServer::Key key = it.key(); + ActionInfo* pInfo = &(*it); + + // If the given action is connected to this key, + if( pAction == pInfo->pAction ) { + disconnectKey( *pAction, key ); + pAction->decConnections(); + + KKeyToActionMap::iterator itRemove = it++; + m_mapKeyToAction.remove( itRemove ); + } else + ++it; + } + return true; +} + +bool TDEAccelBase::setShortcut( const TQString& sAction, const TDEShortcut& cut ) +{ + TDEAccelAction* pAction = actionPtr( sAction ); + if( pAction ) { + if( m_bAutoUpdate ) + removeConnection( pAction ); + + pAction->setShortcut( cut ); + + if( m_bAutoUpdate && !pAction->shortcut().isNull() ) + insertConnection( pAction ); + return true; + } else + return false; +} + +void TDEAccelBase::readSettings( TDEConfigBase* pConfig ) +{ + m_rgActions.readActions( m_sConfigGroup, pConfig ); + if( m_bAutoUpdate ) + updateConnections(); +} + +void TDEAccelBase::writeSettings( TDEConfigBase* pConfig ) const +{ + m_rgActions.writeActions( m_sConfigGroup, pConfig, m_bConfigIsGlobal, m_bConfigIsGlobal ); +} + +TQPopupMenu* TDEAccelBase::createPopupMenu( TQWidget* pParent, const KKeySequence& seq ) +{ + TDEShortcutMenu* pMenu = new TDEShortcutMenu( pParent, &actions(), seq ); + + bool bActionInserted = false; + bool bInsertSeparator = false; + for( uint i = 0; i < actionCount(); i++ ) { + const TDEAccelAction* pAction = actions().actionPtr( i ); + + if( !pAction->isEnabled() ) + continue; + + // If an action has already been inserted into the menu + // and we have a label instead of an action here, + // then indicate that we should insert a separator before the next menu entry. + if( bActionInserted && !pAction->isConfigurable() && pAction->name().contains( ':' ) ) + bInsertSeparator = true; + + for( uint iSeq = 0; iSeq < pAction->shortcut().count(); iSeq++ ) { + const KKeySequence& seqAction = pAction->shortcut().seq(iSeq); + if( seqAction.startsWith( seq ) ) { + if( bInsertSeparator ) { + pMenu->insertSeparator(); + bInsertSeparator = false; + } + + pMenu->insertAction( i, seqAction ); + + //kdDebug(125) << "sLabel = " << sLabel << ", seq = " << (TQString)seqMenu.qt() << ", i = " << i << endl; + //kdDebug(125) << "pMenu->accel(" << i << ") = " << (TQString)pMenu->accel(i) << endl; + bActionInserted = true; + break; + } + } + } + pMenu->updateShortcuts(); + return pMenu; +} diff --git a/tdecore/tdeaccelbase.h b/tdecore/tdeaccelbase.h new file mode 100644 index 000000000..3d7180c4f --- /dev/null +++ b/tdecore/tdeaccelbase.h @@ -0,0 +1,282 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001 Ellis Whitehead + + This library 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. + + 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 _KACCELBASE_H +#define _KACCELBASE_H + +#include +#include +#include +#include +#include + +#include "kaccelaction.h" +#include "kkeyserver.h" + +class TQPopupMenu; +class TQWidget; + +//---------------------------------------------------- + +/** + * @internal + * Handle keyboard accelerators. + * + * Allow an user to configure + * key bindings through application configuration files or through the + * KKeyChooser GUI. + * + * A TDEAccel contains a list of accelerator items. Each accelerator item + * consists of an action name and a keyboard code combined with modifiers + * (Shift, Ctrl and Alt.) + * + * For example, "Ctrl+P" could be a shortcut for printing a document. The key + * codes are listed in ckey.h. "Print" could be the action name for printing. + * The action name identifies the key binding in configuration files and the + * KKeyChooser GUI. + * + * When pressed, an accelerator key calls the slot to which it has been + * connected. Accelerator items can be connected so that a key will activate + * two different slots. + * + * A TDEAccel object handles key events sent to its parent widget and to all + * children of this parent widget. + * + * Key binding reconfiguration during run time can be prevented by specifying + * that an accelerator item is not configurable when it is inserted. A special + * group of non-configurable key bindings are known as the + * standard accelerators. + * + * The standard accelerators appear repeatedly in applications for + * standard document actions such as printing and saving. Convenience methods are + * available to insert and connect these accelerators which are configurable on + * a desktop-wide basis. + * + * It is possible for a user to choose to have no key associated with + * an action. + * + * The translated first argument for insertItem() is used only + * in the configuration dialog. + *\code + * TDEAccel *a = new TDEAccel( myWindow ); + * // Insert an action "Scroll Up" which is associated with the "Up" key: + * a->insertItem( i18n("Scroll Up"), "Scroll Up", "Up" ); + * // Insert an action "Scroll Down" which is not associated with any key: + * a->insertItem( i18n("Scroll Down"), "Scroll Down", 0); + * a->connectItem( "Scroll up", myWindow, TQT_SLOT( scrollUp() ) ); + * // a->insertStdItem( TDEStdAccel::Print ); //not necessary, since it + * // is done automatially with the + * // connect below! + * a->connectItem(TDEStdAccel::Print, myWindow, TQT_SLOT( printDoc() ) ); + * + * a->readSettings(); + *\endcode + * + * If a shortcut has a menu entry as well, you could insert them like + * this. The example is again the TDEStdAccel::Print from above. + * + * \code + * int id; + * id = popup->insertItem("&Print",this, TQT_SLOT(printDoc())); + * a->changeMenuAccel(popup, id, TDEStdAccel::Print ); + * \endcode + * + * If you want a somewhat "exotic" name for your standard print action, like + * id = popup->insertItem(i18n("Print &Document"),this, TQT_SLOT(printDoc())); + * it might be a good idea to insert the standard action before as + * a->insertStdItem( TDEStdAccel::Print, i18n("Print Document") ) + * as well, so that the user can easily find the corresponding function. + * + * This technique works for other actions as well. Your "scroll up" function + * in a menu could be done with + * + * \code + * id = popup->insertItem(i18n"Scroll &up",this, TQT_SLOT(scrollUp())); + * a->changeMenuAccel(popup, id, "Scroll Up" ); + * \endcode + * + * Please keep the order right: First insert all functions in the + * acceleratior, then call a -> readSettings() and @em then build your + * menu structure. + * + * @short Configurable key binding support. + */ + +class TDECORE_EXPORT TDEAccelBase +{ + public: + /** Initialization mode of the TDEAccelBase, used in constructor. */ + enum Init { QT_KEYS = 0x00, NATIVE_KEYS = 0x01 }; + + /** Enum for kinds of signals which may be emitted. */ + enum Signal { KEYCODE_CHANGED }; + + /** Constructor. @p fInitCode should be a bitwise OR of + * values from the Init enum. + */ + TDEAccelBase( int fInitCode ); + virtual ~TDEAccelBase(); + + /** Returns number of actions in this handler. */ + uint actionCount() const; + /** Returns a list of all the actions in this handler. */ + TDEAccelActions& actions(); + /** Returns whether this accelerator handler is enabled or not. */ + bool isEnabled() const; + + /** Returns a pointer to the TDEAccelAction named @p sAction. */ + TDEAccelAction* actionPtr( const TQString& sAction ); + /** Const version of the above. */ + const TDEAccelAction* actionPtr( const TQString& sAction ) const; + /** Returns a pointer to the TDEAccelAction associated with + * the key @p key. This function takes into account the + * key mapping defined in the constructor. + * + * May return 0 if no (or more than one) + * action is associated with the key. + */ + TDEAccelAction* actionPtr( const KKey& key ); + /** Basically the same as above, except a KKeyServer::Key + * already has a key mapping defined (either NATIVE_KEYS or not). + */ + TDEAccelAction* actionPtr( const KKeyServer::Key& key ); + + /** Returns the name of the configuration group these + * accelerators are stored in. The default is "Shortcuts". + */ + const TQString& configGroup() const { return m_sConfigGroup; } + /** Set the group (in the configuration file) for storing + * accelerators. + */ + void setConfigGroup( const TQString& group ); + void setConfigGlobal( bool global ); + /** Enables or disables the accelerator. + * @param bEnabled determines whether the accelerator should be enabled or + * disabled. + */ + virtual void setEnabled( bool bEnabled ) = 0; + /** Returns whether autoupdate is enabled for these accelerators. */ + bool getAutoUpdate() { return m_bAutoUpdate; } + /** Enables (or disables) autoupdate for these accelerators. + * @return the value of autoupdate before the call. + */ + bool setAutoUpdate( bool bAuto ); + +// Procedures for manipulating Actions. + //void clearActions(); + + TDEAccelAction* insert( const TQString& sName, const TQString& sDesc ); + TDEAccelAction* insert( + const TQString& sAction, const TQString& sDesc, const TQString& sHelp, + const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4, + const TQObject* pObjSlot, const char* psMethodSlot, + bool bConfigurable = true, bool bEnabled = true ); + bool remove( const TQString& sAction ); + bool setActionSlot( const TQString& sAction, const TQObject* pObjSlot, const char* psMethodSlot ); + + bool updateConnections(); + + bool setShortcut( const TQString& sAction, const TDEShortcut& cut ); + +// Modify individual Action sub-items + bool setActionEnabled( const TQString& sAction, bool bEnable ); + + /** + * Read all key associations from @p config, or (if @p config + * is zero) from the application's configuration file + * TDEGlobal::config(). + * + * The group in which the configuration is stored can be + * set with setConfigGroup(). + */ + void readSettings( TDEConfigBase* pConfig = 0 ); + + /** + * Write the current configurable associations to @p config, + * or (if @p config is zero) to the application's + * configuration file. + */ + void writeSettings( TDEConfigBase* pConfig = 0 ) const; + + TQPopupMenu* createPopupMenu( TQWidget* pParent, const KKeySequence& ); + + // Protected methods + protected: + void slotRemoveAction( TDEAccelAction* ); + + struct X; + + /** Constructs a list of keys to be connected, sorted highest priority first. + * @param rgKeys constructed list of keys + */ + void createKeyList( TQValueVector& rgKeys ); + bool insertConnection( TDEAccelAction* ); + bool removeConnection( TDEAccelAction* ); + + /** Emits a signal. + * @param signal signal to be emitted + */ + virtual bool emitSignal( Signal signal ) = 0; + /** Defines a key which activates the accelerator and executes the action + * @param action action to be executed when key is pressed + * @param key key which causes the action to be executed + */ + virtual bool connectKey( TDEAccelAction& action, const KKeyServer::Key& key ) = 0; + /** Defines a key which activates the accelerator + * @param key key which causes the action to be executed + */ + virtual bool connectKey( const KKeyServer::Key& key) = 0; + /** Removes the key from accelerator so it no longer executes the action + */ + virtual bool disconnectKey( TDEAccelAction&, const KKeyServer::Key& ) = 0; + /** Removes the key from accelerator + */ + virtual bool disconnectKey( const KKeyServer::Key& ) = 0; + + protected: + virtual bool isEnabledInternal() const; + struct ActionInfo + { + TDEAccelAction* pAction; + uint iSeq, iVariation; + //ActionInfo* pInfoNext; // nil if only one action uses this key. + + ActionInfo() { pAction = 0; iSeq = 0xffff; iVariation = 0xffff; } + ActionInfo( TDEAccelAction* _pAction, uint _iSeq, uint _iVariation ) + { pAction = _pAction; iSeq = _iSeq; iVariation = _iVariation; } + }; + typedef TQMap KKeyToActionMap; + + TDEAccelActions m_rgActions; + KKeyToActionMap m_mapKeyToAction; + TQValueList m_rgActionsNonUnique; + bool m_bNativeKeys; // Use native key codes instead of Qt codes + bool m_bEnabled; + bool m_bConfigIsGlobal; + TQString m_sConfigGroup; + bool m_bAutoUpdate; + TDEAccelAction* mtemp_pActionRemoving; + + private: + TDEAccelBase& operator =( const TDEAccelBase& ); + + friend class TDEAccelActions; +}; + +#endif // _KACCELBASE_H diff --git a/tdecore/tdeaccelmanager.cpp b/tdecore/tdeaccelmanager.cpp new file mode 100644 index 000000000..9ac4dbdae --- /dev/null +++ b/tdecore/tdeaccelmanager.cpp @@ -0,0 +1,872 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Matthias H�lzer-Kl�pfel + + This library 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. + + 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. +*/ + +#include "kaccelmanager.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +#include "kaccelmanager_private.h" +#include "../tdeui/kstdaction_p.h" +#include "../tdeutils/tdemultitabbar.h" + + +/********************************************************************* + + class Item - helper class containing widget information + + This class stores information about the widgets the need accelerators, + as well as about their relationship. + + *********************************************************************/ + + + +/********************************************************************* + + class TDEAcceleratorManagerPrivate - internal helper class + + This class does all the work to find accelerators for a hierarchy of + widgets. + + *********************************************************************/ + + +class TDEAcceleratorManagerPrivate +{ +public: + + static void manage(TQWidget *widget); + static bool programmers_mode; + static bool standardName(const TQString &str); + + static bool checkChange(const TDEAccelString &as) { + TQString t2 = as.accelerated(); + TQString t1 = as.originalText(); + if (t1 != t2) + { + if (as.accel() == -1) { + removed_string += "" + TQStyleSheet::escape(t1) + ""; + } else if (as.originalAccel() == -1) { + added_string += "" + TQStyleSheet::escape(t2) + ""; + } else { + changed_string += "" + TQStyleSheet::escape(t1) + ""; + changed_string += "" + TQStyleSheet::escape(t2) + ""; + } + return true; + } + return false; + } + static TQString changed_string; + static TQString added_string; + static TQString removed_string; + static TQMap ignored_widgets; + +private: + class Item; +public: + typedef TQPtrList ItemList; + +private: + static void traverseChildren(TQWidget *widget, Item *item); + + static void manageWidget(TQWidget *widget, Item *item); + static void manageMenuBar(TQMenuBar *mbar, Item *item); + static void manageTabBar(TQTabBar *bar, Item *item); + + static void calculateAccelerators(Item *item, TQString &used); + + class Item + { + public: + + Item() : m_widget(0), m_children(0), m_index(-1) {} + ~Item(); + + void addChild(Item *item); + + TQWidget *m_widget; + TDEAccelString m_content; + ItemList *m_children; + int m_index; + + }; +}; + + +bool TDEAcceleratorManagerPrivate::programmers_mode = false; +TQString TDEAcceleratorManagerPrivate::changed_string; +TQString TDEAcceleratorManagerPrivate::added_string; +TQString TDEAcceleratorManagerPrivate::removed_string; +static TQStringList *kaccmp_sns = 0; +static KStaticDeleter kaccmp_sns_d; +TQMap TDEAcceleratorManagerPrivate::ignored_widgets; + +bool TDEAcceleratorManagerPrivate::standardName(const TQString &str) +{ + if (!kaccmp_sns) + kaccmp_sns_d.setObject(kaccmp_sns, new TQStringList(KStdAction::internal_stdNames())); + return kaccmp_sns->contains(str); +} + +TDEAcceleratorManagerPrivate::Item::~Item() +{ + delete m_children; +} + + +void TDEAcceleratorManagerPrivate::Item::addChild(Item *item) +{ + if (!m_children) { + m_children = new ItemList; + m_children->setAutoDelete(true); + } + + m_children->append(item); +} + +void TDEAcceleratorManagerPrivate::manage(TQWidget *widget) +{ + if (!widget) + { + kdDebug(131) << "null pointer given to manage" << endl; + return; + } + + if (dynamic_cast(widget)) + { + // create a popup accel manager that can deal with dynamic menus + TDEPopupAccelManager::manage(static_cast(widget)); + return; + } + + Item *root = new Item; + + manageWidget(widget, root); + + TQString used; + calculateAccelerators(root, used); + delete root; +} + + +void TDEAcceleratorManagerPrivate::calculateAccelerators(Item *item, TQString &used) +{ + if (!item->m_children) + return; + + // collect the contents + TDEAccelStringList contents; + for (Item *it = item->m_children->first(); it != 0; + it = item->m_children->next()) + { + contents << it->m_content; + } + + // find the right accelerators + TDEAccelManagerAlgorithm::findAccelerators(contents, used); + + // write them back into the widgets + int cnt = -1; + for (Item *it = item->m_children->first(); it != 0; + it = item->m_children->next()) + { + cnt++; + + TQTabBar *tabBar = dynamic_cast(it->m_widget); + if (tabBar) + { + if (checkChange(contents[cnt])) + tabBar->tabAt(it->m_index)->setText(contents[cnt].accelerated()); + continue; + } + TQMenuBar *menuBar = dynamic_cast(it->m_widget); + if (menuBar) + { + if (it->m_index >= 0) + { + TQMenuItem *mitem = menuBar->findItem(menuBar->idAt(it->m_index)); + if (mitem) + { + checkChange(contents[cnt]); + mitem->setText(contents[cnt].accelerated()); + } + continue; + } + } + // we possibly reserved an accel, but we won't set it as it looks silly + if ( dynamic_cast( it->m_widget ) ) + continue; + // links look weird with ampersands + if ( dynamic_cast( it->m_widget ) && it->m_widget->inherits("KURLLabel") ) + continue; + + int tprop = it->m_widget->metaObject()->findProperty("text", true); + if (tprop != -1) { + if (checkChange(contents[cnt])) + it->m_widget->setProperty("text", contents[cnt].accelerated()); + } else { + tprop = it->m_widget->metaObject()->findProperty("title", true); + if (tprop != -1 && checkChange(contents[cnt])) + it->m_widget->setProperty("title", contents[cnt].accelerated()); + } + } + + // calculate the accelerators for the children + for (Item *it = item->m_children->first(); it != 0; + it = item->m_children->next()) + { + if (it->m_widget && it->m_widget->isVisibleTo( item->m_widget ) ) + calculateAccelerators(it, used); + } +} + + +void TDEAcceleratorManagerPrivate::traverseChildren(TQWidget *widget, Item *item) +{ + TQObjectList *childList = widget->queryList(TQWIDGET_OBJECT_NAME_STRING, 0, false, false); + for ( TQObject *it = childList->first(); it; it = childList->next() ) + { + TQWidget *w = TQT_TQWIDGET(it); + + if ( !w->isVisibleTo( widget ) || ( w->isTopLevel() && dynamic_cast(w) == NULL ) ) + continue; + + if ( TDEAcceleratorManagerPrivate::ignored_widgets.find( w ) != TDEAcceleratorManagerPrivate::ignored_widgets.end() ) + continue; + + manageWidget(w, item); + } + delete childList; +} + +void TDEAcceleratorManagerPrivate::manageWidget(TQWidget *w, Item *item) +{ + // first treat the special cases + + TQTabBar *tabBar = dynamic_cast(w); + if (tabBar) + { + manageTabBar(tabBar, item); + return; + } + + TQWidgetStack *wds = dynamic_cast( w ); + if ( wds ) + { + QWidgetStackAccelManager::manage( wds ); + // return; + } + + TQPopupMenu *popupMenu = dynamic_cast(w); + if (popupMenu) + { + // create a popup accel manager that can deal with dynamic menus + TDEPopupAccelManager::manage(popupMenu); + return; + } + + TQWidgetStack *wdst = dynamic_cast( w ); + if ( wdst ) + { + QWidgetStackAccelManager::manage( wdst ); + // return; + } + + TQMenuBar *menuBar = dynamic_cast(w); + if (menuBar) + { + manageMenuBar(menuBar, item); + return; + } + + if (dynamic_cast(w) || dynamic_cast(w) || + dynamic_cast(w) || dynamic_cast(w) || + dynamic_cast(w) || static_cast(w->tqt_cast("KMultiTabBar"))) + return; + + // now treat 'ordinary' widgets + TQLabel *label = dynamic_cast(w); + if ( label ) { + if ( !label->buddy() ) + label = 0; + else { + if ( label->textFormat() == Qt::RichText || + ( label->textFormat() == Qt::AutoText && + TQStyleSheet::mightBeRichText( label->text() ) ) ) + label = 0; + } + } + + if (w->isFocusEnabled() || label || dynamic_cast(w) || dynamic_cast( w )) + { + TQString content; + TQVariant variant; + int tprop = w->metaObject()->findProperty("text", true); + if (tprop != -1) { + const TQMetaProperty* p = w->metaObject()->property( tprop, true ); + if ( p && p->isValid() ) + w->tqt_property( tprop, 1, &variant ); + else + tprop = -1; + } + + if (tprop == -1) { + tprop = w->metaObject()->findProperty("title", true); + if (tprop != -1) { + const TQMetaProperty* p = w->metaObject()->property( tprop, true ); + if ( p && p->isValid() ) + w->tqt_property( tprop, 1, &variant ); + } + } + + if (variant.isValid()) + content = variant.toString(); + + if (!content.isEmpty()) + { + Item *i = new Item; + i->m_widget = w; + + // put some more weight on the usual action elements + int weight = TDEAccelManagerAlgorithm::DEFAULT_WEIGHT; + if (dynamic_cast(w) || dynamic_cast(w) || dynamic_cast(w) || dynamic_cast(w)) + weight = TDEAccelManagerAlgorithm::ACTION_ELEMENT_WEIGHT; + + // don't put weight on group boxes, as usually the contents are more important + if (dynamic_cast(w)) + weight = TDEAccelManagerAlgorithm::GROUP_BOX_WEIGHT; + + // put a lot of extra weight on the KDialogBaseButton's + if (w->inherits("KDialogBaseButton")) + weight += TDEAccelManagerAlgorithm::DIALOG_BUTTON_EXTRA_WEIGHT; + + i->m_content = TDEAccelString(content, weight); + item->addChild(i); + } + } + traverseChildren(w, item); +} + +void TDEAcceleratorManagerPrivate::manageTabBar(TQTabBar *bar, Item *item) +{ + for (int i=0; icount(); i++) + { + TQString content = bar->tabAt(i)->text(); + if (content.isEmpty()) + continue; + + Item *it = new Item; + item->addChild(it); + it->m_widget = bar; + it->m_index = i; + it->m_content = TDEAccelString(content); + } +} + +void TDEAcceleratorManagerPrivate::manageMenuBar(TQMenuBar *mbar, Item *item) +{ + TQMenuItem *mitem; + TQString s; + + for (uint i=0; icount(); ++i) + { + mitem = mbar->findItem(mbar->idAt(i)); + if (!mitem) + continue; + + // nothing to do for separators + if (mitem->isSeparator()) + continue; + + s = mitem->text(); + if (!s.isEmpty()) + { + Item *it = new Item; + item->addChild(it); + it->m_content = + TDEAccelString(s, + // menu titles are important, so raise the weight + TDEAccelManagerAlgorithm::MENU_TITLE_WEIGHT); + + it->m_widget = mbar; + it->m_index = i; + } + + // have a look at the popup as well, if present + if (mitem->popup()) + TDEPopupAccelManager::manage(mitem->popup()); + } +} + + +/********************************************************************* + + class TDEAcceleratorManager - main entry point + + This class is just here to provide a clean public API... + + *********************************************************************/ + +void TDEAcceleratorManager::manage(TQWidget *widget) +{ + TDEAcceleratorManager::manage(widget, false); +} + +void TDEAcceleratorManager::manage(TQWidget *widget, bool programmers_mode) +{ + kdDebug(131) << "TDEAcceleratorManager::manage\n"; + TDEAcceleratorManagerPrivate::changed_string = TQString::null; + TDEAcceleratorManagerPrivate::added_string = TQString::null; + TDEAcceleratorManagerPrivate::removed_string = TQString::null; + TDEAcceleratorManagerPrivate::programmers_mode = programmers_mode; + TDEAcceleratorManagerPrivate::manage(widget); +} + +void TDEAcceleratorManager::last_manage(TQString &added, TQString &changed, TQString &removed) +{ + added = TDEAcceleratorManagerPrivate::added_string; + changed = TDEAcceleratorManagerPrivate::changed_string; + removed = TDEAcceleratorManagerPrivate::removed_string; +} + + +/********************************************************************* + + class TDEAccelString - a string with weighted characters + + *********************************************************************/ + +TDEAccelString::TDEAccelString(const TQString &input, int initialWeight) + : m_pureText(input), m_weight() +{ + m_orig_accel = m_pureText.find("(!)&"); + if (m_orig_accel != -1) + m_pureText.remove(m_orig_accel, 4); + + m_orig_accel = m_pureText.find("(&&)"); + if (m_orig_accel != -1) + m_pureText.replace(m_orig_accel, 4, "&"); + + m_origText = m_pureText; + + if (m_pureText.contains('\t')) + m_pureText = m_pureText.left(m_pureText.find('\t')); + + m_orig_accel = m_accel = stripAccelerator(m_pureText); + + if (initialWeight == -1) + initialWeight = TDEAccelManagerAlgorithm::DEFAULT_WEIGHT; + + calculateWeights(initialWeight); + + // dump(); +} + + +TQString TDEAccelString::accelerated() const +{ + TQString result = m_origText; + if (result.isEmpty()) + return result; + + if (TDEAcceleratorManagerPrivate::programmers_mode) + { + if (m_accel != m_orig_accel) { + int oa = m_orig_accel; + + if (m_accel >= 0) { + result.insert(m_accel, "(!)&"); + if (m_accel < m_orig_accel) + oa += 4; + } + if (m_orig_accel >= 0) + result.replace(oa, 1, "(&&)"); + } + } else { + if (m_accel >= 0 && m_orig_accel != m_accel) { + result.remove(m_orig_accel, 1); + result.insert(m_accel, "&"); + } + } + return result; +} + + +TQChar TDEAccelString::accelerator() const +{ + if ((m_accel < 0) || (m_accel > (int)m_pureText.length())) + return TQChar(); + + return m_pureText[m_accel].lower(); +} + + +void TDEAccelString::calculateWeights(int initialWeight) +{ + m_weight.resize(m_pureText.length()); + + uint pos = 0; + bool start_character = true; + + while (pos= 0) + { + p = text.find('&', p)+1; + + if (p <= 0 || p >= (int)text.length()) + return -1; + + if (text[p] != '&') + { + TQChar c = text[p]; + if (c.isPrint()) + { + text.remove(p-1,1); + return p-1; + } + } + + p++; + } + + return -1; +} + + +int TDEAccelString::maxWeight(int &index, const TQString &used) +{ + int max = 0; + index = -1; + + for (uint pos=0; pos max) + { + max = m_weight[pos]; + index = pos; + } + + return max; +} + + +void TDEAccelString::dump() +{ + TQString s; + for (uint i=0; imax) + { + max = m; + index = i; + accel = a; + } + } + + // stop if no more accelerators can be found + if (index < 0) + return; + + // insert the accelerator + if (accel >= 0) + { + result[index].setAccel(accel); + used.append(result[index].accelerator()); + } + + // make sure we don't visit this one again + accel_strings[index] = TDEAccelString(); + } +} + + +/********************************************************************* + + class TDEPopupAccelManager - managing TQPopupMenu widgets dynamically + + *********************************************************************/ + +TDEPopupAccelManager::TDEPopupAccelManager(TQPopupMenu *popup) + : TQObject(popup), m_popup(popup), m_count(-1) +{ + aboutToShow(); // do one check and then connect to show + connect(popup, TQT_SIGNAL(aboutToShow()), TQT_SLOT(aboutToShow())); +} + + +void TDEPopupAccelManager::aboutToShow() +{ + // Note: we try to be smart and avoid recalculating the accelerators + // whenever possible. Unfortunately, there is no way to know if an + // item has been added or removed, so we can not do much more than + // to compare the items each time the menu is shown :-( + + if (m_count != (int)m_popup->count()) + { + findMenuEntries(m_entries); + calculateAccelerators(); + m_count = m_popup->count(); + } + else + { + TDEAccelStringList entries; + findMenuEntries(entries); + if (entries != m_entries) + { + m_entries = entries; + calculateAccelerators(); + } + } +} + + +void TDEPopupAccelManager::calculateAccelerators() +{ + // find the new accelerators + TQString used; + TDEAccelManagerAlgorithm::findAccelerators(m_entries, used); + + // change the menu entries + setMenuEntries(m_entries); +} + + +void TDEPopupAccelManager::findMenuEntries(TDEAccelStringList &list) +{ + TQMenuItem *mitem; + TQString s; + + list.clear(); + + // read out the menu entries + for (uint i=0; icount(); i++) + { + mitem = m_popup->findItem(m_popup->idAt(i)); + if (mitem->isSeparator()) + continue; + + s = mitem->text(); + + // in full menus, look at entries with global accelerators last + int weight = 50; + if (s.contains('\t')) + weight = 0; + + list.append(TDEAccelString(s, weight)); + + // have a look at the popup as well, if present + if (mitem->popup()) + TDEPopupAccelManager::manage(mitem->popup()); + } +} + + +void TDEPopupAccelManager::setMenuEntries(const TDEAccelStringList &list) +{ + TQMenuItem *mitem; + + uint cnt = 0; + for (uint i=0; icount(); i++) + { + mitem = m_popup->findItem(m_popup->idAt(i)); + if (mitem->isSeparator()) + continue; + + if (TDEAcceleratorManagerPrivate::checkChange(list[cnt])) + mitem->setText(list[cnt].accelerated()); + cnt++; + } +} + + +void TDEPopupAccelManager::manage(TQPopupMenu *popup) +{ + // don't add more than one manager to a popup + if (popup->child(0, "TDEPopupAccelManager", false) == 0 ) + new TDEPopupAccelManager(popup); +} + +void QWidgetStackAccelManager::manage( TQWidgetStack *stack ) +{ + if ( stack->child( 0, "QWidgetStackAccelManager", false ) == 0 ) + new QWidgetStackAccelManager( stack ); +} + +QWidgetStackAccelManager::QWidgetStackAccelManager(TQWidgetStack *stack) + : TQObject(stack), m_stack(stack) +{ + aboutToShow(stack->visibleWidget()); // do one check and then connect to show + connect(stack, TQT_SIGNAL(aboutToShow(TQWidget *)), TQT_SLOT(aboutToShow(TQWidget *))); +} + +bool QWidgetStackAccelManager::eventFilter ( TQObject * watched, TQEvent * e ) +{ + if ( e->type() == TQEvent::Show && tqApp->activeWindow() ) { + TDEAcceleratorManager::manage( TQT_TQWIDGET(tqApp->activeWindow()) ); + watched->removeEventFilter( this ); + } + return false; +} + +void QWidgetStackAccelManager::aboutToShow(TQWidget *child) +{ + if (!child) + { + kdDebug(131) << "null pointer given to aboutToShow" << endl; + return; + } + + child->installEventFilter( this ); +} + +void TDEAcceleratorManager::setNoAccel( TQWidget *widget ) +{ + TDEAcceleratorManagerPrivate::ignored_widgets[widget] = 1; +} + +#include "kaccelmanager_private.moc" diff --git a/tdecore/tdeaccelmanager.h b/tdecore/tdeaccelmanager.h new file mode 100644 index 000000000..03ee627b3 --- /dev/null +++ b/tdecore/tdeaccelmanager.h @@ -0,0 +1,88 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Matthias Hoelzer-Kluepfel + + This library 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. + + 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 __K_ACCELMANAGER_H__ +#define __K_ACCELMANAGER_H__ + + +class TQWidget; +class TQString; + +#include + +/** + * KDE Accelerator manager. + * + * This class can be used to find a valid and working set of + * accelerators for any widget. + * + * @author Matthias Hoelzer-Kluepfel + * @since 3.1 +*/ + +class TDECORE_EXPORT TDEAcceleratorManager +{ +public: + + /** + * Manages the accelerators of a widget. + * + * Call this function on the top widget of the hierarchy you + * want to manage. It will fix the accelerators of the child widgets so + * there are never duplicate accelerators. It also tries to put + * accelerators on as many widgets as possible. + * + * The algorithm used tries to take the existing accelerators into + * account, as well as the class of each widget. Hopefully, the result + * is close to what you would assign manually. + * + * QPopupMenu's are managed dynamically, so when you add or remove entries, + * the accelerators are reassigned. If you add or remove widgets to your + * toplevel widget, you will have to call manage again to fix the + * accelerators. + * + * @param widget The toplevel widget you want to manage. + */ + + static void manage(TQWidget *widget); + + /** + * Does the same as the above function, but puts hints in the GUI so the + * programmer can enhance his program. + * + * TODO KDE4: merge with the above + * @param widget The toplevel widget you want to manage. + * @param programmers_mode if true, TDEAcceleratorManager adds (&) for removed + * accels and & before added accels + */ + static void manage(TQWidget *widget, bool programmers_mode); + + /** \internal returns the result of the last manage operation. */ + static void last_manage(TQString &added, TQString &changed, TQString &removed); + + /** + * Use this method for a widget (and its children) you want no accels to be set on. + * @since 3.4 + */ + static void setNoAccel( TQWidget *widget ); +}; + + +#endif diff --git a/tdecore/tdeaccelmanager_private.h b/tdecore/tdeaccelmanager_private.h new file mode 100644 index 000000000..ed401801e --- /dev/null +++ b/tdecore/tdeaccelmanager_private.h @@ -0,0 +1,196 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Matthias Hoelzer-Kluepfel + + This library 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. + + 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 __KACCELMANAGER_PRIVATE_H__ +#define __KACCELMANAGER_PRIVATE_H__ + + +#include +#include +#include +#include + +class TQWidgetStack; + +/** + * A string class handling accelerators. + * + * This class contains a string and knowledge about accelerators. + * It keeps a list weights, telling how valuable each character + * would be as an accelerator. + * + * @author Matthias Hoelzer-Kluepfel +*/ + +class TDEAccelString +{ +public: + + TDEAccelString() : m_pureText(), m_accel(-1) {} + TDEAccelString(const TQString &input, int initalWeight=-1); + + void calculateWeights(int initialWeight); + + const TQString &pure() const { return m_pureText; } + TQString accelerated() const; + + int accel() const { return m_accel; } + void setAccel(int accel) { m_accel = accel; } + + int originalAccel() const { return m_orig_accel; } + TQString originalText() const { return m_origText; } + + TQChar accelerator() const; + + int maxWeight(int &index, const TQString &used); + + bool operator == (const TDEAccelString &c) const { return m_pureText == c.m_pureText && m_accel == c.m_accel && m_orig_accel == c.m_orig_accel; } + + +private: + + int stripAccelerator(TQString &input); + + void dump(); + + TQString m_pureText, m_origText; + int m_accel, m_orig_accel; + TQMemArray m_weight; + +}; + + +typedef TQValueList TDEAccelStringList; + + +/** + * This class encapsulates the algorithm finding the 'best' + * distribution of accelerators in a hierarchy of widgets. + * + * @author Matthias Hoelzer-Kluepfel +*/ + +class TDEAccelManagerAlgorithm +{ +public: + + /// Constants used in the algorithm + enum { + /// Default control weight + DEFAULT_WEIGHT = 50, + /// Additional weight for first character in string + FIRST_CHARACTER_EXTRA_WEIGHT = 50, + /// Additional weight for the beginning of a word + WORD_BEGINNING_EXTRA_WEIGHT = 50, + /// Additional weight for the dialog buttons (large, we basically never want these reassigned) + DIALOG_BUTTON_EXTRA_WEIGHT = 300, + /// Additional weight for a 'wanted' accelerator + WANTED_ACCEL_EXTRA_WEIGHT = 150, + /// Default weight for an 'action' widget (ie, pushbuttons) + ACTION_ELEMENT_WEIGHT = 50, + /// Default weight for group boxes (low priority) + GROUP_BOX_WEIGHT = -2000, + /// Default weight for menu titles + MENU_TITLE_WEIGHT = 250, + /// Additional weight for KDE standard accelerators + STANDARD_ACCEL = 300 + }; + + /// Method to call to find the best distribution of accelerators. + static void findAccelerators(TDEAccelStringList &result, TQString &used); + +}; + + +class TQPopupMenu; + + +/** + * This class manages a popup menu. It will notice if entries have been + * added or changed, and will recalculate the accelerators accordingly. + * + * This is necessary for dynamic menus like for example in kicker. + * + * @author Matthias Hoelzer-Kluepfel +*/ + +class TDEPopupAccelManager : public TQObject +{ + Q_OBJECT + +public: + + static void manage(TQPopupMenu *popup); + + +protected: + + TDEPopupAccelManager(TQPopupMenu *popup); + + +private slots: + + void aboutToShow(); + + +private: + + void calculateAccelerators(); + + void findMenuEntries(TDEAccelStringList &list); + void setMenuEntries(const TDEAccelStringList &list); + + TQPopupMenu *m_popup; + TDEAccelStringList m_entries; + int m_count; + +}; + + +class QWidgetStackAccelManager : public TQObject +{ + Q_OBJECT + +public: + + static void manage(TQWidgetStack *popup); + + +protected: + + QWidgetStackAccelManager(TQWidgetStack *popup); + + +private slots: + + void aboutToShow(TQWidget *); + bool eventFilter ( TQObject * watched, TQEvent * e ); + +private: + + void calculateAccelerators(); + + TQWidgetStack *m_stack; + TDEAccelStringList m_entries; + +}; + + +#endif diff --git a/tdecore/tdeaccelprivate.h b/tdecore/tdeaccelprivate.h new file mode 100644 index 000000000..0d967998d --- /dev/null +++ b/tdecore/tdeaccelprivate.h @@ -0,0 +1,53 @@ +#ifndef __KACCELPRIVATE_H +#define __KACCELPRIVATE_H + +#include "kkeyserver_x11.h" +#include + +class TDEAccelAction; + +/** + * @internal + */ +class TDECORE_EXPORT TDEAccelPrivate : public TQObject, public TDEAccelBase +{ + Q_OBJECT + public: + TDEAccel* m_pAccel; + TQWidget* m_pWatch; + TQMap m_mapIDToKey; + TQMap m_mapIDToAction; + TQTimer m_timerShowMenu; + + TDEAccelPrivate( TDEAccel* pParent, TQWidget* pWatch ); + + virtual void setEnabled( bool bEnabled ); + + bool setEnabled( const TQString& sAction, bool bEnable ); + + virtual bool removeAction( const TQString& sAction ); + + virtual bool emitSignal( TDEAccelBase::Signal signal ); + virtual bool connectKey( TDEAccelAction& action, const KKeyServer::Key& key ); + virtual bool connectKey( const KKeyServer::Key& key ); + virtual bool disconnectKey( TDEAccelAction& action, const KKeyServer::Key& key ); + virtual bool disconnectKey( const KKeyServer::Key& key ); + + signals: + void menuItemActivated(); + void menuItemActivated(TDEAccelAction*); + + private: +#ifndef Q_WS_WIN /** @todo TEMP: new implementation (commit #424926) didn't work */ + void emitActivatedSignal(TDEAccelAction*); +#endif + + private slots: + void slotKeyPressed( int id ); + void slotShowMenu(); + void slotMenuActivated( int iAction ); + + bool eventFilter( TQObject* pWatched, TQEvent* pEvent ); // virtual method from QObject +}; + +#endif // !__KACCELPRIVATE_H diff --git a/tdecore/tdeshortcut.cpp b/tdecore/tdeshortcut.cpp new file mode 100644 index 000000000..ae568d5b7 --- /dev/null +++ b/tdecore/tdeshortcut.cpp @@ -0,0 +1,671 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001,2002 Ellis Whitehead + + This library 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. + + 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. +*/ + +#include "kshortcut.h" +#include "kkeynative.h" +#include "kkeyserver.h" + +#include +#include + +#include +#include +#include +#include + +//---------------------------------------------------- + +static KKey* g_pspec = 0; +static KKeySequence* g_pseq = 0; +static TDEShortcut* g_pcut = 0; + +//---------------------------------------------------- +// KKey +//---------------------------------------------------- + +KKey::KKey() { clear(); } +KKey::KKey( uint key, uint modFlags ) { init( key, modFlags ); } +KKey::KKey( int keyQt ) { init( keyQt ); } +KKey::KKey( const TQKeySequence& seq ) { init( seq ); } +KKey::KKey( const TQKeyEvent* pEvent ) { init( pEvent ); } +KKey::KKey( const KKey& key ) { init( key ); } +KKey::KKey( const TQString& sKey ) { init( sKey ); } + +KKey::~KKey() +{ +} + +void KKey::clear() +{ + m_sym = 0; + m_mod = 0; +} + +bool KKey::init( uint key, uint modFlags ) +{ + m_sym = key; + m_mod = modFlags; + return true; +} + +bool KKey::init( int keyQt ) +{ + //KKeyServer::Sym sym; + + //if( sym.initQt( keyQt ) + if( KKeyServer::keyQtToSym( keyQt, m_sym ) + && KKeyServer::keyQtToMod( keyQt, m_mod ) ) + return true; + else { + m_sym = 0; + m_mod = 0; + return false; + } +} + +bool KKey::init( const TQKeySequence& key ) +{ + // TODO: if key.count() > 1, should we return failure? + return init( (int) key ); +} + +bool KKey::init( const TQKeyEvent* pEvent ) +{ + int keyQt = pEvent->key(); + if( pEvent->state() & TQt::ShiftButton ) keyQt |= Qt::SHIFT; + if( pEvent->state() & TQt::ControlButton ) keyQt |= Qt::CTRL; + if( pEvent->state() & TQt::AltButton ) keyQt |= Qt::ALT; + if( pEvent->state() & TQt::MetaButton ) keyQt |= Qt::META; + return init( keyQt ); +} + +bool KKey::init( const KKey& key ) +{ + m_sym = key.m_sym; + m_mod = key.m_mod; + return true; +} + +bool KKey::init( const TQString& sSpec ) +{ + clear(); + + TQString sKey = sSpec.stripWhiteSpace(); + if( sKey.startsWith( "default(" ) && sKey.endsWith( ")" ) ) + sKey = sKey.mid( 8, sKey.length() - 9 ); + // i.e., "Ctrl++" = "Ctrl+Plus" + if( sKey.endsWith( "++" ) ) + sKey = sKey.left( sKey.length() - 1 ) + "plus"; + TQStringList rgs = TQStringList::split( '+', sKey, true ); + + uint i; + // Check for modifier keys first. + for( i = 0; i < rgs.size(); i++ ) { + TQString s = rgs[i].lower(); + if( s == "shift" ) m_mod |= KKey::SHIFT; + else if( s == "ctrl" ) m_mod |= KKey::CTRL; + else if( s == "alt" ) m_mod |= KKey::ALT; + else if( s == "win" ) m_mod |= KKey::WIN; + else if( s == "meta" ) m_mod |= KKey::WIN; + else { + uint m = KKeyServer::stringUserToMod( s ); + if( m != 0 ) m_mod |= m; + else break; + } + } + // If there is one non-blank key left: + if( (i == rgs.size() - 1 && !rgs[i].isEmpty()) ) { + KKeyServer::Sym sym( rgs[i] ); + m_sym = sym.m_sym; + } + + if( m_sym == 0 ) + m_mod = 0; + + kdDebug(125) << "KKey::init( \"" << sSpec << "\" ):" + << " m_sym = " << TQString::number(m_sym, 16) + << ", m_mod = " << TQString::number(m_mod, 16) << endl; + + return m_sym != 0; +} + +bool KKey::isNull() const { return m_sym == 0; } +uint KKey::sym() const { return m_sym; } +uint KKey::modFlags() const { return m_mod; } + +int KKey::compare( const KKey& spec ) const +{ + if( m_sym != spec.m_sym ) + return m_sym - spec.m_sym; + if( m_mod != spec.m_mod ) + return m_mod - spec.m_mod; + return 0; +} + +int KKey::keyCodeQt() const +{ + return KKeyNative( *this ).keyCodeQt(); +} + +TQString KKey::toString() const +{ + TQString s; + + s = KKeyServer::modToStringUser( m_mod ); + if( !s.isEmpty() ) + s += '+'; + s += KKeyServer::Sym(m_sym).toString(); + + return s; +} + +TQString KKey::toStringInternal() const +{ + //kdDebug(125) << "KKey::toStringInternal(): this = " << this + // << " mod = " << TQString::number(m_mod, 16) + // << " key = " << TQString::number(m_sym, 16) << endl; + TQString s; + + s = KKeyServer::modToStringInternal( m_mod ); + if( !s.isEmpty() ) + s += '+'; + s += KKeyServer::Sym(m_sym).toStringInternal(); + return s; +} + +KKey& KKey::null() +{ + if( !g_pspec ) + g_pspec = new KKey; + if( !g_pspec->isNull() ) + g_pspec->clear(); + return *g_pspec; +} + +TQString KKey::modFlagLabel( ModFlag modFlag ) +{ + return KKeyServer::modToStringUser( modFlag ); +} + +//--------------------------------------------------------------------- +// KKeySequence +//--------------------------------------------------------------------- + +KKeySequence::KKeySequence() { clear(); } +KKeySequence::KKeySequence( const TQKeySequence& seq ) { init( seq ); } +KKeySequence::KKeySequence( const KKey& key ) { init( key ); } +KKeySequence::KKeySequence( const KKeySequence& seq ) { init( seq ); } +KKeySequence::KKeySequence( const TQString& s ) { init( s ); } + +KKeySequence::~KKeySequence() +{ +} + +void KKeySequence::clear() +{ + m_nKeys = 0; + m_bTriggerOnRelease = false; +} + +bool KKeySequence::init( const TQKeySequence& seq ) +{ + clear(); + if( !seq.isEmpty() ) { + for( uint i = 0; i < seq.count(); i++ ) { + m_rgvar[i].init( seq[i] ); + if( m_rgvar[i].isNull() ) + return false; + } + m_nKeys = seq.count(); + m_bTriggerOnRelease = false; + } + return true; +} + +bool KKeySequence::init( const KKey& key ) +{ + if( !key.isNull() ) { + m_nKeys = 1; + m_rgvar[0].init( key ); + m_bTriggerOnRelease = false; + } else + clear(); + return true; +} + +bool KKeySequence::init( const KKeySequence& seq ) +{ + m_bTriggerOnRelease = false; + m_nKeys = seq.m_nKeys; + for( uint i = 0; i < m_nKeys; i++ ) { + if( seq.m_rgvar[i].isNull() ) { + kdDebug(125) << "KKeySequence::init( seq ): key[" << i << "] is null." << endl; + m_nKeys = 0; + return false; + } + m_rgvar[i] = seq.m_rgvar[i]; + } + return true; +} + +bool KKeySequence::init( const TQString& s ) +{ + m_bTriggerOnRelease = false; + //kdDebug(125) << "KKeySequence::init( " << s << " )" << endl; + TQStringList rgs = TQStringList::split( ',', s ); + if( s == "none" || rgs.size() == 0 ) { + clear(); + return true; + } else if( rgs.size() <= MAX_KEYS ) { + m_nKeys = rgs.size(); + for( uint i = 0; i < m_nKeys; i++ ) { + m_rgvar[i].init( KKey(rgs[i]) ); + //kdDebug(125) << "\t'" << rgs[i] << "' => " << m_rgvar[i].toStringInternal() << endl; + } + return true; + } else { + clear(); + return false; + } +} + +uint KKeySequence::count() const +{ + return m_nKeys; +} + +const KKey& KKeySequence::key( uint i ) const +{ + if( i < m_nKeys ) + return m_rgvar[i]; + else + return KKey::null(); +} + +bool KKeySequence::isTriggerOnRelease() const + { return m_bTriggerOnRelease; } + +bool KKeySequence::setKey( uint iKey, const KKey& key ) +{ + if( iKey <= m_nKeys && iKey < MAX_KEYS ) { + m_rgvar[iKey].init( key ); + if( iKey == m_nKeys ) + m_nKeys++; + return true; + } else + return false; +} + +bool KKeySequence::isNull() const +{ + return m_nKeys == 0; +} + +bool KKeySequence::startsWith( const KKeySequence& seq ) const +{ + if( m_nKeys < seq.m_nKeys ) + return false; + + for( uint i = 0; i < seq.m_nKeys; i++ ) { + if( m_rgvar[i] != seq.m_rgvar[i] ) + return false; + } + + return true; +} + +int KKeySequence::compare( const KKeySequence& seq ) const +{ + for( uint i = 0; i < m_nKeys && i < seq.m_nKeys; i++ ) { + int ret = m_rgvar[i].compare( seq.m_rgvar[i] ); + if( ret != 0 ) + return ret; + } + if( m_nKeys != seq.m_nKeys ) + return m_nKeys - seq.m_nKeys; + else + return 0; +} + +TQKeySequence KKeySequence::qt() const +{ + int k[4] = { 0, 0, 0, 0 }; + + for( uint i = 0; i < count(); i++ ) + k[i] = KKeyNative(key(i)).keyCodeQt(); + TQKeySequence seq( k[0], k[1], k[2], k[3] ); + return seq; +} + +int KKeySequence::keyCodeQt() const +{ + return (count() == 1) ? KKeyNative(key(0)).keyCodeQt() : 0; +} + +TQString KKeySequence::toString() const +{ + if( m_nKeys < 1 ) return TQString::null; + + TQString s; + s = m_rgvar[0].toString(); + for( uint i = 1; i < m_nKeys; i++ ) { + s += ","; + s += m_rgvar[i].toString(); + } + + return s; +} + +TQString KKeySequence::toStringInternal() const +{ + if( m_nKeys < 1 ) return TQString::null; + + TQString s; + s = m_rgvar[0].toStringInternal(); + for( uint i = 1; i < m_nKeys; i++ ) { + s += ","; + s += m_rgvar[i].toStringInternal(); + } + + return s; +} + +KKeySequence& KKeySequence::null() +{ + if( !g_pseq ) + g_pseq = new KKeySequence; + if( !g_pseq->isNull() ) + g_pseq->clear(); + return *g_pseq; +} + +//--------------------------------------------------------------------- +// TDEShortcut +//--------------------------------------------------------------------- + +TDEShortcut::TDEShortcut() { clear(); } +TDEShortcut::TDEShortcut( int keyQt ) { init( keyQt ); } +TDEShortcut::TDEShortcut( const TQKeySequence& key ) { init( key ); } +TDEShortcut::TDEShortcut( const KKey& key ) { init( key ); } +TDEShortcut::TDEShortcut( const KKeySequence& seq ) { init( seq ); } +TDEShortcut::TDEShortcut( const TDEShortcut& cut ) { init( cut ); } +TDEShortcut::TDEShortcut( const char* ps ) { init( TQString(ps) ); } +TDEShortcut::TDEShortcut( const TQString& s ) { init( s ); } + +TDEShortcut::~TDEShortcut() +{ +} + +void TDEShortcut::clear() +{ + m_nSeqs = 0; +} + +bool TDEShortcut::init( int keyQt ) +{ + if( keyQt ) { + m_nSeqs = 1; + m_rgseq[0].init( TQKeySequence(keyQt) ); + } else + clear(); + return true; +} + +bool TDEShortcut::init( const TQKeySequence& key ) +{ + m_nSeqs = 1; + m_rgseq[0].init( key ); + return true; +} + +bool TDEShortcut::init( const KKey& spec ) +{ + m_nSeqs = 1; + m_rgseq[0].init( spec ); + return true; +} + +bool TDEShortcut::init( const KKeySequence& seq ) +{ + m_nSeqs = 1; + m_rgseq[0] = seq; + return true; +} + +bool TDEShortcut::init( const TDEShortcut& cut ) +{ + m_nSeqs = cut.m_nSeqs; + for( uint i = 0; i < m_nSeqs; i++ ) + m_rgseq[i] = cut.m_rgseq[i]; + return true; +} + +bool TDEShortcut::init( const TQString& s ) +{ + bool bRet = true; + TQStringList rgs = TQStringList::split( ';', s ); + + if( s == "none" || rgs.size() == 0 ) + clear(); + else if( rgs.size() <= MAX_SEQUENCES ) { + m_nSeqs = rgs.size(); + for( uint i = 0; i < m_nSeqs; i++ ) { + TQString& sSeq = rgs[i]; + if( sSeq.startsWith( "default(" ) ) + sSeq = sSeq.mid( 8, sSeq.length() - 9 ); + m_rgseq[i].init( sSeq ); + //kdDebug(125) << "*\t'" << sSeq << "' => " << m_rgseq[i].toStringInternal() << endl; + } + } else { + clear(); + bRet = false; + } + + if( !s.isEmpty() ) { + TQString sDebug; + TQTextStream os( &sDebug, IO_WriteOnly ); + os << "TDEShortcut::init( \"" << s << "\" ): "; + for( uint i = 0; i < m_nSeqs; i++ ) { + os << " m_rgseq[" << i << "]: "; + KKeyServer::Variations vars; + vars.init( m_rgseq[i].key(0), true ); + for( uint j = 0; j < vars.count(); j++ ) + os << TQString::number(vars.m_rgkey[j].keyCodeQt(),16) << ','; + } + kdDebug(125) << sDebug << endl; + } + + return bRet; +} + +uint TDEShortcut::count() const +{ + return m_nSeqs; +} + +const KKeySequence& TDEShortcut::seq( uint i ) const +{ + return (i < m_nSeqs) ? m_rgseq[i] : KKeySequence::null(); +} + +int TDEShortcut::keyCodeQt() const +{ + if( m_nSeqs >= 1 ) + return m_rgseq[0].keyCodeQt(); + return TQKeySequence(); +} + +bool TDEShortcut::isNull() const +{ + return m_nSeqs == 0; +} + +int TDEShortcut::compare( const TDEShortcut& cut ) const +{ + for( uint i = 0; i < m_nSeqs && i < cut.m_nSeqs; i++ ) { + int ret = m_rgseq[i].compare( cut.m_rgseq[i] ); + if( ret != 0 ) + return ret; + } + return m_nSeqs - cut.m_nSeqs; +} + +bool TDEShortcut::contains( const KKey& key ) const +{ + return contains( KKeySequence(key) ); +} + +bool TDEShortcut::contains( const KKeyNative& keyNative ) const +{ + KKey key = keyNative.key(); + key.simplify(); + + for( uint i = 0; i < count(); i++ ) { + if( !m_rgseq[i].isNull() + && m_rgseq[i].count() == 1 + && m_rgseq[i].key(0) == key ) + return true; + } + return false; +} + +bool TDEShortcut::contains( const KKeySequence& seq ) const +{ + for( uint i = 0; i < count(); i++ ) { + if( !m_rgseq[i].isNull() && m_rgseq[i] == seq ) + return true; + } + return false; +} + +bool TDEShortcut::setSeq( uint iSeq, const KKeySequence& seq ) +{ + // TODO: check if seq is null, and act accordingly. + if( iSeq <= m_nSeqs && iSeq < MAX_SEQUENCES ) { + m_rgseq[iSeq] = seq; + if( iSeq == m_nSeqs ) + m_nSeqs++; + return true; + } else + return false; +} + +void TDEShortcut::remove( const KKeySequence& seq ) +{ + if (seq.isNull()) return; + + for( uint iSeq = 0; iSeq < m_nSeqs; iSeq++ ) + { + if (m_rgseq[iSeq] == seq) + { + for( uint jSeq = iSeq + 1; jSeq < m_nSeqs; jSeq++) + m_rgseq[jSeq-1] = m_rgseq[jSeq]; + m_nSeqs--; + } + } +} + +bool TDEShortcut::append( const KKeySequence& seq ) +{ + if( m_nSeqs < MAX_SEQUENCES ) { + if( !seq.isNull() ) { + m_rgseq[m_nSeqs] = seq; + m_nSeqs++; + } + return true; + } else + return false; +} + +bool TDEShortcut::append( const KKey& spec ) +{ + if( m_nSeqs < MAX_SEQUENCES ) { + m_rgseq[m_nSeqs].init( spec ); + m_nSeqs++; + return true; + } else + return false; +} + +bool TDEShortcut::append( const TDEShortcut& cut ) +{ + uint seqs = m_nSeqs, co = cut.count(); + for( uint i=0; i MAX_SEQUENCES ) return false; + + for( uint i=0; i= 1 ) + return m_rgseq[0].qt(); + else + return TQKeySequence(); +} + +TQString TDEShortcut::toString() const +{ + TQString s; + + for( uint i = 0; i < count(); i++ ) { + s += m_rgseq[i].toString(); + if( i < count() - 1 ) + s += ';'; + } + + return s; +} + +TQString TDEShortcut::toStringInternal( const TDEShortcut* pcutDefault ) const +{ + TQString s; + + for( uint i = 0; i < count(); i++ ) { + const KKeySequence& seq = m_rgseq[i]; + if( pcutDefault && i < pcutDefault->count() && seq == (*pcutDefault).seq(i) ) { + s += "default("; + s += seq.toStringInternal(); + s += ")"; + } else + s += seq.toStringInternal(); + if( i < count() - 1 ) + s += ';'; + } + + return s; +} + +TDEShortcut& TDEShortcut::null() +{ + if( !g_pcut ) + g_pcut = new TDEShortcut; + if( !g_pcut->isNull() ) + g_pcut->clear(); + return *g_pcut; +} diff --git a/tdecore/tdeshortcut.h b/tdecore/tdeshortcut.h new file mode 100644 index 000000000..e98a007b5 --- /dev/null +++ b/tdecore/tdeshortcut.h @@ -0,0 +1,851 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001,2002 Ellis Whitehead + + This library 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. + + 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 __KSHORTCUT_H +#define __KSHORTCUT_H + +#include +#include +#include "tdelibs_export.h" + +class TQKeyEvent; +class KKeyNative; + +/** +* A KKey object represents a single key with possible modifiers +* (Shift, Ctrl, Alt, Win). It can represent both keys which are +* understood by Qt as well as those which are additionally supported +* by the underlying system (e.g. X11). +* @see KKeyNative +* @see KKeySequence +* @see TDEShortcut +*/ + +class TDECORE_EXPORT KKey +{ + public: + /** + * The number of flags. + * @see ModFlag + */ + enum { MOD_FLAG_COUNT = 4 }; + enum { QtWIN = (Qt::META) }; + /** + * Flags to represent the modifiers. You can combine modifiers + * by ORing them. + */ + enum ModFlag { + SHIFT = 0x01, + CTRL = 0x02, + ALT = 0x04, + WIN = 0x08 + }; + + /** + * Creates a new null KKey. + * @see clear() + * @see isNull() + * @see null() + */ + KKey(); + + /** + * Creates a new key for the given Qt key code. + * @param keyQt the qt keycode + * @see Qt::Key + */ + KKey( int keyQt ); + + /** + * Creates a new key from the first key code of the given key sequence. + * @param keySeq the key sequence that contains the key + */ + KKey( const TQKeySequence& keySeq ); + + /** + * Extracts the key from the given key event. + * @param keyEvent the key event to get the key from + */ + KKey( const TQKeyEvent* keyEvent ); + + /** + * Copy constructor. + */ + KKey( const KKey& key ); + + /** + * Creates a new key from the given description. The form of the description + * is "[modifier+[modifier+]]+key", for example "e", "CTRL+q" or + * "CTRL+ALT+DEL". Allowed modifiers are "SHIFT", "CTRL", "ALT", "WIN" and + * "META". "WIN" and "META" are equivalent. Modifiers are not case-sensitive. + * @param key the description of the key + * @see KKeyServer::Sym::init() + */ + KKey( const TQString& key ); + /** + * @internal + */ + KKey( uint key, uint mod ); + ~KKey(); + + // Initialization methods + /** + * Clears the key. The key is null after calling this function. + * @see isNull() + */ + void clear(); + + /** + * Initializes the key with the given Qt key code. + * @param keyQt the qt keycode + * @return true if successful, false otherwise + * @see Qt::Key + */ + bool init( int keyQt ); + + /** + * Initializes the key with the first key code of the given key sequence. + * @param keySeq the key sequence that contains the key + * @return true if successful, false otherwise + */ + bool init( const TQKeySequence& keySeq ); + + /** + * Initializes the key by extracting the code from the given key event. + * @param keyEvent the key event to get the key from + * @return true if successful, false otherwise + */ + bool init( const TQKeyEvent* keyEvent ); + + /** + * Copies the given key. + * @param key the key to copy + * @return true if successful, false otherwise + */ + bool init( const KKey& key ); + + /** + * Initializes the key with the given description. The form of the description + * is "[modifier+[modifier+]]+key", for example "e", "CTRL+q" or + * "CTRL+ALT+DEL". Allowed modifiers are "SHIFT", "CTRL", "ALT", "WIN" and + * "META". "WIN" and "META" are equivalent. Modifiers are not case-sensitive. + * @param key the description of the key + * @return true if successful, false otherwise + * @see KKeyServer::Sym::init() + */ + bool init( const TQString& key); + + /** + * @internal + */ + bool init( uint key, uint mod ); + + /** + * Copies the key. + */ + KKey& operator =( const KKey& key ) + { init( key ); return *this; } + + // Query methods. + /** + * Returns true if the key is null (after clear() or empty + * constructor). + * @return true if the key is null + * @see clear() + * @see null() + */ + bool isNull() const; + + /** + * @internal + */ + uint sym() const; + /** + * @internal + */ + uint modFlags() const; + + // Comparison Methods + /** + * Compares this key with the given KKey object. Returns a negative + * number if the given KKey is larger, 0 if they are equal and + * a positive number this KKey is larger. The returned value + * is the difference between the symbol or, if the symbols + * are equal, the difference between the encoded modifiers. + * @param key the key to compare with this key + * @return a negative number if the given KKey is larger, 0 if + * they are equal and a positive number this KKey is larger + */ + int compare( const KKey& key ) const; + + /** + * Compares the symbol and modifiers of both keys. + * @see compare() + */ + bool operator == ( const KKey& key ) const + { return compare( key ) == 0; } + /** + * Compares the symbol and modifiers of both keys. + * @see compare() + */ + bool operator != ( const KKey& key ) const + { return compare( key ) != 0; } + /** + * Compares the symbol and modifiers of both keys. + * @see compare() + */ + bool operator < ( const KKey& key ) const + { return compare( key ) < 0; } + + // Conversion methods. + /** + * Returns the qt key code. + * @return the qt key code or 0 if there is no key set. + * @see Qt::Key + */ + int keyCodeQt() const; + + /** + * Returns a human-readable representation of the key in the form + * "modifier+key". Note that the representation is localised, + * use toStringInternal() for cases like saving to configuration files. + * @return the string representation of the key + * @see toStringInternal() + */ + TQString toString() const; + + /** + * Returns an untranslated text representation of the key in the form + * "modifier+key", suitable e.g. for saving in configuration files. + */ + TQString toStringInternal() const; + + // Operation methods + /** + * @internal + */ + void simplify(); + + /** + * Returns a null key. + * @return the null key + * @see isNull() + * @see clear() + */ + static KKey& null(); + + /** + * Returns a user-readable representation of the given modifiers. + * @param f the modifiers to convert + * @return the string representation of the modifiers + */ + static TQString modFlagLabel( ModFlag f ); + + private: + /* + * Under X11, m_key will hold an X11 key symbol. + * For Qt/Embedded, it will hold the Qt key code. + */ + /** + * Returns the native key symbol value key. Under X11, this is the X + * keycode. Under Qt/Embedded, this is the Qt keycode. + * @see /usr/include/X11/keysymdef.h + * @see tqnamespace.h + */ + uint m_sym; + /** + * m_mod holds the + */ + uint m_mod; + + private: + friend class KKeyNative; +}; + +/** +* A KKeySequence object holds a sequence of up to 4 keys. +* Ex: Ctrl+X,I +* @see KKey +* @see TDEShortcut +*/ + +class TDECORE_EXPORT KKeySequence +{ + public: + /// Defines the maximum length of the key sequence + enum { MAX_KEYS = 4 }; + + /** + * Create a new null key sequence. + * @see isNull() + * @see null() + * @see clear() + */ + KKeySequence(); + + /** + * Copies the given qt key sequence. + * @param keySeq the qt key sequence to copy + */ + KKeySequence( const TQKeySequence& keySeq ); + + /** + * Create a new key sequence that only contains the given key. + * @param key the key to add + */ + KKeySequence( const KKey& key ); + + /** + * Create a new key sequence that only contains the given key. + * @param key the key to add + */ + KKeySequence( const KKeyNative& key ); + + /** + * Copies the given key sequence. + * @param keySeq the key sequence to copy + */ + KKeySequence( const KKeySequence& keySeq ); + + /** + * Creates a new key sequence that contains the given key sequence. + * The description consists of comma-separated keys as + * required by KKey::KKey(const TQString&). + * @param keySeq the description of the key + * @see KKeyServer::Sym::init() + * @see KKey::KKey(const TQString&) + */ + KKeySequence( const TQString& keySeq ); + + ~KKeySequence(); + + /** + * Clears the key sequence. The key sequence is null after calling this + * function. + * @see isNull() + */ + void clear(); + + /** + * Copies the given qt key sequence over this key sequence. + * @param keySeq the qt key sequence to copy + * @return true if successful, false otherwise + */ + bool init( const TQKeySequence& keySeq ); + + /** + * Initializes the key sequence to only contain the given key. + * @param key the key to set + * @return true if successful, false otherwise + */ + bool init( const KKey& key ); + + /** + * Initializes the key sequence to only contain the given key. + * @param key the key to set + * @return true if successful, false otherwise + */ + bool init( const KKeyNative& key ); + + /** + * Copies the given key sequence over this key sequence. + * @param keySeq the key sequence to copy + * @return true if successful, false otherwise + */ + bool init( const KKeySequence& keySeq ); + + /** + * Initializes this key sequence to contain the given key sequence. + * The description consists of comma-separated keys as + * required by KKey::KKey(const TQString&). + * @param key the description of the key + * @return true if successful, false otherwise + * @see KKeyServer::Sym::init() + * @see KKey::KKey(const TQString&) + */ + bool init( const TQString& key ); + + /** + * Copy the given key sequence into this sequence. + */ + KKeySequence& operator =( const KKeySequence& seq ) + { init( seq ); return *this; } + + /** + * Returns the number of key strokes of this sequence. + * @return the number of key strokes + * @see MAX_KEYS + */ + uint count() const; + + /** + * Return the @p i'th key of this sequence, or a null key if there + * are less then i keys. + * @param i the key to retrieve + * @return the @p i'th key, or KKey::null() if there are less + * than i keys + * @see MAX_KEYS + */ + const KKey& key( uint i ) const; + + /** + * @internal + */ + bool isTriggerOnRelease() const; + + /** + * Sets the @p i'th key of the sequence. You can not introduce gaps + * in a sequence, so you must use an @p i <= count(). Also note that + * the maximum length of a key sequence is MAX_KEYS. + * @param i the position of the new key (<= count(), <= MAX_KEYS) + * @param key the key to set + * @return true if successful, false otherwise + */ + bool setKey( uint i, const KKey& key ); + + /** + * Returns true if the key sequence is null (after clear() or empty + * constructor). + * @return true if the key sequence is null + * @see clear() + * @see null() + */ + bool isNull() const; + + /** + * Returns true if this key sequence begins with the given sequence. + * @param keySeq the key sequence to search + * @return true if this key sequence begins with the given sequence + */ + bool startsWith( const KKeySequence& keySeq ) const; + + /** + * Compares this object with the given key sequence. Returns a negative + * number if the given KKeySequence is larger, 0 if they are equal and + * a positive number this KKeySequence is larger. Key sequences are + * compared by comparing the individual keys, starting from the beginning + * until an unequal key has been found. If a sequence contains more + * keys, it is considered larger. + * @param keySeq the key sequence to compare to + * @return a negative number if the given KKeySequence is larger, 0 if + * they are equal and a positive number this KKeySequence is larger + * @see KKey::sequence + */ + int compare( const KKeySequence& keySeq ) const; + + /** + * Compares the keys of both sequences. + * @see compare() + */ + bool operator == ( const KKeySequence& seq ) const + { return compare( seq ) == 0; } + + /** + * Compares the keys of both sequences. + * @see compare() + */ + bool operator != ( const KKeySequence& seq ) const + { return compare( seq ) != 0; } + + /** + * Compares the keys of both sequences. + * @see compare() + */ + bool operator < ( const KKeySequence& seq ) const + { return compare( seq ) < 0; } + // TODO: consider adding Qt::SequenceMatch matches(...) methods for TQKeySequence equivalence + + /** + * Converts this key sequence to a TQKeySequence. + * @return the QKeySequence + */ + TQKeySequence qt() const; + + /** + * Returns the qt key code of the first key. + * @return the qt key code of the first key + * @see Qt::Key + * @see KKey::keyCodeQt() + */ + int keyCodeQt() const; + + /** + * Returns the key sequence as a number of key presses as + * returned by KKey::toString(), separated by commas. + * @return the string represenation of this key sequence + * @see KKey::toString() + */ + TQString toString() const; + + /** + * @internal + */ + TQString toStringInternal() const; + + /** + * Returns a null key sequence. + * @return the null key sequence + * @see isNull() + * @see clear() + */ + static KKeySequence& null(); + + protected: + uchar m_nKeys; + uchar m_bTriggerOnRelease; + // BCI: m_rgvar should be renamed to m_rgkey for KDE 4.0 + KKey m_rgvar[MAX_KEYS]; + + private: + class KKeySequencePrivate* d; + friend class KKeyNative; +}; + +/** +* The TDEShortcut class is used to represent a keyboard shortcut to an action. +* A shortcut is normally a single key with modifiers, such as Ctrl+V. +* A TDEShortcut object may also contain an alternate key which will also +* activate the action it's associated to, as long as no other actions have +* defined that key as their primary key. Ex: Ctrl+V;Shift+Insert. +* +* This can be used to add additional accelerators to a TDEAction. For example, +* the below code binds the escape key to the close action. +* +* \code +* TDEAction *closeAction = KStdAction::close( this, TQT_SLOT( close() ), actionCollection() ); +* TDEShortcut closeShortcut = closeAction->shortcut(); +* closeShortcut.append( KKey(Key_Escape)); +* closeAction->setShortcut(closeShortcut); +* \endcode +* +* Note that a shortcut cannot have more than 2 key combinations associated with it, so the above +* code would not do anything (and append() would return false) if the closeAction already had +* an key and alternate key. +* +*/ + +class TDECORE_EXPORT TDEShortcut +{ + public: + /** + * The maximum number of key sequences that can be contained in + * a TDEShortcut. + */ + enum { MAX_SEQUENCES = 2 }; + + /** + * Creates a new null shortcut. + * @see null() + * @see isNull() + * @see clear() + */ + TDEShortcut(); + + /** + * Creates a new shortcut with the given Qt key code + * as the only key sequence. + * @param keyQt the qt keycode + * @see Qt::Key + */ + TDEShortcut( int keyQt ); + + /** + * Creates a new shortcut that contains only the given qt key + * sequence. + * @param keySeq the qt key sequence to add + */ + TDEShortcut( const TQKeySequence& keySeq ); + + /** + * Creates a new shortcut that contains only the given key + * in its only sequence. + * @param key the key to add + */ + TDEShortcut( const KKey& key ); + + /** + * Creates a new shortcut that contains only the given key + * sequence. + * @param keySeq the key sequence to add + */ + TDEShortcut( const KKeySequence& keySeq ); + + /** + * Copies the given shortcut. + * @param shortcut the shortcut to add + */ + TDEShortcut( const TDEShortcut& shortcut ); + + /** + * Creates a new key sequence that contains the given key sequence. + * The description consists of semicolon-separated keys as + * used in KKeySequence::KKeySequence(const TQString&). + * @param shortcut the description of the key + * @see KKeySequence::KKeySequence(const TQString&) + */ + TDEShortcut( const char* shortcut ); + + /** + * Creates a new key sequence that contains the given key sequence. + * The description consists of semicolon-separated keys as + * used in KKeySequence::KKeySequence(const TQString&). + * @param shortcut the description of the key + * @see KKeySequence::KKeySequence(const TQString&) + */ + TDEShortcut( const TQString& shortcut ); + ~TDEShortcut(); + + /** + * Clears the shortcut. The shortcut is null after calling this + * function. + * @see isNull() + */ + void clear(); + + /** + * Initializes the shortcut with the given Qt key code + * as the only key sequence. + * @param keyQt the qt keycode + * @see Qt::Key + */ + bool init( int keyQt ); + + /** + * Initializes the shortcut with the given qt key sequence. + * @param keySeq the qt key sequence to add + */ + bool init( const TQKeySequence& keySeq ); + + /** + * Initializes the shortcut with the given key as its only sequence. + * @param key the key to add + */ + bool init( const KKey& key ); + + /** + * Initializes the shortcut with the given qt key sequence. + * @param keySeq the qt key sequence to add + */ + bool init( const KKeySequence& keySeq ); + + /** + * Copies the given shortcut. + * @param shortcut the shortcut to add + */ + bool init( const TDEShortcut& shortcut ); + + /** + * Initializes the key sequence with the given key sequence. + * The description consists of semicolon-separated keys as + * used in KKeySequence::KKeySequence(const TQString&). + * @param shortcut the description of the key + * @see KKeySequence::KKeySequence(const TQString&) + */ + bool init( const TQString& shortcut ); + + /** + * Copies the given shortcut over this shortcut. + */ + TDEShortcut& operator =( const TDEShortcut& cut ) + { init( cut ); return *this; } + + /** + * Returns the number of sequences that are in this + * shortcut. + * @return the number of sequences + * MAX_SEQUENCES + */ + uint count() const; + + /** + * Returns the @p i'th key sequence of this shortcut. + * @param i the number of the key sequence to retrieve + * @return the @p i'th sequence or KKeySequence::null() if + * there are less than @p i key sequences + * MAX_SEQUENCES + */ + const KKeySequence& seq( uint i ) const; + + /** + * Returns the key code of the first key sequence, or + * null if there is no first key sequence. + * @return the key code of the first sequence's first key + * @see Qt::Key + * @see KKeySequence::keyCodeQt() + */ + int keyCodeQt() const; + + /** + * Returns true if the shortcut is null (after clear() or empty + * constructor). + * @return true if the shortcut is null + * @see clear() + * @see null() + */ + bool isNull() const; + + /** + * Compares this object with the given shortcut. Returns a negative + * number if the given shortcut is larger, 0 if they are equal and + * a positive number this shortcut is larger. Shortcuts are + * compared by comparing the individual key sequences, starting from the + * beginning until an unequal key sequences has been found. If a shortcut + * contains more key sequences, it is considered larger. + * @param shortcut the shortcut to compare to + * @return a negative number if the given TDEShortcut is larger, 0 if + * they are equal and a positive number this TDEShortcut is larger + * @see KKey::compare() + * @see KKeyShortcut::compare() + */ + int compare( const TDEShortcut& shortcut ) const; + + /** + * Compares the sequences of both shortcuts. + * @see compare() + */ + bool operator == ( const TDEShortcut& cut ) const + { return compare( cut ) == 0; } + + /** + * Compares the sequences of both shortcuts. + * @see compare() + */ + bool operator != ( const TDEShortcut& cut ) const + { return compare( cut ) != 0; } + + /** + * Compares the sequences of both shortcuts. + * @see compare() + */ + bool operator < ( const TDEShortcut& cut ) const + { return compare( cut ) < 0; } + + /** + * Checks whether this shortcut contains a sequence that starts + * with the given key. + * @param key the key to check + * @return true if a key sequence starts with the key + */ + bool contains( const KKey& key ) const; + + /** + * Checks whether this shortcut contains a sequence that starts + * with the given key. + * @param key the key to check + * @return true if a key sequence starts with the key + */ + bool contains( const KKeyNative& key ) const; + + /** + * Checks whether this shortcut contains the given sequence. + * @param keySeq the key sequence to check + * @return true if the shortcut has the given key sequence + */ + bool contains( const KKeySequence& keySeq ) const; + + /** + * Sets the @p i 'th key sequence of the shortcut. You can not introduce + * gaps in the list of sequences, so you must use an @p i <= count(). + * Also note that the maximum number of key sequences is MAX_SEQUENCES. + * @param i the position of the new key sequence(0 <= i <= count(), 0 <= i < MAX_SEQUENCES) + * @param keySeq the key sequence to set + * @return true if successful, false otherwise + */ + bool setSeq( uint i, const KKeySequence& keySeq ); + + /** + * Appends the given key sequence. This sets it as either the keysequence or + * the alternate keysequence. If the shortcut already has MAX_SEQUENCES + * sequences then this call does nothing, and returns false. + * + * @param keySeq the key sequence to add + * @return true if successful, false otherwise + * @see setSeq() + */ + bool append( const KKeySequence& keySeq ); + + /** + * Removes the given key sequence from this shortcut + * @param keySeq the key sequence to remove + * @since 3.3 + */ + void remove( const KKeySequence& keySeq ); + + /** + * Appends the given key + * @param spec the key to add + * @return true if successful, false otherwise + * @see setSeq() + * @see MAX_SEQUENCES + * @since 3.2 + */ + bool append( const KKey& spec ); + + /** + * Appends the sequences from the given shortcut. + * @param cut the shortcut to append + * @return true if successful, false otherwise + * @see MAX_SEQUENCES + * @since 3.2 + */ + bool append( const TDEShortcut& cut ); + + /** + * Converts this shortcut to a key sequence. The first key sequence + * will be taken. + */ + operator TQKeySequence () const; + + /** + * Returns a description of the shortcut as semicolon-separated + * ket sequences, as returned by KKeySequence::toString(). + * @return the string represenation of this shortcut + * @see KKey::toString() + * @see KKeySequence::toString() + */ + TQString toString() const; + + /** + * @internal + */ + TQString toStringInternal( const TDEShortcut* pcutDefault = 0 ) const; + + /** + * Returns a null shortcut. + * @return the null shortcut + * @see isNull() + * @see clear() + */ + static TDEShortcut& null(); + + protected: + uint m_nSeqs; + KKeySequence m_rgseq[MAX_SEQUENCES]; + + private: + class TDEShortcutPrivate* d; + friend class KKeyNative; + +#ifndef KDE_NO_COMPAT + public: + operator int () const { return keyCodeQt(); } +#endif +}; + +#endif // __KSHORTCUT_H diff --git a/tdecore/tdeshortcutlist.cpp b/tdecore/tdeshortcutlist.cpp new file mode 100644 index 000000000..d32df889d --- /dev/null +++ b/tdecore/tdeshortcutlist.cpp @@ -0,0 +1,220 @@ +#include +#include + +#include +#include "kaccelaction.h" +#include +#include +#include +#include +#include +#include +#include "kshortcutlist.h" + +//--------------------------------------------------------------------- +// TDEShortcutList +//--------------------------------------------------------------------- + +TDEShortcutList::TDEShortcutList() +{ +} + +TDEShortcutList::~TDEShortcutList() +{ +} + +bool TDEShortcutList::isGlobal( uint ) const +{ + return false; +} + +int TDEShortcutList::index( const TQString& sName ) const +{ + uint nSize = count(); + for( uint i = 0; + i < nSize; + ++i ) + if( name( i ) == sName ) + return i; + return -1; +} + +int TDEShortcutList::index( const KKeySequence& seq ) const +{ + if( seq.isNull() ) + return -1; + + uint nSize = count(); + for( uint i = 0; i < nSize; i++ ) { + if( shortcut(i).contains( seq ) ) + return i; + } + + return -1; +} + +const TDEInstance* TDEShortcutList::instance() const +{ + return 0; +} + +TQVariant TDEShortcutList::getOther( Other, uint ) const +{ + return TQVariant(); +} + +bool TDEShortcutList::setOther( Other, uint, TQVariant ) +{ + return false; +} + +bool TDEShortcutList::readSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig ) +{ + kdDebug(125) << "TDEShortcutList::readSettings( \"" << sConfigGroup << "\", " << pConfig << " ) start" << endl; + if( !pConfig ) + pConfig = TDEGlobal::config(); + TQString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : TQString("Shortcuts"); + + // If the config file still has the old group name: + // FIXME: need to rename instead? -- and don't do this if hasGroup( "Shortcuts" ). + if( sGroup == "Shortcuts" && pConfig->hasGroup( "Keys" ) ) { + readSettings( "Keys", pConfig ); + } + + kdDebug(125) << "\treadSettings( \"" << sGroup << "\", " << pConfig << " )" << endl; + if( !pConfig->hasGroup( sGroup ) ) + return true; + TDEConfigGroupSaver cgs( pConfig, sGroup ); + + uint nSize = count(); + for( uint i = 0; i < nSize; i++ ) { + if( isConfigurable(i) ) { + TQString sEntry = pConfig->readEntry( name(i) ); + if( !sEntry.isEmpty() ) { + if( sEntry == "none" ) + setShortcut( i, TDEShortcut() ); + else + setShortcut( i, TDEShortcut(sEntry) ); + } + else // default shortcut + setShortcut( i, shortcutDefault(i) ); + kdDebug(125) << "\t" << name(i) << " = '" << sEntry << "'" << endl; + } + } + + kdDebug(125) << "TDEShortcutList::readSettings done" << endl; + return true; +} + +bool TDEShortcutList::writeSettings( const TQString &sConfigGroup, TDEConfigBase* pConfig, bool bWriteAll, bool bGlobal ) const +{ + kdDebug(125) << "TDEShortcutList::writeSettings( " << sConfigGroup << ", " << pConfig << ", " << bWriteAll << ", " << bGlobal << " )" << endl; + if( !pConfig ) + pConfig = TDEGlobal::config(); + + TQString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : TQString("Shortcuts"); + + // If it has the deprecated group [Keys], remove it + if( pConfig->hasGroup( "Keys" ) ) + pConfig->deleteGroup( "Keys", true ); + + TDEConfigGroupSaver cs( pConfig, sGroup ); + + uint nSize = count(); + for( uint i = 0; i < nSize; i++ ) { + if( isConfigurable(i) ) { + const TQString& sName = name(i); + bool bConfigHasAction = !pConfig->readEntry( sName ).isEmpty(); + bool bSameAsDefault = (shortcut(i) == shortcutDefault(i)); + // If we're using a global config or this setting + // differs from the default, then we want to write. + if( bWriteAll || !bSameAsDefault ) { + TQString s = shortcut(i).toStringInternal(); + if( s.isEmpty() ) + s = "none"; + kdDebug(125) << "\twriting " << sName << " = " << s << endl; + pConfig->writeEntry( sName, s, true, bGlobal ); + } + // Otherwise, this key is the same as default + // but exists in config file. Remove it. + else if( bConfigHasAction ) { + kdDebug(125) << "\tremoving " << sName << " because == default" << endl; + pConfig->deleteEntry( sName, false, bGlobal ); + } + } + } + + pConfig->sync(); + return true; +} + +//--------------------------------------------------------------------- +// TDEAccelShortcutList +//--------------------------------------------------------------------- + +class TDEAccelShortcutListPrivate +{ + public: + TQString m_configGroup; +}; + +TDEAccelShortcutList::TDEAccelShortcutList( TDEAccel* pAccel ) +: m_actions( pAccel->actions() ) +{ + d=new TDEAccelShortcutListPrivate; + m_bGlobal = false; + d->m_configGroup=pAccel->configGroup(); +} + +TDEAccelShortcutList::TDEAccelShortcutList( TDEGlobalAccel* pAccel ) +: m_actions( pAccel->actions() ) +{ + d=new TDEAccelShortcutListPrivate; + m_bGlobal = true; + d->m_configGroup=pAccel->configGroup(); +} + +TDEAccelShortcutList::TDEAccelShortcutList( TDEAccelActions& actions, bool bGlobal ) +: m_actions( actions ) +{ + d=new TDEAccelShortcutListPrivate; + m_bGlobal = bGlobal; +} + + +TDEAccelShortcutList::~TDEAccelShortcutList() + { delete d;} +uint TDEAccelShortcutList::count() const + { return m_actions.count(); } +TQString TDEAccelShortcutList::name( uint i ) const + { return m_actions.actionPtr(i)->name(); } +TQString TDEAccelShortcutList::label( uint i ) const + { return m_actions.actionPtr(i)->label(); } +TQString TDEAccelShortcutList::whatsThis( uint i ) const + { return m_actions.actionPtr(i)->whatsThis(); } +const TDEShortcut& TDEAccelShortcutList::shortcut( uint i ) const + { return m_actions.actionPtr(i)->shortcut(); } +const TDEShortcut& TDEAccelShortcutList::shortcutDefault( uint i ) const + { return m_actions.actionPtr(i)->shortcutDefault(); } +bool TDEAccelShortcutList::isConfigurable( uint i ) const + { return m_actions.actionPtr(i)->isConfigurable(); } +bool TDEAccelShortcutList::setShortcut( uint i, const TDEShortcut& cut ) + { return m_actions.actionPtr(i)->setShortcut( cut ); } +TQVariant TDEAccelShortcutList::getOther( Other, uint ) const + { return TQVariant(); } +bool TDEAccelShortcutList::isGlobal( uint ) const + { return m_bGlobal; } +bool TDEAccelShortcutList::setOther( Other, uint, TQVariant ) + { return false; } +bool TDEAccelShortcutList::save() const + { return writeSettings( d->m_configGroup ); } + +void TDEShortcutList::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +void TDEAccelShortcutList::virtual_hook( int id, void* data ) +{ TDEShortcutList::virtual_hook( id, data ); } + +void TDEStdAccel::ShortcutList::virtual_hook( int id, void* data ) +{ TDEShortcutList::virtual_hook( id, data ); } + diff --git a/tdecore/tdeshortcutlist.h b/tdecore/tdeshortcutlist.h new file mode 100644 index 000000000..99e83766b --- /dev/null +++ b/tdecore/tdeshortcutlist.h @@ -0,0 +1,295 @@ +/* This file is part of the KDE libraries + Copyright (C) 2002 Ellis Whitehead + + This library 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. + + 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 __KSHORTCUTLIST_H +#define __KSHORTCUTLIST_H + +#include // For uint +#include +#include "tdelibs_export.h" + +class TQVariant; +class TDEConfigBase; +class TDEInstance; +class KKeySequence; +class TDEShortcut; + +/********************************************************************** +* This is a wrapper class which allows a function to use one interface +* to TDEActionCollection, TDEAccelActions, and TDEActionPtrList. +**********************************************************************/ + +/** + * TDEShortcutList is an abstract base class for + * TDEAccelShortcutList and TDEStdAccel::ShortcutList. It gives + * you an unified interface for accessing the accelerator lists + * of TDEAccel (using TDEAccelShortcutList), + * TDEGlobalAccel (using TDEAccelShortcutList), and + * TDEStdAccel (using TDEStdAccel::ShortcutList). + * + * @short Base class for accessing accelerator lists + */ +class TDECORE_EXPORT TDEShortcutList +{ + public: + /** + * Default constructor. + */ + TDEShortcutList(); + virtual ~TDEShortcutList(); + + /** + * Returns the number of entries. + * @return the number of entries + */ + virtual uint count() const = 0; + + /** + * Returns the name of the shortcut with the given @p index. + * @param index the index of the shortcut (must be < count()) + * @return the name of the shortcut + */ + virtual TQString name( uint index ) const = 0; + + /** + * Returns the (i18n'd) label of the shortcut with the given @p index. + * @param index the index of the shortcut (must be < count()) + * @return the label (i18n'd) of the shortcut + */ + virtual TQString label( uint index ) const = 0; + + /** + * Returns the (i18n'd) What's This text of the shortcut with the given @p index. + * @param index the index of the shortcut (must be < count()) + * @return the What's This text (i18n'd) of the shortcut + */ + virtual TQString whatsThis( uint index ) const = 0; + + // TODO KDE4: add virtual TQString toolTip( uint index ) const = 0 + // Will then be used by the listview in kkeydialog + + /** + * Returns the shortcut with the given @p index. + * @param index the index of the shortcut (must be < count()) + * @return the shortcut + * @see shortcutDefault() + */ + virtual const TDEShortcut& shortcut( uint index ) const = 0; + + /** + * Returns default shortcut with the given @p index. + * @param index the index of the shortcut (must be < count()) + * @return the default shortcut + * @see shortcut() + */ + virtual const TDEShortcut& shortcutDefault( uint index ) const = 0; + + /** + * Checks whether the shortcut with the given @p index is configurable. + * @param index the index of the shortcut (must be < count()) + * @return true if configurable, false otherwise + */ + virtual bool isConfigurable( uint index ) const = 0; + + /** + * Sets the shortcut of the given entry + * @param index the index of the shortcut (must be < count()) + * @param shortcut the shortcut + */ + virtual bool setShortcut( uint index, const TDEShortcut &shortcut ) = 0; + + /** + * Checks whether the shortcut with the given @p index is saved in the + * global configuration. + * @param index the index of the shortcut (must be < count()) + * @return true if global, false otherwise + */ + virtual bool isGlobal( uint index ) const; + + /** + * Returns the index of the shortcut with he given name. + * @param sName the name of the shortcut to search + * @return the index of the shortcut, of -1 if not found + */ + virtual int index( const TQString& sName ) const; + + /** + * Returns the index of the shortcut with he given key sequence. + * @param keySeq the key sequence to search for + * @return the index of the shortcut, of -1 if not found + */ + virtual int index( const KKeySequence& keySeq ) const; + + /** + * The TDEInstance. + * @return the TDEInstance of the list, can be 0 if not available + */ + virtual const TDEInstance* instance() const; + + // These are here in order to handle expansion. + enum Other { }; + /** \internal */ + virtual TQVariant getOther( Other, uint index ) const = 0; + /** \internal */ + virtual bool setOther( Other, uint index, TQVariant ) = 0; + + /** + * Save the shortcut list. + * @return true if successful, false otherwise + */ + virtual bool save() const = 0; + + /** + * Loads the shortcuts from the given configuration file. + * + * @param sConfigGroup the group in the configuration file + * @param pConfig the configuration file to load from + * @return true if successful, false otherwise + */ + virtual bool readSettings( const TQString& sConfigGroup = TQString::null, TDEConfigBase* pConfig = 0 ); + + /** + * Writes the shortcuts to the given configuration file. + * + * @param sConfigGroup the group in the configuration file + * @param pConfig the configuration file to save to + * @param bWriteAll true to write all actions + * @param bGlobal true to write to the global configuration file + * @return true if successful, false otherwise + */ + virtual bool writeSettings( const TQString& sConfigGroup = TQString::null, TDEConfigBase* pConfig = 0, + bool bWriteAll = false, bool bGlobal = false ) const; + + protected: + /// used to extend the interface with virtuals without breaking binary compatibility + virtual void virtual_hook( int id, void* data ); + private: + class TDEShortcutListPrivate* d; +}; + +//--------------------------------------------------------------------- +// TDEAccelShortcutList +//--------------------------------------------------------------------- + +class TDEAccel; +class TDEAccelActions; +class TDEGlobalAccel; + +/** + * TDEShortcutList implementation to access TDEAccel and + * TDEGlobalAccel lists. + */ +class TDECORE_EXPORT TDEAccelShortcutList : public TDEShortcutList +{ + public: + /** + * Creates a new TDEShortcutList that accesses the given TDEAccel. + * @param accel the accelerators to access + */ + TDEAccelShortcutList( TDEAccel* accel ); + + /** + * Creates a new TDEShortcutList that accesses the given + * TDEGlobalAccel. + * @param accel the accelerators to access + */ + TDEAccelShortcutList( TDEGlobalAccel* accel ); + + /** + * @internal + * Creates a new TDEShortcutList that accesses the given + * TDEAccelActions collection. + * @param actions the actions to access + * @param bGlobal true to save the actions in the global + * configuration file + */ + TDEAccelShortcutList( TDEAccelActions &actions, bool bGlobal ); + virtual ~TDEAccelShortcutList(); + + virtual uint count() const; + virtual TQString name( uint index ) const; + virtual TQString label( uint index ) const; + virtual TQString whatsThis( uint index ) const; + virtual const TDEShortcut& shortcut( uint index ) const; + virtual const TDEShortcut& shortcutDefault( uint index ) const; + virtual bool isConfigurable( uint index ) const; + virtual bool setShortcut( uint index , const TDEShortcut& shortcut ); + virtual bool isGlobal( uint index ) const; + + /** \internal */ + virtual TQVariant getOther( Other, uint index ) const; + /** \internal */ + virtual bool setOther( Other, uint index, TQVariant ); + + virtual bool save() const; + + protected: + /** Actions (collection) for this shortcut list. Set by constructor. */ + TDEAccelActions& m_actions; + /** Is this shortcut list global? Access through isGlobal() */ + bool m_bGlobal; + + protected: + virtual void virtual_hook( int id, void* data ); + private: + class TDEAccelShortcutListPrivate* d; +}; + +namespace TDEStdAccel { +//--------------------------------------------------------------------- +// ShortcutList +//--------------------------------------------------------------------- + +/** + * TDEShortcutList implementation that accesses TDEStdAccel + * actions. + */ +class TDECORE_EXPORT ShortcutList : public TDEShortcutList +{ + public: + /** + * Creates a new ShortcutList. + */ + ShortcutList(); + virtual ~ShortcutList(); + + virtual uint count() const; + virtual TQString name( uint index ) const; + virtual TQString label( uint index ) const; + virtual TQString whatsThis( uint index ) const; + virtual const TDEShortcut& shortcut( uint index ) const; + virtual const TDEShortcut& shortcutDefault( uint index ) const; + virtual bool isConfigurable( uint index ) const; + virtual bool setShortcut( uint index , const TDEShortcut& shortcut ); + + /** \internal */ + virtual TQVariant getOther( Other, uint index ) const; + /** \internal */ + virtual bool setOther( Other, uint index, TQVariant ); + + virtual bool save() const; + + protected: + virtual void virtual_hook( int id, void* data ); + private: + class ShortcutListPrivate* d; +}; +} + +#endif // __KSHORTCUTLIST_H diff --git a/tdecore/tdeshortcutmenu.cpp b/tdecore/tdeshortcutmenu.cpp new file mode 100644 index 000000000..be485fb7e --- /dev/null +++ b/tdecore/tdeshortcutmenu.cpp @@ -0,0 +1,161 @@ +/* + Copyright (c) 2002 Ellis Whitehead + + This library 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. + + 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. +*/ + +#include +#include +#include + +#include "kaccelaction.h" +#include +#include +#include "kshortcutmenu.h" +//#include + +TDEShortcutMenu::TDEShortcutMenu( TQWidget* pParent, TDEAccelActions* pActions, KKeySequence seq ) +: TQPopupMenu( pParent ), + m_pActions( pActions ), + m_seq( seq ) +{ + kdDebug() << seq.toStringInternal() << endl; + + TQFont fontTitle = TDEGlobalSettings::menuFont(); + fontTitle.setBold( true ); + + pTitle = new TQLabel( "", (TQWidget*)0 ); + pTitle->setFont( fontTitle ); + pTitle->setFrameShape( TQFrame::Panel ); + + insertItem( pTitle ); +} + +bool TDEShortcutMenu::insertAction( uint iAction, KKeySequence seq ) +{ + TDEAccelAction* pAction = m_pActions->actionPtr( iAction ); + + if( pAction ) { + insertItem( "", iAction ); + m_seqs[indexOf(iAction)] = seq; + return true; + } else + return false; +} + + +void TDEShortcutMenu::updateShortcuts() +{ + pTitle->setText( m_seq.toString() + ",..." ); + + for( uint iItem = 1; iItem < count(); iItem++ ) { + int iAction = idAt( iItem ); + if( iAction >= 0 ) { + TDEAccelAction* pAction = m_pActions->actionPtr( iAction ); + if( pAction ) { + KKeySequence seq = m_seqs[iItem]; + TQString sSeq = seq.key(m_seq.count()).toString(); + for( uint iKey = m_seq.count() + 1; iKey < seq.count(); iKey++ ) + sSeq += TQString(",") + seq.key(iKey).toString(); + + kdDebug(125) << "seq = " << seq.toStringInternal() << " sSeq = " << sSeq << endl; + changeItem( iAction, pAction->label() + "\t" + sSeq ); + } + } + } +} + +void TDEShortcutMenu::keyPressEvent( TQKeyEvent* pEvent ) +{ + kdDebug() << "keypress; " << pEvent->key() << endl; + KKey key( pEvent ); + + switch( pEvent->key() ) { + case TQ_Key_Shift: + case TQ_Key_Control: + case TQ_Key_Alt: + case TQ_Key_Meta: + case TQ_Key_Super_L: + case TQ_Key_Super_R: + case TQ_Key_Hyper_L: + case TQ_Key_Hyper_R: + break; + default: + int iItem = searchForKey( key ); + // If key not found, look for unmodified version. + if( iItem == -1 ) { + key = pEvent->key(); + iItem = searchForKey( key ); + } + + if( iItem == -1 ) { + // Let Up and Down keys navigate menu, + // And permit Enter, Return to select the item. + if( pEvent->key() == Qt::Key_Up || pEvent->key() == Qt::Key_Down || + pEvent->key() == Qt::Key_Enter || pEvent->key() == Qt::Key_Return ) + TQPopupMenu::keyPressEvent( pEvent ); + else + close(); + } + else if( iItem == 0 ) + keepItemsMatching( key ); + else + activateItemAt( iItem ); + } +} + +int TDEShortcutMenu::searchForKey( KKey key ) +{ + int iItemFound = -1; // -1 indicates no match + uint iKey = m_seq.count(); + + for( uint iItem = 1; iItem < count(); iItem++ ) { + if( m_seqs.contains( iItem ) ) { + KKey keyItem = m_seqs[iItem].key( iKey ); + //kdDebug(125) << "iItem = " << iItem << " key = " << key.toStringInternal() << " keyItem = " << keyItem.toStringInternal() << endl; + if( key == keyItem ) { + if( iItemFound == -1 ) + iItemFound = iItem; + else + return 0; // 0 indicates duplicate matches + } + } + } + + return iItemFound; +} + +void TDEShortcutMenu::keepItemsMatching( KKey key ) +{ + kdDebug(125) << "MyAccel::keepItemsMatching( " << key.toStringInternal() << " )" << endl; + + uint iKey = m_seq.count(); + m_seq.setKey( iKey, key ); + + for( uint iItem = 1; iItem < count(); iItem++ ) { + if( m_seqs.contains( iItem ) ) { + KKey keyItem = m_seqs[iItem].key( iKey ); + if( key != keyItem ) { + m_seqs.remove( iItem ); + removeItemAt( iItem-- ); + } + } + } + + updateShortcuts(); +} + +#include "kshortcutmenu.moc" diff --git a/tdecore/tdeshortcutmenu.h b/tdecore/tdeshortcutmenu.h new file mode 100644 index 000000000..6e01cdd95 --- /dev/null +++ b/tdecore/tdeshortcutmenu.h @@ -0,0 +1,61 @@ +/* This file is part of the KDE libraries + Copyright (C) 2002 Ellis Whitehead + + This library 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. + + 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 __KSHORTCUTMENU_H +#define __KSHORTCUTMENU_H + +#include +#include + +#include "kshortcut.h" + +class TQLabel; + +class TDEAccelActions; + +/** + * @internal + */ +class TDECORE_EXPORT TDEShortcutMenu : public TQPopupMenu +{ + Q_OBJECT + public: + TDEShortcutMenu( TQWidget* pParent, TDEAccelActions* pActions, KKeySequence seq ); + + bool insertAction( uint iAction, KKeySequence seq ); + + void updateShortcuts(); + + protected: + void keyPressEvent( TQKeyEvent* pEvent ); + + private: + int searchForKey( KKey key ); + void keepItemsMatching( KKey key ); + + private: + typedef TQMap IndexToKKeySequence; + + TDEAccelActions* m_pActions; + KKeySequence m_seq; + TQLabel* pTitle; + IndexToKKeySequence m_seqs; +}; + +#endif // __KSHORTCUTMENU_H diff --git a/tdecore/tdestdaccel.cpp b/tdecore/tdestdaccel.cpp new file mode 100644 index 000000000..ac1381c88 --- /dev/null +++ b/tdecore/tdestdaccel.cpp @@ -0,0 +1,396 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997 Stefan Taferner (taferner@alpin.or.at) + Copyright (C) 2000 Nicolas Hadacek (haadcek@kde.org) + Copyright (C) 2001,2002 Ellis Whitehead (ellis@kde.org) + + 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. +*/ +#define __KSTDACCEL_CPP_ 1 + +#include "kstdaccel.h" + +#include "kaccelaction.h" +#include "kaccelbase.h" +#include +#include +#include +#include +#include +#include + +namespace TDEStdAccel +{ + +struct TDEStdAccelInfo +{ + StdAccel id; + const char* psName; + const char* psDesc; + int cutDefault, cutDefault4, cutDefault3B, cutDefault4B; + TDEShortcut cut; + bool bInitialized; +}; + +/** Array of predefined TDEStdAccelInfo objects, which cover all + the "standard" accelerators. Each enum value from StdAccel + should appear in this table. +*/ +static TDEStdAccelInfo g_infoStdAccel[] = +{ + {AccelNone, "Group:File", I18N_NOOP("File"), 0, 0, 0, 0, TDEShortcut(), false }, + { Open, I18N_NOOP("Open"), 0, Qt::CTRL+Qt::Key_O, 0, 0, 0, TDEShortcut(), false }, + { New, I18N_NOOP("New"), 0, Qt::CTRL+Qt::Key_N, 0, 0, 0, TDEShortcut(), false }, + { Close, I18N_NOOP("Close"), 0, Qt::CTRL+Qt::Key_W, Qt::CTRL+Qt::Key_Escape, 0, Qt::CTRL+Qt::Key_W, TDEShortcut(), false }, + { Save, I18N_NOOP("Save"), 0, Qt::CTRL+Qt::Key_S, 0, 0, 0, TDEShortcut(), false }, + { Print, I18N_NOOP("Print"), 0, Qt::CTRL+Qt::Key_P, 0, 0, 0, TDEShortcut(), false }, + { Quit, I18N_NOOP("Quit"), 0, Qt::CTRL+Qt::Key_Q, 0, 0, 0, TDEShortcut(), false }, + {AccelNone, "Group:Edit", I18N_NOOP("Edit"), 0, 0, 0, 0, TDEShortcut(), false }, + { Undo, I18N_NOOP("Undo"), 0, Qt::CTRL+Qt::Key_Z, 0, 0, 0, TDEShortcut(), false }, + { Redo, I18N_NOOP("Redo"), 0, Qt::CTRL+Qt::SHIFT+Qt::Key_Z, 0, 0, 0, TDEShortcut(), false }, + { Cut, I18N_NOOP("Cut"), 0, Qt::CTRL+Qt::Key_X, 0, Qt::SHIFT+Qt::Key_Delete, 0, TDEShortcut(), false }, + { Copy, I18N_NOOP("Copy"), 0, Qt::CTRL+Qt::Key_C, 0, Qt::CTRL+Qt::Key_Insert, 0, TDEShortcut(), false }, + { Paste, I18N_NOOP("Paste"), 0, Qt::CTRL+Qt::Key_V, 0, Qt::SHIFT+Qt::Key_Insert, 0, TDEShortcut(), false }, + { PasteSelection, I18N_NOOP("Paste Selection"), 0, 0, 0, Qt::CTRL+Qt::SHIFT+Qt::Key_Insert, 0, TDEShortcut(), false }, + { SelectAll, "SelectAll", I18N_NOOP("Select All"), Qt::CTRL+Qt::Key_A, 0, 0, 0, TDEShortcut(), false }, + { Deselect, I18N_NOOP("Deselect"), 0, Qt::CTRL+Qt::SHIFT+Qt::Key_A, 0, 0, 0, TDEShortcut(), false }, + { DeleteWordBack, "DeleteWordBack", I18N_NOOP("Delete Word Backwards"), Qt::CTRL+Qt::Key_Backspace, 0, 0, 0, TDEShortcut(), false }, + { DeleteWordForward, "DeleteWordForward", I18N_NOOP("Delete Word Forward"), Qt::CTRL+Qt::Key_Delete, 0, 0, 0, TDEShortcut(), false }, + { Find, I18N_NOOP("Find"), 0, Qt::CTRL+Qt::Key_F, 0, 0, 0, TDEShortcut(), false }, + { FindNext, "FindNext", I18N_NOOP("Find Next"), Qt::Key_F3, 0, 0, 0, TDEShortcut(), false }, + { FindPrev, "FindPrev", I18N_NOOP("Find Prev"), Qt::SHIFT+Qt::Key_F3, 0, 0, 0, TDEShortcut(), false }, + { Replace, I18N_NOOP("Replace"), 0, Qt::CTRL+Qt::Key_R, 0, 0, 0, TDEShortcut(), false }, + {AccelNone, "Group:Navigation", I18N_NOOP("Navigation"), 0, 0, 0, 0, TDEShortcut(), false }, + { Home, I18N_NOOP2("Opposite to End","Home"), 0, Qt::CTRL+Qt::Key_Home, 0, Qt::Key_HomePage, 0, TDEShortcut(), false }, + { End, I18N_NOOP("End"), 0, Qt::CTRL+Qt::Key_End, 0, 0, 0, TDEShortcut(), false }, + { BeginningOfLine, "BeginningOfLine", I18N_NOOP("Beginning of Line"), Qt::Key_Home, 0, 0, 0, TDEShortcut(), false}, + { EndOfLine, "EndOfLine", I18N_NOOP("End of Line"), Qt::Key_End, 0, 0, 0, TDEShortcut(), false}, + { Prior, I18N_NOOP("Prior"), 0, TQt::Key_Prior, 0, 0, 0, TDEShortcut(), false }, + { Next, I18N_NOOP2("Opposite to Prior","Next"), 0, TQt::Key_Next, 0, 0, 0, TDEShortcut(), false }, + { GotoLine, "GotoLine", I18N_NOOP("Go to Line"), Qt::CTRL+Qt::Key_G, 0, 0, 0, TDEShortcut(), false }, + { AddBookmark, "AddBookmark", I18N_NOOP("Add Bookmark"), Qt::CTRL+Qt::Key_B, 0, 0, 0, TDEShortcut(), false }, + { ZoomIn, "ZoomIn", I18N_NOOP("Zoom In"), Qt::CTRL+Qt::Key_Plus, 0, 0, 0, TDEShortcut(), false }, + { ZoomOut, "ZoomOut", I18N_NOOP("Zoom Out"), Qt::CTRL+Qt::Key_Minus, 0, 0, 0, TDEShortcut(), false }, + { Up, I18N_NOOP("Up"), 0, Qt::ALT+Qt::Key_Up, 0, 0, 0, TDEShortcut(), false }, + { Back, I18N_NOOP("Back"), 0, Qt::ALT+Qt::Key_Left, 0, Qt::Key_Back, 0, TDEShortcut(), false }, + { Forward, I18N_NOOP("Forward"), 0, Qt::ALT+Qt::Key_Right, 0, Qt::Key_Forward, 0, TDEShortcut(), false }, + { Reload, I18N_NOOP("Reload"), 0, Qt::Key_F5, 0, Qt::Key_Refresh, 0, TDEShortcut(), false }, + { PopupMenuContext, "PopupMenuContext", I18N_NOOP("Popup Menu Context"), Qt::Key_Menu, 0, 0, 0, TDEShortcut(), false }, + { ShowMenubar, "ShowMenubar", I18N_NOOP("Show Menu Bar"), Qt::CTRL+Qt::Key_M, 0, 0, 0, TDEShortcut(), false }, + { BackwardWord, "BackwardWord", I18N_NOOP("Backward Word"), Qt::CTRL+Qt::Key_Left, 0, 0, 0, TDEShortcut(), false }, + { ForwardWord, "ForwardWord", I18N_NOOP("Forward Word"), Qt::CTRL+Qt::Key_Right, 0, 0, 0, TDEShortcut(), false }, + { TabNext, I18N_NOOP("Activate Next Tab"), 0, Qt::CTRL+Qt::Key_Period, 0, Qt::CTRL+Qt::Key_BracketRight, 0, TDEShortcut(), false }, + { TabPrev, I18N_NOOP("Activate Previous Tab"), 0, Qt::CTRL+Qt::Key_Comma, 0, Qt::CTRL+Qt::Key_BracketLeft, 0, TDEShortcut(), false }, + { FullScreen, "FullScreen", I18N_NOOP("Full Screen Mode"), Qt::CTRL+Qt::SHIFT+Qt::Key_F, 0, 0, 0, TDEShortcut(), false }, + {AccelNone, "Group:Help", I18N_NOOP("Help"), 0, 0, 0, 0, TDEShortcut(), false }, + { Help, I18N_NOOP("Help"), 0, Qt::Key_F1, 0, 0, 0, TDEShortcut(), false }, + { WhatsThis, "WhatsThis", I18N_NOOP("What's This"), Qt::SHIFT+Qt::Key_F1, 0, 0, 0, TDEShortcut(), false }, + {AccelNone, "Group:TextCompletion", I18N_NOOP("Text Completion"), 0, 0, 0, 0, TDEShortcut(), false }, + { TextCompletion, "TextCompletion", I18N_NOOP("Text Completion"), Qt::CTRL+Qt::Key_E, 0, 0, 0, TDEShortcut(), false }, + { PrevCompletion, "PrevCompletion", I18N_NOOP("Previous Completion Match"), Qt::CTRL+Qt::Key_Up, 0, 0, 0, TDEShortcut(), false }, + { NextCompletion, "NextCompletion", I18N_NOOP("Next Completion Match"), Qt::CTRL+Qt::Key_Down, 0, 0, 0, TDEShortcut(), false }, + { SubstringCompletion, "SubstringCompletion", I18N_NOOP("Substring Completion"), Qt::CTRL+Qt::Key_T, 0, 0, 0, TDEShortcut(), false }, + { RotateUp, "RotateUp", I18N_NOOP("Previous Item in List"), Qt::Key_Up, 0, 0, 0, TDEShortcut(), false }, + { RotateDown, "RotateDown", I18N_NOOP("Next Item in List"), Qt::Key_Down, 0, 0, 0, TDEShortcut(), false }, + { AccelNone, 0, 0, 0, 0, 0, 0, TDEShortcut(), false } +}; + +/** Search for the TDEStdAccelInfo object associated with the given @p id. */ +static TDEStdAccelInfo* infoPtr( StdAccel id ) +{ + if( id != AccelNone ) { + // Linear search. Changing the data structure doesn't seem possible + // (since we need groups for the config stuff), but maybe a little + // additional hashtable wouldn't hurt. + for( uint i = 0; g_infoStdAccel[i].psName != 0; i++ ) { + if( g_infoStdAccel[i].id == id ) + return &g_infoStdAccel[i]; + } + } + return 0; +} + +/** Initialize the accelerator @p id by checking if it is overridden + in the configuration file (and if it isn't, use the default). +*/ +static void initialize( StdAccel id ) +{ + TDEConfigGroupSaver saver( TDEGlobal::config(), "Shortcuts" ); + TDEStdAccelInfo* pInfo = infoPtr( id ); + + if( !pInfo ) { + kdWarning(125) << "TDEStdAccel: id not found!" << endl; // -- ellis + return; + } + + if( saver.config()->hasKey( pInfo->psName ) ) { + TQString s = saver.config()->readEntry( pInfo->psName ); + if( s != "none" ) + pInfo->cut.init( s ); + else + pInfo->cut.clear(); + } else + pInfo->cut = shortcutDefault( id ); + pInfo->bInitialized = true; +} + +TQString name( StdAccel id ) +{ + TDEStdAccelInfo* pInfo = infoPtr( id ); + if( !pInfo ) + return TQString::null; + return pInfo->psName; +} + +TQString label( StdAccel id ) +{ + TDEStdAccelInfo* pInfo = infoPtr( id ); + if( !pInfo ) + return TQString::null; + return i18n((pInfo->psDesc) ? pInfo->psDesc : pInfo->psName); +} + +// TODO: Add psWhatsThis entry to TDEStdAccelInfo +TQString whatsThis( StdAccel /*id*/ ) +{ +// TDEStdAccelInfo* pInfo = infoPtr( id ); +// if( pInfo && pInfo->psWhatsThis ) +// return i18n(pInfo->psWhatsThis); +// else + return TQString::null; +} + +const TDEShortcut& shortcut( StdAccel id ) +{ + TDEStdAccelInfo* pInfo = infoPtr( id ); + if( !pInfo ) + return TDEShortcut::null(); + + if( !pInfo->bInitialized ) + initialize( id ); + + return pInfo->cut; +} + +StdAccel findStdAccel( const KKeySequence& seq ) +{ + if( !seq.isNull() ) { + for( uint i = 0; g_infoStdAccel[i].psName != 0; i++ ) { + StdAccel id = g_infoStdAccel[i].id; + if( id != AccelNone ) { + if( !g_infoStdAccel[i].bInitialized ) + initialize( id ); + if( g_infoStdAccel[i].cut.contains( seq ) ) + return id; + } + } + } + return AccelNone; +} + +TDEShortcut shortcutDefault( StdAccel id ) +{ + return (TDEAccelAction::useFourModifierKeys()) + ? shortcutDefault4(id) : shortcutDefault3(id); +} + +TDEShortcut shortcutDefault3( StdAccel id ) +{ + TDEShortcut cut; + + TDEStdAccelInfo* pInfo = infoPtr( id ); + if( pInfo ) { + if( pInfo->cutDefault ) + cut.init( pInfo->cutDefault ); + // FIXME: if there is no cutDefault, then this we be made the primary + // instead of alternate shortcut. + if( pInfo->cutDefault3B ) + cut.append( KKey(pInfo->cutDefault3B) ); + } + + return cut; +} + +TDEShortcut shortcutDefault4( StdAccel id ) +{ + TDEShortcut cut; + + TDEStdAccelInfo* pInfo = infoPtr( id ); + if( pInfo ) { + TDEStdAccelInfo& info = *pInfo; + KKeySequence key2; + + cut.init( (info.cutDefault4) ? + TQKeySequence(info.cutDefault) : TQKeySequence(info.cutDefault4) ); + + if( info.cutDefault4B ) + key2.init( TQKeySequence(info.cutDefault4B) ); + else if( info.cutDefault3B ) + key2.init( TQKeySequence(info.cutDefault3B) ); + + if( key2.count() ) + cut.append( key2 ); + } + + return cut; +} + +#if 0 // unused +void createAccelActions( TDEAccelActions& actions ) +{ + actions.clear(); + + for( uint i = 0; g_infoStdAccel[i].psName != 0; i++ ) { + StdAccel id = g_infoStdAccel[i].id; + TDEStdAccelInfo* pInfo = &g_infoStdAccel[i]; + + if( id != AccelNone ) { + actions.insert( pInfo->psName, + i18n((pInfo->psDesc) ? pInfo->psDesc : pInfo->psName), + TQString::null, // pInfo->psWhatsThis, + shortcutDefault3(id), + shortcutDefault4(id) ); + } else + actions.insert( pInfo->psName, i18n(pInfo->psDesc) ); + } +} +#endif + +const TDEShortcut& open() { return shortcut( Open ); } +const TDEShortcut& openNew() { return shortcut( New ); } +const TDEShortcut& close() { return shortcut( Close ); } +const TDEShortcut& save() { return shortcut( Save ); } +const TDEShortcut& print() { return shortcut( Print ); } +const TDEShortcut& quit() { return shortcut( Quit ); } +const TDEShortcut& cut() { return shortcut( Cut ); } +const TDEShortcut& copy() { return shortcut( Copy ); } +const TDEShortcut& paste() { return shortcut( Paste ); } +const TDEShortcut& pasteSelection() { return shortcut( PasteSelection ); } +const TDEShortcut& deleteWordBack() { return shortcut( DeleteWordBack ); } +const TDEShortcut& deleteWordForward() { return shortcut( DeleteWordForward ); } +const TDEShortcut& undo() { return shortcut( Undo ); } +const TDEShortcut& redo() { return shortcut( Redo ); } +const TDEShortcut& find() { return shortcut( Find ); } +const TDEShortcut& findNext() { return shortcut( FindNext ); } +const TDEShortcut& findPrev() { return shortcut( FindPrev ); } +const TDEShortcut& replace() { return shortcut( Replace ); } +const TDEShortcut& home() { return shortcut( Home ); } +const TDEShortcut& end() { return shortcut( End ); } +const TDEShortcut& beginningOfLine() { return shortcut( BeginningOfLine ); } +const TDEShortcut& endOfLine() { return shortcut( EndOfLine ); } +const TDEShortcut& prior() { return shortcut( Prior ); } +const TDEShortcut& next() { return shortcut( Next ); } +const TDEShortcut& backwardWord() { return shortcut( BackwardWord ); } +const TDEShortcut& forwardWord() { return shortcut( ForwardWord ); } +const TDEShortcut& gotoLine() { return shortcut( GotoLine ); } +const TDEShortcut& addBookmark() { return shortcut( AddBookmark ); } +const TDEShortcut& tabNext() { return shortcut( TabNext ); } +const TDEShortcut& tabPrev() { return shortcut( TabPrev ); } +const TDEShortcut& fullScreen() { return shortcut( FullScreen ); } +const TDEShortcut& zoomIn() { return shortcut( ZoomIn ); } +const TDEShortcut& zoomOut() { return shortcut( ZoomOut ); } +const TDEShortcut& help() { return shortcut( Help ); } +const TDEShortcut& completion() { return shortcut( TextCompletion ); } +const TDEShortcut& prevCompletion() { return shortcut( PrevCompletion ); } +const TDEShortcut& nextCompletion() { return shortcut( NextCompletion ); } +const TDEShortcut& rotateUp() { return shortcut( RotateUp ); } +const TDEShortcut& rotateDown() { return shortcut( RotateDown ); } +const TDEShortcut& substringCompletion() { return shortcut( SubstringCompletion ); } +const TDEShortcut& popupMenuContext() { return shortcut( PopupMenuContext ); } +const TDEShortcut& whatsThis() { return shortcut( WhatsThis ); } +const TDEShortcut& reload() { return shortcut( Reload ); } +const TDEShortcut& selectAll() { return shortcut( SelectAll ); } +const TDEShortcut& up() { return shortcut( Up ); } +const TDEShortcut& back() { return shortcut( Back ); } +const TDEShortcut& forward() { return shortcut( Forward ); } +const TDEShortcut& showMenubar() { return shortcut( ShowMenubar ); } + +//--------------------------------------------------------------------- +// ShortcutList +//--------------------------------------------------------------------- + +ShortcutList::ShortcutList() + { } + +ShortcutList::~ShortcutList() + { } + +uint ShortcutList::count() const +{ + static uint g_nAccels = 0; + if( g_nAccels == 0 ) { + for( ; g_infoStdAccel[g_nAccels].psName != 0; g_nAccels++ ) + ; + } + return g_nAccels; +} + +TQString ShortcutList::name( uint i ) const + { return g_infoStdAccel[i].psName; } + +TQString ShortcutList::label( uint i ) const + { return i18n((g_infoStdAccel[i].psDesc) ? g_infoStdAccel[i].psDesc : g_infoStdAccel[i].psName); } + +TQString ShortcutList::whatsThis( uint ) const + { return TQString::null; } + +const TDEShortcut& ShortcutList::shortcut( uint i ) const +{ + if( !g_infoStdAccel[i].bInitialized ) + initialize( g_infoStdAccel[i].id ); + return g_infoStdAccel[i].cut; +} + +const TDEShortcut& ShortcutList::shortcutDefault( uint i ) const +{ + static TDEShortcut cut; + cut = TDEStdAccel::shortcutDefault( g_infoStdAccel[i].id ); + return cut; +} + +bool ShortcutList::isConfigurable( uint i ) const + { return (g_infoStdAccel[i].id != AccelNone); } + +bool ShortcutList::setShortcut( uint i, const TDEShortcut& cut ) + { g_infoStdAccel[i].cut = cut; return true; } + +TQVariant ShortcutList::getOther( Other, uint ) const + { return TQVariant(); } + +bool ShortcutList::setOther( Other, uint, TQVariant ) + { return false; } + +bool ShortcutList::save() const +{ + return writeSettings( TQString::null, 0, false, true ); +} + +TDECORE_EXPORT TQString action(StdAccel id) + { return name(id); } +TDECORE_EXPORT TQString description(StdAccel id) + { return label(id); } +TDECORE_EXPORT int key(StdAccel id) + { return shortcut(id).keyCodeQt(); } +TDECORE_EXPORT int defaultKey(StdAccel id) + { return shortcutDefault(id).keyCodeQt(); } + +TDECORE_EXPORT bool isEqual(const TQKeyEvent* ev, int keyQt) +{ + KKey key1( ev ), key2( keyQt ); + return key1 == key2; +} + +} + +#undef __KSTDACCEL_CPP_ diff --git a/tdecore/tdestdaccel.h b/tdecore/tdestdaccel.h new file mode 100644 index 000000000..580204673 --- /dev/null +++ b/tdecore/tdestdaccel.h @@ -0,0 +1,492 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997 Stefan Taferner (taferner@kde.org) + Copyright (C) 2000 Nicolas Hadacek (hadacek@kde.org) + Copyright (C) 2001,2002 Ellis Whitehead (ellis@kde.org) + + 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 KSTDACCEL_H +#define KSTDACCEL_H + +#include +#include +#include "tdelibs_export.h" + +class TQKeyEvent; +class TDEAccelActions; + +/** + * \namespace TDEStdAccel + * Convenient methods for access to the common accelerator keys in + * the key configuration. These are the standard keybindings that should + * be used in all KDE applications. They will be configurable, + * so do not hardcode the default behavior. + * + * If you want real configurable keybindings in your applications, + * please checkout the class TDEAccel in kaccel.h + * @see TDEAccelShortcutList + */ +namespace TDEStdAccel +{ + // Always add new std-accels to the end of this enum, never in the middle! + /** + * Defines the identifier of all standard accelerators. + */ + enum StdAccel { + AccelNone, + // File menu + Open, New, Close, Save, + // The Print item + Print, + Quit, + // Edit menu + Undo, Redo, Cut, Copy, Paste, SelectAll, Deselect, DeleteWordBack, + DeleteWordForward, Find, FindNext, FindPrev, Replace, + // Navigation + Home, End, Prior, Next, GotoLine, AddBookmark, ZoomIn, ZoomOut, + Up, Back, Forward, Reload, PopupMenuContext, ShowMenubar, + // Help menu + Help, WhatsThis, + // Text completion + TextCompletion, PrevCompletion, NextCompletion, SubstringCompletion, + RotateUp, RotateDown, + + // Tabular navigation + TabNext, ///< @since 3.2 + TabPrev, ///< @since 3.2 + + // Full screen mode + FullScreen, ///< @since 3.2 + + // Text Navigation + BackwardWord, ///< @since 3.3 + ForwardWord, ///< @since 3.3 + BeginningOfLine, ///< @since 3.3 + EndOfLine, ///< @since 3.3 + + PasteSelection ///< @since 3.4 + +#ifndef KDE_NO_COMPAT + , WhatThis = WhatsThis +#endif + }; + + /** + * Returns the keybinding for @p accel. + * @param id the id of the accelerator + */ + TDECORE_EXPORT const TDEShortcut& shortcut(StdAccel id); + + /** + * Returns a unique name for the given accel. + * @param id the id of the accelerator + * @return the unique name of the accelerator + */ + TDECORE_EXPORT TQString name(StdAccel id); + + /** + * Returns a localized label for user-visible display. + * @param id the id of the accelerator + * @return a localized label for the accelerator + */ + TDECORE_EXPORT TQString label(StdAccel id); + + /** + * Returns an extended WhatsThis description for the given accelerator. + * @param id the id of the accelerator + * @return a localized description of the accelerator + */ + TDECORE_EXPORT TQString whatsThis(StdAccel id); + + /** + * Return the StdAccel id of the standard accel action which + * uses this key sequence, or AccelNone if none of them do. + * This is used by class KKeyChooser. + * @param keySeq the key sequence to search + * @return the id of the standard accelerator, or AccelNone if there + * is none + */ + TDECORE_EXPORT StdAccel findStdAccel( const KKeySequence &keySeq ); + + /** + * Returns the hardcoded default shortcut for @p id. + * This does not take into account the user's configuration. + * @param id the id of the accelerator + * @return the default shortcut of the accelerator + */ + TDECORE_EXPORT TDEShortcut shortcutDefault(StdAccel id); + /** + * Returns the hardcoded default 3 modifier shortcut for @p id. + * This does not take into account the user's configuration. + * @param id the id of the accelerator + * @return the default 3 modifier shortcut + */ + TDECORE_EXPORT TDEShortcut shortcutDefault3(StdAccel id); + /** + * Returns the hardcoded default 4 modifier shortcut for @p id. + * This does not take into account the user's configuration. + * @param id the id of the accelerator + * @return the default 4 modifier shortcut + */ + TDECORE_EXPORT TDEShortcut shortcutDefault4(StdAccel id); + + /** + * Open file. Default: Ctrl-o + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& open(); + + /** + * Create a new document (or whatever). Default: Ctrl-n + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& openNew(); + + /** + * Close current document. Default: Ctrl-w + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& close(); + + /** + * Save current document. Default: Ctrl-s + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& save(); + + /** + * Print current document. Default: Ctrl-p + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& print(); + + /** + * Quit the program. Default: Ctrl-q + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& quit(); + + /** + * Undo last operation. Default: Ctrl-z + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& undo(); + + /** + * Redo. Default: Shift-Ctrl-z + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& redo(); + + /** + * Cut selected area and store it in the clipboard. Default: Ctrl-x + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& cut(); + + /** + * Copy selected area into the clipboard. Default: Ctrl-c + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& copy(); + + /** + * Paste contents of clipboard at mouse/cursor position. Default: Ctrl-v + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& paste(); + + /** + * Paste the selection at mouse/cursor position. Default: Ctrl-Shift-Insert + * @return the shortcut of the standard accelerator + * @since 3.4 + */ + TDECORE_EXPORT const TDEShortcut& pasteSelection(); + + /** + * Reload. Default: Ctrl-A + * @return the shortcut of the standard accelerator + **/ + TDECORE_EXPORT const TDEShortcut& selectAll(); + + /** + * Delete a word back from mouse/cursor position. Default: Ctrl-Backspace + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& deleteWordBack(); + + /** + * Delete a word forward from mouse/cursor position. Default: Ctrl-Delete + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& deleteWordForward(); + + /** + * Find, search. Default: Ctrl-f + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& find(); + + /** + * Find/search next. Default: F3 + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& findNext(); + + /** + * Find/search previous. Default: Shift-F3 + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& findPrev(); + + /** + * Find and replace matches. Default: Ctrl-r + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& replace(); + + /** + * Zoom in. Default: Ctrl-Plus + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& zoomIn(); + + /** + * Zoom out. Default: Ctrl-Minus + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& zoomOut(); + + /** + * Toggle insert/overwrite (with visual feedback, e.g. in the statusbar). Default: Insert + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& insert(); + + /** + * Goto beginning of the document. Default: Ctrl-Home + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& home(); + + /** + * Goto end of the document. Default: Ctrl-End + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& end(); + + /** + * Goto beginning of current line. Default: Home + * @return the shortcut of the standard accelerator + * @since 3.3 + */ + TDECORE_EXPORT const TDEShortcut& beginningOfLine(); + + /** + * Goto end of current line. Default: End + * @return the shortcut of the standard accelerator + * @since 3.3 + */ + TDECORE_EXPORT const TDEShortcut& endOfLine(); + + /** + * Scroll up one page. Default: Prior + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& prior(); + + /** + * Scroll down one page. Default: Next + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& next(); + + /** + * Go to line. Default: Ctrl+G + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& gotoLine(); + + /** + * Add current page to bookmarks. Default: Ctrl+B + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& addBookmark(); + + /** + * Next Tab. Default: Ctrl-< + * @return the shortcut of the standard accelerator + * @since 3.2 + */ + TDECORE_EXPORT const TDEShortcut& tabNext(); + + /** + * Previous Tab. Default: Ctrl-> + * @return the shortcut of the standard accelerator + * @since 3.2 + */ + TDECORE_EXPORT const TDEShortcut& tabPrev(); + + /** + * Full Screen Mode. Default: Ctrl+Shift+F + * @return the shortcut of the standard accelerator + * @since 3.2 + */ + TDECORE_EXPORT const TDEShortcut& fullScreen(); + + /** + * Help the user in the current situation. Default: F1 + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& help(); + + /** + * Complete text in input widgets. Default Ctrl+E + * @return the shortcut of the standard accelerator + **/ + TDECORE_EXPORT const TDEShortcut& completion(); + + /** + * Iterate through a list when completion returns + * multiple items. Default: Ctrl+Up + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& prevCompletion(); + + /** + * Iterate through a list when completion returns + * multiple items. Default: Ctrl+Down + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& nextCompletion(); + + /** + * Find a string within another string or list of strings. + * Default: Ctrl-T + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& substringCompletion(); + + /** + * Help users iterate through a list of entries. Default: Up + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& rotateUp(); + + /** + * Help users iterate through a list of entries. Default: Down + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& rotateDown(); + + /** + * popup a context menu. Default: Menu + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& popupMenuContext(); + + /** + * What's This button. Default: Shift+F1 + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& whatsThis(); + + /** + * Reload. Default: F5 + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& reload(); + + /** + * Up. Default: Alt+Up + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& up(); + + /** + * Back. Default: Alt+Left + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& back(); + + /** + * Forward. Default: ALT+Right + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& forward(); + + /** + * BackwardWord. Default: Ctrl+Left + * @return the shortcut of the standard accelerator + * @since 3.3 + */ + TDECORE_EXPORT const TDEShortcut& backwardWord(); + + /** + * ForwardWord. Default: Ctrl+Right + * @return the shortcut of the standard accelerator + * @since 3.3 + */ + TDECORE_EXPORT const TDEShortcut& forwardWord(); + + /** + * Show Menu Bar. Default: Ctrl-M + * @return the shortcut of the standard accelerator + */ + TDECORE_EXPORT const TDEShortcut& showMenubar(); + +#if !defined(KDE_NO_COMPAT) && !defined(__KSTDACCEL_CPP_) + /** + * @deprecated + * Obsolete. Use name(). Returns a string representation for @p accel. + */ + TDECORE_EXPORT TQString action(StdAccel id) KDE_DEPRECATED; + /** + * @deprecated + * Obsolete. Use desc(). Returns a localized description of @p accel. + */ + TDECORE_EXPORT TQString description(StdAccel id) KDE_DEPRECATED; + /** + * @deprecated + * Obsolete. Use shortcut(). Returns the keybinding for @p accel. + */ + TDECORE_EXPORT int key(StdAccel) KDE_DEPRECATED; + /** + * @deprecated + * Obsolete. Use shortcutDefault(). + */ + TDECORE_EXPORT int defaultKey(StdAccel accel) KDE_DEPRECATED; + + /** + * @deprecated. Use KKey(const TQKeyEvent*) == KKey(int). + * + * Compare the keys generated by the key event with + * the value of the integer. + * + * If a modifier (Shift, Alt, Ctrl) key is present in + * TQKeyEvent, its sum with the actual key value + * is used for comparing it with the integer parameter. + * + * @param pEvent the key event to be used in the comparison. + * @param keyQt the int value to be compared to the key event. + * + * @return true if the int value matches the integer representation of the QKeyEvent + */ + TDECORE_EXPORT bool isEqual(const TQKeyEvent* pEvent, int keyQt) KDE_DEPRECATED; +#endif // !KDE_NO_COMPAT + +} + +#endif diff --git a/tdecore/tests/kstdacceltest.cpp b/tdecore/tests/kstdacceltest.cpp deleted file mode 100644 index a3e2d2473..000000000 --- a/tdecore/tests/kstdacceltest.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include - -#include -#include -#include -#include // for exit - -static bool check(TQString txt, TQString a, TQString b) -{ - if (a.isEmpty()) - a = TQString::null; - if (b.isEmpty()) - b = TQString::null; - if (a == b) { - kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl; - } - else { - kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl; - exit(1); - } - return true; -} - -int main(int argc, char *argv[]) -{ - TDEApplication::disableAutoDcopRegistration(); - TDEApplication app(argc,argv,"kstdacceltest",false,false); - - check( "shortcutDefault FullScreen", TDEStdAccel::shortcutDefault( TDEStdAccel::FullScreen ).toString(), "Ctrl+Shift+F" ); - check( "shortcutDefault BeginningOfLine", TDEStdAccel::shortcutDefault( TDEStdAccel::BeginningOfLine ).toString(), "Home" ); - check( "shortcutDefault EndOfLine", TDEStdAccel::shortcutDefault( TDEStdAccel::EndOfLine ).toString(), "End" ); - - check( "name BeginningOfLine", TDEStdAccel::name( TDEStdAccel::BeginningOfLine ), "BeginningOfLine" ); - check( "name EndOfLine", TDEStdAccel::name( TDEStdAccel::EndOfLine ), "EndOfLine" ); - - check( "shortcut method", TDEStdAccel::shortcut( TDEStdAccel::ZoomIn ).toString(), TDEStdAccel::zoomIn().toString() ); - - return 0; -} diff --git a/tdecore/tests/tdestdacceltest.cpp b/tdecore/tests/tdestdacceltest.cpp new file mode 100644 index 000000000..a3e2d2473 --- /dev/null +++ b/tdecore/tests/tdestdacceltest.cpp @@ -0,0 +1,39 @@ +#include + +#include +#include +#include +#include // for exit + +static bool check(TQString txt, TQString a, TQString b) +{ + if (a.isEmpty()) + a = TQString::null; + if (b.isEmpty()) + b = TQString::null; + if (a == b) { + kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl; + } + else { + kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl; + exit(1); + } + return true; +} + +int main(int argc, char *argv[]) +{ + TDEApplication::disableAutoDcopRegistration(); + TDEApplication app(argc,argv,"kstdacceltest",false,false); + + check( "shortcutDefault FullScreen", TDEStdAccel::shortcutDefault( TDEStdAccel::FullScreen ).toString(), "Ctrl+Shift+F" ); + check( "shortcutDefault BeginningOfLine", TDEStdAccel::shortcutDefault( TDEStdAccel::BeginningOfLine ).toString(), "Home" ); + check( "shortcutDefault EndOfLine", TDEStdAccel::shortcutDefault( TDEStdAccel::EndOfLine ).toString(), "End" ); + + check( "name BeginningOfLine", TDEStdAccel::name( TDEStdAccel::BeginningOfLine ), "BeginningOfLine" ); + check( "name EndOfLine", TDEStdAccel::name( TDEStdAccel::EndOfLine ), "EndOfLine" ); + + check( "shortcut method", TDEStdAccel::shortcut( TDEStdAccel::ZoomIn ).toString(), TDEStdAccel::zoomIn().toString() ); + + return 0; +} diff --git a/tdeio/tdefile/krecentdirs.cpp b/tdeio/tdefile/krecentdirs.cpp deleted file mode 100644 index 0d8d008bd..000000000 --- a/tdeio/tdefile/krecentdirs.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- c++ -*- - * Copyright (C)2000 Waldo Bastian - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#include -#include -#include -#include - -#define MAX_DIR_HISTORY 3 - -static void recentdirs_done(TDEConfig *config) -{ - if (config == TDEGlobal::config()) - { - config->sync(); - } - else - { - delete config; - } -} - -static TDEConfig *recentdirs_readList(TQString &key, TQStringList &result, bool readOnly) -{ - TDEConfig *config; - if ((key.length() < 2) || (key[0] != ':')) - key = ":default"; - if (key[1] == ':') - { - key = key.mid(2); - config = new KSimpleConfig(TQString::fromLatin1("krecentdirsrc"), readOnly); - } - else - { - key = key.mid(1); - config = TDEGlobal::config(); - config->setGroup(TQString::fromLatin1("Recent Dirs")); - } - - result=config->readPathListEntry(key); - if (result.isEmpty()) - { - result.append(TDEGlobalSettings::documentPath()); - } - return config; -} - -TQStringList TDERecentDirs::list(const TQString &fileClass) -{ - TQString key = fileClass; - TQStringList result; - recentdirs_done(recentdirs_readList(key, result, true)); - return result; -} - -TQString TDERecentDirs::dir(const TQString &fileClass) -{ - TQStringList result = list(fileClass); - return result[0]; -} - -void TDERecentDirs::add(const TQString &fileClass, const TQString &directory) -{ - TQString key = fileClass; - TQStringList result; - TDEConfig *config = recentdirs_readList(key, result, false); - // make sure the dir is first in history - result.remove(directory); - result.prepend(directory); - while(result.count() > MAX_DIR_HISTORY) - result.remove(result.fromLast()); - config->writePathEntry(key, result); - recentdirs_done(config); -} - diff --git a/tdeio/tdefile/krecentdirs.h b/tdeio/tdefile/krecentdirs.h deleted file mode 100644 index cc9be16b4..000000000 --- a/tdeio/tdefile/krecentdirs.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- c++ -*- - * Copyright (C)2000 Waldo Bastian - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#ifndef __KRECENTDIRS_H -#define __KRECENTDIRS_H - -#include - -#include - -/** - * The goal of this class is to make sure that, when the user needs to - * specify a file via the file selection dialog, this dialog will start - * in the directory most likely to contain the desired files. - * - * This works as follows: Each time the file selection dialog is - * shown, the programmer can specify a "file-class". The file-dialog will - * then start with the directory associated with this file-class. When - * the dialog closes, the directory currently shown in the file-dialog - * will be associated with the file-class. - * - * A file-class can either start with ':' or with '::'. If it starts with - * a single ':' the file-class is specific to the current application. - * If the file-class starts with '::' it is global to all applications. - */ -class TDEIO_EXPORT TDERecentDirs -{ -public: - /** - * Returns a list of directories associated with this file-class. - * The most recently used directory is at the front of the list. - */ - static TQStringList list(const TQString &fileClass); - - /** - * Returns the most recently used directory accociated with this file-class. - */ - static TQString dir(const TQString &fileClass); - - /** - * Associates @p directory with @p fileClass - */ - static void add(const TQString &fileClass, const TQString &directory); -}; - -#endif diff --git a/tdeio/tdefile/krecentdocument.cpp b/tdeio/tdefile/krecentdocument.cpp deleted file mode 100644 index 85af01c46..000000000 --- a/tdeio/tdefile/krecentdocument.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* -*- c++ -*- - * Copyright (C)2000 Daniel M. Duley - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -TQString TDERecentDocument::recentDocumentDirectory() -{ - // need to change this path, not sure where - return locateLocal("data", TQString::fromLatin1("RecentDocuments/")); -} - -TQStringList TDERecentDocument::recentDocuments() -{ - TQDir d(recentDocumentDirectory(), "*.desktop", TQDir::Time, - TQDir::Files | TQDir::Readable | TQDir::Hidden); - - if (!d.exists()) - d.mkdir(recentDocumentDirectory()); - - TQStringList list = d.entryList(); - TQStringList fullList; - - for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { - TQString pathDesktop = d.absFilePath( *it ); - KDesktopFile tmpDesktopFile( pathDesktop, false); - KURL urlDesktopFile(tmpDesktopFile.readURL()); - if( urlDesktopFile.isLocalFile() && !TQFile(urlDesktopFile.path()).exists()) - d.remove(pathDesktop); - else - fullList.append( pathDesktop ); - } - - return fullList; -} - -void TDERecentDocument::add(const KURL& url) -{ - TDERecentDocument::add(url, tqApp->argv()[0]); // ### argv[0] might not match the service filename! -} - -void TDERecentDocument::add(const KURL& url, const TQString& desktopEntryName) -{ - if ( url.isLocalFile() && !TDEGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/")) - return; - - TQString openStr = url.url(); - openStr.replace( TQRegExp("\\$"), "$$" ); // Desktop files with type "Link" are $-variable expanded - - kdDebug(250) << "TDERecentDocument::add for " << openStr << endl; - TDEConfig *config = TDEGlobal::config(); - TQString oldGrp = config->group(); - config->setGroup(TQString::fromLatin1("RecentDocuments")); - bool useRecent = config->readBoolEntry(TQString::fromLatin1("UseRecent"), true); - int maxEntries = config->readNumEntry(TQString::fromLatin1("MaxEntries"), 10); - - config->setGroup(oldGrp); - if(!useRecent) - return; - - TQString path = recentDocumentDirectory(); - - TQString dStr = path + url.fileName(); - - TQString ddesktop = dStr + TQString::fromLatin1(".desktop"); - - int i=1; - // check for duplicates - while(TQFile::exists(ddesktop)){ - // see if it points to the same file and application - KSimpleConfig tmp(ddesktop); - tmp.setDesktopGroup(); - if(tmp.readEntry(TQString::fromLatin1("X-TDE-LastOpenedWith")) - == desktopEntryName) - { - utime(TQFile::encodeName(ddesktop), NULL); - return; - } - // if not append a (num) to it - ++i; - if ( i > maxEntries ) - break; - ddesktop = dStr + TQString::fromLatin1("[%1].desktop").arg(i); - } - - TQDir dir(path); - // check for max entries, delete oldest files if exceeded - TQStringList list = dir.entryList(TQDir::Files | TQDir::Hidden, TQDir::Time | TQDir::Reversed); - i = list.count(); - if(i > maxEntries-1){ - TQStringList::Iterator it; - it = list.begin(); - while(i > maxEntries-1){ - TQFile::remove(dir.absPath() + TQString::fromLatin1("/") + (*it)); - --i, ++it; - } - } - - // create the applnk - KSimpleConfig conf(ddesktop); - conf.setDesktopGroup(); - conf.writeEntry( TQString::fromLatin1("Type"), TQString::fromLatin1("Link") ); - conf.writePathEntry( TQString::fromLatin1("URL"), openStr ); - // If you change the line below, change the test in the above loop - conf.writeEntry( TQString::fromLatin1("X-TDE-LastOpenedWith"), desktopEntryName ); - TQString name = url.fileName(); - if (name.isEmpty()) - name = openStr; - conf.writeEntry( TQString::fromLatin1("Name"), name ); - conf.writeEntry( TQString::fromLatin1("Icon"), KMimeType::iconForURL( url ) ); -} - -void TDERecentDocument::add(const TQString &openStr, bool isUrl) -{ - if( isUrl ) { - add( KURL( openStr ) ); - } else { - KURL url; - url.setPath( openStr ); - add( url ); - } -} - -void TDERecentDocument::clear() -{ - TQStringList list = recentDocuments(); - TQDir dir; - for(TQStringList::Iterator it = list.begin(); it != list.end() ; ++it) - dir.remove(*it); -} - -int TDERecentDocument::maximumItems() -{ - TDEConfig *config = TDEGlobal::config(); - TDEConfigGroupSaver sa(config, TQString::fromLatin1("RecentDocuments")); - return config->readNumEntry(TQString::fromLatin1("MaxEntries"), 10); -} - - diff --git a/tdeio/tdefile/krecentdocument.h b/tdeio/tdefile/krecentdocument.h deleted file mode 100644 index b788c0dc2..000000000 --- a/tdeio/tdefile/krecentdocument.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- c++ -*- - * Copyright (C)2000 Daniel M. Duley - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#ifndef __KRECENTDOCUMENT_H -#define __KRECENTDOCUMENT_H - -#include -#include - -/** - * Manage the "Recent Document Menu" entries displayed by - * applications such as Kicker and Konqueror. - * - * These entries are automatically generated .desktop files pointing - * to the current application and document. You should call the - * static add() method whenever the user opens or saves a new - * document if you want it to show up in the menu. - * - * You don't have to worry about this if you are using any - * KFileDialog derived class to open and save documents, as it - * already calls this class. User defined limits on the maximum - * number of documents to save, etc... are all automatically handled. - * - * @author Daniel M. Duley - */ -class TDEIO_EXPORT TDERecentDocument -{ -public: - - /** - * - * Return a list of absolute paths to recent document .desktop files, - * sorted by date. - * - */ - static TQStringList recentDocuments(); - - /** - * Add a new item to the Recent Document menu. - * - * @param url The url to add. - */ - static void add(const KURL& url); - - /** - * Add a new item to the Recent Document menu, specifying the application to open it with. - * The above add() method uses argv[0] for the app name, which isn't always flexible enough. - * This method is used when an application launches another one to open a document. - * - * @param url The url to add. - * @param desktopEntryName The desktopEntryName of the service to use for opening this document. - */ - static void add(const KURL& url, const TQString& desktopEntryName); - - /** - * - * Add a new item to the Recent Document menu. Calls add( url ). - * - * @param documentStr The full path to the document or URL to add. - * @param isURL Set to @p true if @p documentStr is an URL and not a local file path. - */ - static void add(const TQString &documentStr, bool isURL = false); - - /** - * Clear the recent document menu of all entries. - */ - static void clear(); - - /** - * Returns the maximum amount of recent document entries allowed. - */ - static int maximumItems(); - - /** - * Returns the path to the directory where recent document .desktop files - * are stored. - */ - static TQString recentDocumentDirectory(); -}; - -#endif diff --git a/tdeio/tdefile/tderecentdirs.cpp b/tdeio/tdefile/tderecentdirs.cpp new file mode 100644 index 000000000..0d8d008bd --- /dev/null +++ b/tdeio/tdefile/tderecentdirs.cpp @@ -0,0 +1,99 @@ +/* -*- c++ -*- + * Copyright (C)2000 Waldo Bastian + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +#include +#include +#include +#include + +#define MAX_DIR_HISTORY 3 + +static void recentdirs_done(TDEConfig *config) +{ + if (config == TDEGlobal::config()) + { + config->sync(); + } + else + { + delete config; + } +} + +static TDEConfig *recentdirs_readList(TQString &key, TQStringList &result, bool readOnly) +{ + TDEConfig *config; + if ((key.length() < 2) || (key[0] != ':')) + key = ":default"; + if (key[1] == ':') + { + key = key.mid(2); + config = new KSimpleConfig(TQString::fromLatin1("krecentdirsrc"), readOnly); + } + else + { + key = key.mid(1); + config = TDEGlobal::config(); + config->setGroup(TQString::fromLatin1("Recent Dirs")); + } + + result=config->readPathListEntry(key); + if (result.isEmpty()) + { + result.append(TDEGlobalSettings::documentPath()); + } + return config; +} + +TQStringList TDERecentDirs::list(const TQString &fileClass) +{ + TQString key = fileClass; + TQStringList result; + recentdirs_done(recentdirs_readList(key, result, true)); + return result; +} + +TQString TDERecentDirs::dir(const TQString &fileClass) +{ + TQStringList result = list(fileClass); + return result[0]; +} + +void TDERecentDirs::add(const TQString &fileClass, const TQString &directory) +{ + TQString key = fileClass; + TQStringList result; + TDEConfig *config = recentdirs_readList(key, result, false); + // make sure the dir is first in history + result.remove(directory); + result.prepend(directory); + while(result.count() > MAX_DIR_HISTORY) + result.remove(result.fromLast()); + config->writePathEntry(key, result); + recentdirs_done(config); +} + diff --git a/tdeio/tdefile/tderecentdirs.h b/tdeio/tdefile/tderecentdirs.h new file mode 100644 index 000000000..cc9be16b4 --- /dev/null +++ b/tdeio/tdefile/tderecentdirs.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- + * Copyright (C)2000 Waldo Bastian + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +#ifndef __KRECENTDIRS_H +#define __KRECENTDIRS_H + +#include + +#include + +/** + * The goal of this class is to make sure that, when the user needs to + * specify a file via the file selection dialog, this dialog will start + * in the directory most likely to contain the desired files. + * + * This works as follows: Each time the file selection dialog is + * shown, the programmer can specify a "file-class". The file-dialog will + * then start with the directory associated with this file-class. When + * the dialog closes, the directory currently shown in the file-dialog + * will be associated with the file-class. + * + * A file-class can either start with ':' or with '::'. If it starts with + * a single ':' the file-class is specific to the current application. + * If the file-class starts with '::' it is global to all applications. + */ +class TDEIO_EXPORT TDERecentDirs +{ +public: + /** + * Returns a list of directories associated with this file-class. + * The most recently used directory is at the front of the list. + */ + static TQStringList list(const TQString &fileClass); + + /** + * Returns the most recently used directory accociated with this file-class. + */ + static TQString dir(const TQString &fileClass); + + /** + * Associates @p directory with @p fileClass + */ + static void add(const TQString &fileClass, const TQString &directory); +}; + +#endif diff --git a/tdeio/tdefile/tderecentdocument.cpp b/tdeio/tdefile/tderecentdocument.cpp new file mode 100644 index 000000000..85af01c46 --- /dev/null +++ b/tdeio/tdefile/tderecentdocument.cpp @@ -0,0 +1,177 @@ +/* -*- c++ -*- + * Copyright (C)2000 Daniel M. Duley + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +TQString TDERecentDocument::recentDocumentDirectory() +{ + // need to change this path, not sure where + return locateLocal("data", TQString::fromLatin1("RecentDocuments/")); +} + +TQStringList TDERecentDocument::recentDocuments() +{ + TQDir d(recentDocumentDirectory(), "*.desktop", TQDir::Time, + TQDir::Files | TQDir::Readable | TQDir::Hidden); + + if (!d.exists()) + d.mkdir(recentDocumentDirectory()); + + TQStringList list = d.entryList(); + TQStringList fullList; + + for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { + TQString pathDesktop = d.absFilePath( *it ); + KDesktopFile tmpDesktopFile( pathDesktop, false); + KURL urlDesktopFile(tmpDesktopFile.readURL()); + if( urlDesktopFile.isLocalFile() && !TQFile(urlDesktopFile.path()).exists()) + d.remove(pathDesktop); + else + fullList.append( pathDesktop ); + } + + return fullList; +} + +void TDERecentDocument::add(const KURL& url) +{ + TDERecentDocument::add(url, tqApp->argv()[0]); // ### argv[0] might not match the service filename! +} + +void TDERecentDocument::add(const KURL& url, const TQString& desktopEntryName) +{ + if ( url.isLocalFile() && !TDEGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/")) + return; + + TQString openStr = url.url(); + openStr.replace( TQRegExp("\\$"), "$$" ); // Desktop files with type "Link" are $-variable expanded + + kdDebug(250) << "TDERecentDocument::add for " << openStr << endl; + TDEConfig *config = TDEGlobal::config(); + TQString oldGrp = config->group(); + config->setGroup(TQString::fromLatin1("RecentDocuments")); + bool useRecent = config->readBoolEntry(TQString::fromLatin1("UseRecent"), true); + int maxEntries = config->readNumEntry(TQString::fromLatin1("MaxEntries"), 10); + + config->setGroup(oldGrp); + if(!useRecent) + return; + + TQString path = recentDocumentDirectory(); + + TQString dStr = path + url.fileName(); + + TQString ddesktop = dStr + TQString::fromLatin1(".desktop"); + + int i=1; + // check for duplicates + while(TQFile::exists(ddesktop)){ + // see if it points to the same file and application + KSimpleConfig tmp(ddesktop); + tmp.setDesktopGroup(); + if(tmp.readEntry(TQString::fromLatin1("X-TDE-LastOpenedWith")) + == desktopEntryName) + { + utime(TQFile::encodeName(ddesktop), NULL); + return; + } + // if not append a (num) to it + ++i; + if ( i > maxEntries ) + break; + ddesktop = dStr + TQString::fromLatin1("[%1].desktop").arg(i); + } + + TQDir dir(path); + // check for max entries, delete oldest files if exceeded + TQStringList list = dir.entryList(TQDir::Files | TQDir::Hidden, TQDir::Time | TQDir::Reversed); + i = list.count(); + if(i > maxEntries-1){ + TQStringList::Iterator it; + it = list.begin(); + while(i > maxEntries-1){ + TQFile::remove(dir.absPath() + TQString::fromLatin1("/") + (*it)); + --i, ++it; + } + } + + // create the applnk + KSimpleConfig conf(ddesktop); + conf.setDesktopGroup(); + conf.writeEntry( TQString::fromLatin1("Type"), TQString::fromLatin1("Link") ); + conf.writePathEntry( TQString::fromLatin1("URL"), openStr ); + // If you change the line below, change the test in the above loop + conf.writeEntry( TQString::fromLatin1("X-TDE-LastOpenedWith"), desktopEntryName ); + TQString name = url.fileName(); + if (name.isEmpty()) + name = openStr; + conf.writeEntry( TQString::fromLatin1("Name"), name ); + conf.writeEntry( TQString::fromLatin1("Icon"), KMimeType::iconForURL( url ) ); +} + +void TDERecentDocument::add(const TQString &openStr, bool isUrl) +{ + if( isUrl ) { + add( KURL( openStr ) ); + } else { + KURL url; + url.setPath( openStr ); + add( url ); + } +} + +void TDERecentDocument::clear() +{ + TQStringList list = recentDocuments(); + TQDir dir; + for(TQStringList::Iterator it = list.begin(); it != list.end() ; ++it) + dir.remove(*it); +} + +int TDERecentDocument::maximumItems() +{ + TDEConfig *config = TDEGlobal::config(); + TDEConfigGroupSaver sa(config, TQString::fromLatin1("RecentDocuments")); + return config->readNumEntry(TQString::fromLatin1("MaxEntries"), 10); +} + + diff --git a/tdeio/tdefile/tderecentdocument.h b/tdeio/tdefile/tderecentdocument.h new file mode 100644 index 000000000..b788c0dc2 --- /dev/null +++ b/tdeio/tdefile/tderecentdocument.h @@ -0,0 +1,105 @@ +/* -*- c++ -*- + * Copyright (C)2000 Daniel M. Duley + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +#ifndef __KRECENTDOCUMENT_H +#define __KRECENTDOCUMENT_H + +#include +#include + +/** + * Manage the "Recent Document Menu" entries displayed by + * applications such as Kicker and Konqueror. + * + * These entries are automatically generated .desktop files pointing + * to the current application and document. You should call the + * static add() method whenever the user opens or saves a new + * document if you want it to show up in the menu. + * + * You don't have to worry about this if you are using any + * KFileDialog derived class to open and save documents, as it + * already calls this class. User defined limits on the maximum + * number of documents to save, etc... are all automatically handled. + * + * @author Daniel M. Duley + */ +class TDEIO_EXPORT TDERecentDocument +{ +public: + + /** + * + * Return a list of absolute paths to recent document .desktop files, + * sorted by date. + * + */ + static TQStringList recentDocuments(); + + /** + * Add a new item to the Recent Document menu. + * + * @param url The url to add. + */ + static void add(const KURL& url); + + /** + * Add a new item to the Recent Document menu, specifying the application to open it with. + * The above add() method uses argv[0] for the app name, which isn't always flexible enough. + * This method is used when an application launches another one to open a document. + * + * @param url The url to add. + * @param desktopEntryName The desktopEntryName of the service to use for opening this document. + */ + static void add(const KURL& url, const TQString& desktopEntryName); + + /** + * + * Add a new item to the Recent Document menu. Calls add( url ). + * + * @param documentStr The full path to the document or URL to add. + * @param isURL Set to @p true if @p documentStr is an URL and not a local file path. + */ + static void add(const TQString &documentStr, bool isURL = false); + + /** + * Clear the recent document menu of all entries. + */ + static void clear(); + + /** + * Returns the maximum amount of recent document entries allowed. + */ + static int maximumItems(); + + /** + * Returns the path to the directory where recent document .desktop files + * are stored. + */ + static TQString recentDocumentDirectory(); +}; + +#endif diff --git a/tdeparts/dockmainwindow.cpp b/tdeparts/dockmainwindow.cpp deleted file mode 100644 index ce462e691..000000000 --- a/tdeparts/dockmainwindow.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2000 Falk Brettschneider - (C) 1999 Simon Hausmann - (C) 1999 David Faure - - This library 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. - - 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. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -using namespace KParts; - -namespace KParts -{ -class DockMainWindowPrivate -{ -public: - DockMainWindowPrivate() - { - m_activePart = 0; - m_bShellGUIActivated = false; - m_helpMenu = 0; - } - ~DockMainWindowPrivate() - { - } - - TQGuardedPtr m_activePart; - bool m_bShellGUIActivated; - KHelpMenu *m_helpMenu; -}; -} - -DockMainWindow::DockMainWindow( TQWidget* parent, const char *name, WFlags f ) - : KDockMainWindow( parent, name, f ) -{ - d = new DockMainWindowPrivate(); - PartBase::setPartObject( TQT_TQOBJECT(this) ); -} - -DockMainWindow::~DockMainWindow() -{ - delete d; -} - -void DockMainWindow::createGUI( Part * part ) -{ - kdDebug(1000) << TQString(TQString("DockMainWindow::createGUI for %1").arg(part?part->name():"0L")) << endl; - - KXMLGUIFactory *factory = guiFactory(); - - setUpdatesEnabled( false ); - - TQPtrList plugins; - - if ( d->m_activePart ) - { - kdDebug(1000) << TQString(TQString("deactivating GUI for %1").arg(d->m_activePart->name())) << endl; - - GUIActivateEvent ev( false ); - TQApplication::sendEvent( d->m_activePart, &ev ); - - factory->removeClient( d->m_activePart ); - - disconnect( d->m_activePart, TQT_SIGNAL( setWindowCaption( const TQString & ) ), - this, TQT_SLOT( setCaption( const TQString & ) ) ); - disconnect( d->m_activePart, TQT_SIGNAL( setStatusBarText( const TQString & ) ), - this, TQT_SLOT( slotSetStatusBarText( const TQString & ) ) ); - } - - if ( !d->m_bShellGUIActivated ) - { - loadPlugins( TQT_TQOBJECT(this), this, TDEGlobal::instance() ); - createShellGUI(); - d->m_bShellGUIActivated = true; - } - - if ( part ) - { - // do this before sending the activate event - connect( part, TQT_SIGNAL( setWindowCaption( const TQString & ) ), - this, TQT_SLOT( setCaption( const TQString & ) ) ); - connect( part, TQT_SIGNAL( setStatusBarText( const TQString & ) ), - this, TQT_SLOT( slotSetStatusBarText( const TQString & ) ) ); - - factory->addClient( part ); - - GUIActivateEvent ev( true ); - TQApplication::sendEvent( part, &ev ); - - } - - setUpdatesEnabled( true ); - - d->m_activePart = part; -} - -void DockMainWindow::slotSetStatusBarText( const TQString & text ) -{ - statusBar()->message( text ); -} - -void DockMainWindow::createShellGUI( bool create ) -{ - bool bAccelAutoUpdate = accel()->setAutoUpdate( false ); - assert( d->m_bShellGUIActivated != create ); - d->m_bShellGUIActivated = create; - if ( create ) - { - if ( isHelpMenuEnabled() ) - d->m_helpMenu = new KHelpMenu( this, instance()->aboutData(), true, actionCollection() ); - - TQString f = xmlFile(); - setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) ); - if ( !f.isEmpty() ) - setXMLFile( f, true ); - else - { - TQString auto_file( instance()->instanceName() + "ui.rc" ); - setXMLFile( auto_file, true ); - } - - GUIActivateEvent ev( true ); - TQApplication::sendEvent( this, &ev ); - - guiFactory()->addClient( this ); - - } - else - { - GUIActivateEvent ev( false ); - TQApplication::sendEvent( this, &ev ); - - guiFactory()->removeClient( this ); - } - accel()->setAutoUpdate( bAccelAutoUpdate ); -} - -#include "dockmainwindow.moc" diff --git a/tdeparts/dockmainwindow.h b/tdeparts/dockmainwindow.h deleted file mode 100644 index 223bd3a42..000000000 --- a/tdeparts/dockmainwindow.h +++ /dev/null @@ -1,88 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2000 Falk Brettschneider - (C) 1999 Simon Hausmann - (C) 1999 David Faure - - This library 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. - - 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 __DOCKMAINWINDOW_H -#define __DOCKMAINWINDOW_H - -#include -#include - -#include - -#include - -class TQString; - -namespace KParts -{ - -class DockMainWindowPrivate; - -/** - * A KPart-aware main window with ability for docking widgets, whose user interface is described in XML. - * - * Inherit your main dock-window from this class - * and don't forget to call setXMLFile() in the inherited constructor. - * - * It implements all internal interfaces in the case of a KDockMainWindow as host: - * the builder and servant interface (for menu merging). - */ -class KPARTS_EXPORT DockMainWindow : public KDockMainWindow, virtual public PartBase -{ - Q_OBJECT - public: - /** - * Constructor, same signature as KDockMainWindow. - */ - DockMainWindow( TQWidget* parent = 0L, const char *name = 0L, WFlags f = (WFlags)WDestructiveClose ); - /** - * Destructor. - */ - virtual ~DockMainWindow(); - -protected slots: - - /** - * Create the GUI (by merging the host's and the active part's) - * - * Called on startup and whenever the active part changes. - * For this you need to connect this slot to the - * PartManager::activePartChanged() signal - * @param part The active part (set to 0L if no part). - */ - void createGUI( KParts::Part * part ); - - /** - * Called when the active part wants to change the statusbar message. - * Reimplement if your dock-mainwindow has a complex statusbar - * (with several items) - */ - virtual void slotSetStatusBarText( const TQString & ); - -protected: - virtual void createShellGUI( bool create = true ); - - private: - DockMainWindowPrivate *d; - }; - -} - -#endif diff --git a/tdeparts/doctdemainwindow.cpp b/tdeparts/doctdemainwindow.cpp new file mode 100644 index 000000000..ce462e691 --- /dev/null +++ b/tdeparts/doctdemainwindow.cpp @@ -0,0 +1,166 @@ +/* This file is part of the KDE project + Copyright (C) 2000 Falk Brettschneider + (C) 1999 Simon Hausmann + (C) 1999 David Faure + + This library 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. + + 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +using namespace KParts; + +namespace KParts +{ +class DockMainWindowPrivate +{ +public: + DockMainWindowPrivate() + { + m_activePart = 0; + m_bShellGUIActivated = false; + m_helpMenu = 0; + } + ~DockMainWindowPrivate() + { + } + + TQGuardedPtr m_activePart; + bool m_bShellGUIActivated; + KHelpMenu *m_helpMenu; +}; +} + +DockMainWindow::DockMainWindow( TQWidget* parent, const char *name, WFlags f ) + : KDockMainWindow( parent, name, f ) +{ + d = new DockMainWindowPrivate(); + PartBase::setPartObject( TQT_TQOBJECT(this) ); +} + +DockMainWindow::~DockMainWindow() +{ + delete d; +} + +void DockMainWindow::createGUI( Part * part ) +{ + kdDebug(1000) << TQString(TQString("DockMainWindow::createGUI for %1").arg(part?part->name():"0L")) << endl; + + KXMLGUIFactory *factory = guiFactory(); + + setUpdatesEnabled( false ); + + TQPtrList plugins; + + if ( d->m_activePart ) + { + kdDebug(1000) << TQString(TQString("deactivating GUI for %1").arg(d->m_activePart->name())) << endl; + + GUIActivateEvent ev( false ); + TQApplication::sendEvent( d->m_activePart, &ev ); + + factory->removeClient( d->m_activePart ); + + disconnect( d->m_activePart, TQT_SIGNAL( setWindowCaption( const TQString & ) ), + this, TQT_SLOT( setCaption( const TQString & ) ) ); + disconnect( d->m_activePart, TQT_SIGNAL( setStatusBarText( const TQString & ) ), + this, TQT_SLOT( slotSetStatusBarText( const TQString & ) ) ); + } + + if ( !d->m_bShellGUIActivated ) + { + loadPlugins( TQT_TQOBJECT(this), this, TDEGlobal::instance() ); + createShellGUI(); + d->m_bShellGUIActivated = true; + } + + if ( part ) + { + // do this before sending the activate event + connect( part, TQT_SIGNAL( setWindowCaption( const TQString & ) ), + this, TQT_SLOT( setCaption( const TQString & ) ) ); + connect( part, TQT_SIGNAL( setStatusBarText( const TQString & ) ), + this, TQT_SLOT( slotSetStatusBarText( const TQString & ) ) ); + + factory->addClient( part ); + + GUIActivateEvent ev( true ); + TQApplication::sendEvent( part, &ev ); + + } + + setUpdatesEnabled( true ); + + d->m_activePart = part; +} + +void DockMainWindow::slotSetStatusBarText( const TQString & text ) +{ + statusBar()->message( text ); +} + +void DockMainWindow::createShellGUI( bool create ) +{ + bool bAccelAutoUpdate = accel()->setAutoUpdate( false ); + assert( d->m_bShellGUIActivated != create ); + d->m_bShellGUIActivated = create; + if ( create ) + { + if ( isHelpMenuEnabled() ) + d->m_helpMenu = new KHelpMenu( this, instance()->aboutData(), true, actionCollection() ); + + TQString f = xmlFile(); + setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) ); + if ( !f.isEmpty() ) + setXMLFile( f, true ); + else + { + TQString auto_file( instance()->instanceName() + "ui.rc" ); + setXMLFile( auto_file, true ); + } + + GUIActivateEvent ev( true ); + TQApplication::sendEvent( this, &ev ); + + guiFactory()->addClient( this ); + + } + else + { + GUIActivateEvent ev( false ); + TQApplication::sendEvent( this, &ev ); + + guiFactory()->removeClient( this ); + } + accel()->setAutoUpdate( bAccelAutoUpdate ); +} + +#include "dockmainwindow.moc" diff --git a/tdeparts/doctdemainwindow.h b/tdeparts/doctdemainwindow.h new file mode 100644 index 000000000..223bd3a42 --- /dev/null +++ b/tdeparts/doctdemainwindow.h @@ -0,0 +1,88 @@ +/* This file is part of the KDE project + Copyright (C) 2000 Falk Brettschneider + (C) 1999 Simon Hausmann + (C) 1999 David Faure + + This library 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. + + 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 __DOCKMAINWINDOW_H +#define __DOCKMAINWINDOW_H + +#include +#include + +#include + +#include + +class TQString; + +namespace KParts +{ + +class DockMainWindowPrivate; + +/** + * A KPart-aware main window with ability for docking widgets, whose user interface is described in XML. + * + * Inherit your main dock-window from this class + * and don't forget to call setXMLFile() in the inherited constructor. + * + * It implements all internal interfaces in the case of a KDockMainWindow as host: + * the builder and servant interface (for menu merging). + */ +class KPARTS_EXPORT DockMainWindow : public KDockMainWindow, virtual public PartBase +{ + Q_OBJECT + public: + /** + * Constructor, same signature as KDockMainWindow. + */ + DockMainWindow( TQWidget* parent = 0L, const char *name = 0L, WFlags f = (WFlags)WDestructiveClose ); + /** + * Destructor. + */ + virtual ~DockMainWindow(); + +protected slots: + + /** + * Create the GUI (by merging the host's and the active part's) + * + * Called on startup and whenever the active part changes. + * For this you need to connect this slot to the + * PartManager::activePartChanged() signal + * @param part The active part (set to 0L if no part). + */ + void createGUI( KParts::Part * part ); + + /** + * Called when the active part wants to change the statusbar message. + * Reimplement if your dock-mainwindow has a complex statusbar + * (with several items) + */ + virtual void slotSetStatusBarText( const TQString & ); + +protected: + virtual void createShellGUI( bool create = true ); + + private: + DockMainWindowPrivate *d; + }; + +} + +#endif diff --git a/tdeui/kaccelgen.h b/tdeui/kaccelgen.h deleted file mode 100644 index d1e761876..000000000 --- a/tdeui/kaccelgen.h +++ /dev/null @@ -1,280 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2000 Keunwoo Lee - - 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. - - This program 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 KACCELGEN_H -#define KACCELGEN_H - -#include -#include -#include - -#include - -/** - * Provides functions that, given a collection of QStrings, will - * automatically and intelligently assign menu accelerators to the - * QStrings in the collection. - * - * NOTE: When this file speaks of "accelerators", we really mean - * accelerators as defined by the KDE User Interface Guidelines. We - * do NOT mean "shortcuts", which are what's handled by most other KDE - * libraries with "accel" in the name. - * - * In the Qt library, the mechanism for adding a keyboard accelerator - * to a menu item is to insert an '&' before the letter. Since we - * usually don't want to disturb the original collection, the idiom in - * these functions is to populate a "target" TQStringList parameter - * with the input collectin's QStrings, plus possibly some added '&' - * characters. - * - * That is the mechanism. Here is the policy, in order of decreasing - * importance (it may seem like these are implementation details, but - * IMHO the policy is an important part of the interface): - * - * 1. If the string already contains an '&' character, skip this - * string, because we consider such strings to be "user-specified" - * accelerators. - * - * 2. No accelerator may clash with a previously defined accelerator, - * including any legal (alphanumeric) user-specified accelerator - * anywhere in the collection - * - * 3. Prefer alphanumerics at the start of the string. - * - * 4. Otherwise, prefer alphanumerics at the start of a word. - * - * 5. Otherwise, choose any alphanumeric character not already - * taken. If no such character is available, give up & skip this - * string. - * - * A typical use of these functions would be to automatically assign - * accelerators to a dynamically populated popup menu. For example, - * the core code was written to automatically set accelerators for the - * "Load View Profile" popup menu for Konqueror. We quickly realized - * that it would be useful to make this facility more generally - * available, so I abstracted it out into a set of templates. - * - * TODO: - * - * + Add sugar functions for more collections. - * - * + Add more Deref classes so that we can access a wider variety of - * collections. - * */ -namespace TDEAccelGen -{ - -// HELPERS - -/** - * Static dereference class, for use as a template parameter. - */ -template -class Deref -{ -public: - static TQString deref(Iter i) { return *i; } -}; - -/** - * Static dereference class that calls the key() method on its - * target; for use as a template parameter. - */ -template -class Deref_Key -{ -public: - static TQString deref(Iter i) { return i.key(); } -}; - -/** - * Helper to determine if the given offset in the string could be a - * legal alphanumeric accelerator. - * - * @param str base string - * @param index offset to check - */ -inline bool -isLegalAccelerator(const TQString& str, uint index) -{ - return index < str.length() - && str[index].isLetterOrNumber(); -} - -/** - * Loads all legal predefined accelerators in the (implicitly - * specified) collection into the given TQMap. - * - * @param begin start iterator - * @param end (last+1) iterator - * @param keys map to store output - */ -template -inline void -loadPredefined(Iter begin, Iter end, TQMap& keys) -{ - for (Iter i = begin; i != end; ++i) { - TQString item = Deref::deref(i); - int user_ampersand = item.find(TQChar('&')); - if( user_ampersand >= 0 ) { - // Sanity check. Note that we don't try to find an - // accelerator if the user shoots him/herself in the foot - // by adding a bad '&'. - if( isLegalAccelerator(item, user_ampersand+1) ) { - keys.insert(item[user_ampersand+1], true); - } - } - } -} - - -// /////////////////////////////////////////////////////////////////// -// MAIN USER FUNCTIONS - - -/** - * Main, maximally flexible template function that assigns - * accelerators to the elements of a collection of QStrings. Clients - * will seldom use this directly, as it's usually easier to use one of - * the wrapper functions that simply takes a collection (see below). - * - * The Deref template parameter is a class containing a static - * dereferencing function, modeled after the comparison class C in - * Stroustrup 13.4. - * - * @param begin (you know) - * @param end (you know) - * @param target collection to store generated strings - */ -template -void -generate(Iter begin, Iter end, TQStringList& target) -{ - // Will keep track of used accelerator chars - TQMap used_accels; - - // Prepass to detect manually user-coded accelerators - loadPredefined(begin, end, used_accels); - - // Main pass - for (Iter i = begin; i != end; ++i) { - TQString item = Iter_Deref::deref(i); - - // Attempt to find a good accelerator, but only if the user - // has not manually hardcoded one. - int user_ampersand = item.find(TQChar('&')); - if( user_ampersand < 0 || item[user_ampersand+1] == '&') { - bool found = false; - uint found_idx; - uint j; - - // Check word-starting letters first. - for( j=0; j < item.length(); ++j ) { - if( isLegalAccelerator(item, j) - && !used_accels.contains(item[j]) - && (0 == j || (j > 0 && item[j-1].isSpace())) ) { - found = true; - found_idx = j; - break; - } - } - - if( !found ) { - // No word-starting letter; search for any letter. - for( j=0; j < item.length(); ++j ) { - if( isLegalAccelerator(item, j) - && !used_accels.contains(item[j]) ) { - found = true; - found_idx = j; - break; - } - } - } - - if( found ) { - // Both upper and lower case marked as used - used_accels.insert(item[j].upper(),true); - used_accels.insert(item[j].lower(),true); - item.insert(j,TQChar('&')); - } - } - - target.append( item ); - } -} - -/** - * Another convenience function; looks up the key instead of - * dereferencing directly for the given iterator. - * - * @param begin - * @param end - * @param target - */ -template -inline void -generateFromKeys(Iter begin, Iter end, TQStringList& target) -{ - generate< Iter, Deref_Key >(begin, end, target); -} - - -/** - * Convenience function; generates accelerators for all the items in - * a TQStringList. - * - * @param source Strings for which to generate accelerators - * @param target Output for accelerator-added strings */ -inline void -generate(const TQStringList& source, TQStringList& target) -{ - generate >(source.begin(), source.end(), target); -} - -/** - * Convenience function; generates accelerators for all the values in - * a TQMap. - * - * @param source Map with input strings as VALUES. - * @param target Output for accelerator-added strings */ -template -inline void -generateFromValues(const TQMap& source, TQStringList& target) -{ - generate, Deref_Key > >(source.begin(), source.end(), target); -} - -/** - * Convenience function; generates an accelerator mapping from all the - * keys in a TQMap - * - * @param source Map with input strings as KEYS. - * @param target Output for accelerator-added strings */ -template -inline void -generateFromKeys(const TQMap& source, TQStringList& target) -{ - generateFromKeys(source.begin(), source.end(), target); -} - - -} // end namespace TDEAccelGen - -#endif - diff --git a/tdeui/kaction.cpp b/tdeui/kaction.cpp deleted file mode 100644 index 24a940c2f..000000000 --- a/tdeui/kaction.cpp +++ /dev/null @@ -1,1288 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999 Reginald Stadlbauer - (C) 1999 Simon Hausmann - (C) 2000 Nicolas Hadacek - (C) 2000 Kurt Granroth - (C) 2000 Michael Koch - (C) 2001 Holger Freyther - (C) 2002 Ellis Whitehead - (C) 2002 Joseph Wenninger - - 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. -*/ - -#include "kaction.h" - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -/** -* How it works. -* TDEActionCollection is an organizing container for TDEActions. -* TDEActionCollection keeps track of the information necessary to handle -* configuration and shortcuts. -* -* Focus Widget pointer: -* This is the widget which is the focus for action shortcuts. -* It is set either by passing a TQWidget* to the TDEActionCollection constructor -* or by calling setWidget() if the widget wasn't known when the object was -* initially constructed (as in KXMLGUIClient and KParts::PartBase) -* -* Shortcuts: -* An action's shortcut will not not be connected unless a focus widget has -* been specified in TDEActionCollection. -* -* XML Filename: -* This is used to save user-modified settings back to the *ui.rc file. -* It is set by KXMLGUIFactory. -*/ - -int TDEAction::getToolButtonID() -{ - static int toolbutton_no = -2; - return toolbutton_no--; -} - -//--------------------------------------------------------------------- -// TDEAction::TDEActionPrivate -//--------------------------------------------------------------------- - -class TDEAction::TDEActionPrivate : public KGuiItem -{ -public: - TDEActionPrivate() : KGuiItem() - { - m_kaccel = 0; - m_configurable = true; - } - - TDEAccel *m_kaccel; - TQValueList m_kaccelList; - - TQString m_groupText; - TQString m_group; - - TDEShortcut m_cut; - TDEShortcut m_cutDefault; - - bool m_configurable; - - struct Container - { - Container() { m_container = 0; m_representative = 0; m_id = 0; } - Container( const Container& s ) { m_container = s.m_container; - m_id = s.m_id; m_representative = s.m_representative; } - TQWidget* m_container; - int m_id; - TQWidget* m_representative; - }; - - TQValueList m_containers; -}; - -//--------------------------------------------------------------------- -// TDEAction -//--------------------------------------------------------------------- - -TDEAction::TDEAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TDEActionCollection* parent, const char* name ) -: TQObject( parent, name ), d(new TDEActionPrivate) -{ - initPrivate( text, cut, receiver, slot ); -} - -TDEAction::TDEAction( const TQString& text, const TQString& sIconName, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TDEActionCollection* parent, const char* name ) -: TQObject( parent, name ), d(new TDEActionPrivate) -{ - initPrivate( text, cut, receiver, slot ); - d->setIconName( sIconName ); -} - -TDEAction::TDEAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TDEActionCollection* parent, const char* name ) -: TQObject( parent, name ), d(new TDEActionPrivate) -{ - initPrivate( text, cut, receiver, slot ); - d->setIconSet( pix ); -} - -TDEAction::TDEAction( const KGuiItem& item, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TDEActionCollection* parent, const char* name ) -: TQObject( parent, name ), d(new TDEActionPrivate) -{ - initPrivate( item.text(), cut, receiver, slot ); - if( item.hasIcon() ) - setIcon( item.iconName() ); - setToolTip( item.toolTip() ); - setWhatsThis( item.whatsThis() ); -} - -#ifndef KDE_NO_COMPAT // KDE 4: remove -TDEAction::TDEAction( const TQString& text, const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TQObject( parent, name ), d(new TDEActionPrivate) -{ - initPrivate( text, cut, 0, 0 ); -} - -TDEAction::TDEAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, TQObject* parent, const char* name ) - : TQObject( parent, name ), d(new TDEActionPrivate) -{ - initPrivate( text, cut, receiver, slot ); -} - -TDEAction::TDEAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TQObject( parent, name ), d(new TDEActionPrivate) -{ - initPrivate( text, cut, 0, 0 ); - setIconSet( pix ); -} - -TDEAction::TDEAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) -: TQObject( parent, name ), d(new TDEActionPrivate) -{ - initPrivate( text, cut, 0, 0 ); - d->setIconName( pix ); -} - -TDEAction::TDEAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, - const char* name ) - : TQObject( parent, name ), d(new TDEActionPrivate) -{ - initPrivate( text, cut, receiver, slot ); - setIconSet( pix ); -} - -TDEAction::TDEAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, - const char* name ) - : TQObject( parent, name ), d(new TDEActionPrivate) -{ - initPrivate( text, cut, receiver, slot ); - d->setIconName(pix); -} - -TDEAction::TDEAction( TQObject* parent, const char* name ) - : TQObject( parent, name ), d(new TDEActionPrivate) -{ - initPrivate( TQString::null, TDEShortcut(), 0, 0 ); -} -#endif // KDE 4: remove end - -TDEAction::~TDEAction() -{ - kdDebug(129) << "TDEAction::~TDEAction( this = \"" << name() << "\" )" << endl; // -- ellis -#ifndef KDE_NO_COMPAT - if (d->m_kaccel) - unplugAccel(); -#endif - - // If actionCollection hasn't already been destructed, - if ( m_parentCollection ) { - m_parentCollection->take( this ); - - const TQValueList & accelList = d->m_kaccelList; - TQValueList::const_iterator itr = accelList.constBegin(); - const TQValueList::const_iterator itrEnd = accelList.constEnd(); - - const char * const namePtr = name(); - for (; itr != itrEnd; ++itr ) - (*itr)->remove(namePtr); - - } - - // Do not call unplugAll from here, as tempting as it sounds. - // TDEAction is designed around the idea that you need to plug - // _and_ to unplug it "manually". Unplugging leads to an important - // slowdown when e.g. closing the window, in which case we simply - // want to destroy everything asap, not to remove actions one by one - // from the GUI. - - delete d; -} - -void TDEAction::initPrivate( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot ) -{ - d->m_cutDefault = cut; - - m_parentCollection = tqt_dynamic_cast( parent() ); - kdDebug(129) << "TDEAction::initPrivate(): this = " << this << " name = \"" << name() << "\" cut = " << cut.toStringInternal() << " m_parentCollection = " << m_parentCollection << endl; - if ( m_parentCollection ) - m_parentCollection->insert( this ); - - if ( receiver && slot ) - connect( this, TQT_SIGNAL( activated() ), receiver, slot ); - - if( !cut.isNull() && !qstrcmp( name(), "unnamed" ) ) - kdWarning(129) << "TDEAction::initPrivate(): trying to assign a shortcut (" << cut.toStringInternal() << ") to an unnamed action." << endl; - d->setText( text ); - initShortcut( cut ); -} - -bool TDEAction::isPlugged() const -{ - return (!d->m_containers.empty()) || d->m_kaccel; -} - -bool TDEAction::isPlugged( const TQWidget *container ) const -{ - return findContainer( container ) > -1; -} - -bool TDEAction::isPlugged( const TQWidget *container, int id ) const -{ - int i = findContainer( container ); - return ( i > -1 && itemId( i ) == id ); -} - -bool TDEAction::isPlugged( const TQWidget *container, const TQWidget *_representative ) const -{ - int i = findContainer( container ); - return ( i > -1 && representative( i ) == _representative ); -} - - -/* -Three actionCollection conditions: - 1) Scope is known on creation and TDEAccel object is created (e.g. TDEMainWindow) - 2) Scope is unknown and no TDEAccel object is available (e.g. KXMLGUIClient) - a) addClient() will be called on object - b) we just want to add the actions to another KXMLGUIClient object - -The question is how to do we incorporate #2b into the XMLGUI framework? - - -We have a KCommandHistory object with undo and redo actions in a passed actionCollection -We have a KoDoc object which holds a KCommandHistory object and the actionCollection -We have two KoView objects which both point to the same KoDoc object -Undo and Redo should be available in both KoView objects, and - calling the undo->setEnabled() should affect both KoViews - -When addClient is called, it needs to be able to find the undo and redo actions -When it calls plug() on them, they need to be inserted into the TDEAccel object of the appropriate KoView - -In this case, the actionCollection belongs to KoDoc and we need to let it know that its shortcuts -have the same scope as the KoView actionCollection - -KXMLGUIClient::addSubActionCollection - -Document: - create document actions - -View - create view actions - add document actionCollection as sub-collection - -A parentCollection is created -Scenario 1: parentCollection has a focus widget set (e.g. via TDEMainWindow) - A TDEAccel object is created in the parentCollection - A TDEAction is created with parent=parentCollection - The shortcut is inserted into this actionCollection - Scenario 1a: xml isn't used - done - Scenario 1b: KXMLGUIBuilder::addClient() called - setWidget is called -- ignore - shortcuts are set -Scenario 2: parentCollection has no focus widget (e.g., KParts) - A TDEAction is created with parent=parentCollection - Scenario 2a: xml isn't used - no shortcuts - Scenario 2b: KXMLGUIBuilder::addClient() called - setWidget is called - shortcuts are inserted into current TDEAccel - shortcuts are set in all other TDEAccels, if the action is present in the other TDEAccels -*/ - -/* -shortcut may be set: - - on construction - - on plug - - on reading XML - - on plugAccel (deprecated) - -On Construction: [via initShortcut()] - insert into TDEAccel of m_parentCollection, - if kaccel() && isAutoConnectShortcuts() exists - -On Plug: [via plug() -> plugShortcut()] - insert into TDEAccel of m_parentCollection, if exists and not already inserted into - -On Read XML: [via setShortcut()] - set in all current TDEAccels - insert into TDEAccel of m_parentCollection, if exists and not already inserted into -*/ - -TDEAccel* TDEAction::kaccelCurrent() -{ - if( m_parentCollection && m_parentCollection->builderTDEAccel() ) - return m_parentCollection->builderTDEAccel(); - else if( m_parentCollection && m_parentCollection->kaccel() ) - return m_parentCollection->kaccel(); - else - return 0L; -} - -// Only to be called from initPrivate() -bool TDEAction::initShortcut( const TDEShortcut& cut ) -{ - d->m_cut = cut; - - // Only insert action into TDEAccel if it has a valid name, - if( qstrcmp( name(), "unnamed" ) && - m_parentCollection && - m_parentCollection->isAutoConnectShortcuts() && - m_parentCollection->kaccel() ) - { - insertTDEAccel( m_parentCollection->kaccel() ); - return true; - } - return false; - } - -// Only to be called from plug() -void TDEAction::plugShortcut() -{ - TDEAccel* const kaccel = kaccelCurrent(); - - //kdDebug(129) << "TDEAction::plugShortcut(): this = " << this << " kaccel() = " << (m_parentCollection ? m_parentCollection->kaccel() : 0) << endl; - if( kaccel && qstrcmp( name(), "unnamed" ) ) { - // Check if already plugged into current TDEAccel object - const TQValueList & accelList = d->m_kaccelList; - TQValueList::const_iterator itr = accelList.constBegin(); - const TQValueList::const_iterator itrEnd = accelList.constEnd(); - - for( ; itr != itrEnd; ++itr) { - if( (*itr) == kaccel ) - return; - } - - insertTDEAccel( kaccel ); - } -} - -bool TDEAction::setShortcut( const TDEShortcut& cut ) -{ - bool bChanged = (d->m_cut != cut); - d->m_cut = cut; - - TDEAccel* const kaccel = kaccelCurrent(); - bool bInsertRequired = true; - // Apply new shortcut to all existing TDEAccel objects - - const TQValueList & accelList = d->m_kaccelList; - TQValueList::const_iterator itr = accelList.constBegin(); - const TQValueList::const_iterator itrEnd = accelList.constEnd(); - - for( ; itr != itrEnd; ++itr) { - // Check whether shortcut has already been plugged into - // the current kaccel object. - if( (*itr) == kaccel ) - bInsertRequired = false; - if( bChanged ) - updateTDEAccelShortcut( *itr ); - } - - // Only insert action into TDEAccel if it has a valid name, - if( kaccel && bInsertRequired && qstrcmp( name(), "unnamed" ) ) - insertTDEAccel( kaccel ); - - if( bChanged ) { -#ifndef KDE_NO_COMPAT // KDE 4: remove - if ( d->m_kaccel ) - d->m_kaccel->setShortcut( name(), cut ); -#endif // KDE 4: remove end - int len = containerCount(); - for( int i = 0; i < len; ++i ) - updateShortcut( i ); - } - return true; -} - -bool TDEAction::updateTDEAccelShortcut( TDEAccel* kaccel ) -{ - // Check if action is permitted - if (kapp && !kapp->authorizeTDEAction(name())) - return false; - - bool b = true; - - if ( !kaccel->actions().actionPtr( name() ) ) { - if(!d->m_cut.isNull() ) { - kdDebug(129) << "Inserting " << name() << ", " << d->text() << ", " << d->plainText() << endl; - b = kaccel->insert( name(), d->plainText(), TQString::null, - d->m_cut, - this, TQT_SLOT(slotActivated()), - isShortcutConfigurable(), isEnabled() ); - } - } - else - b = kaccel->setShortcut( name(), d->m_cut ); - - return b; -} - -void TDEAction::insertTDEAccel( TDEAccel* kaccel ) -{ - //kdDebug(129) << "TDEAction::insertTDEAccel( " << kaccel << " ): this = " << this << endl; - if ( !kaccel->actions().actionPtr( name() ) ) { - if( updateTDEAccelShortcut( kaccel ) ) { - d->m_kaccelList.append( kaccel ); - connect( kaccel, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotDestroyed()) ); - } - } - else - kdWarning(129) << "TDEAction::insertTDEAccel( kaccel = " << kaccel << " ): TDEAccel object already contains an action name \"" << name() << "\"" << endl; // -- ellis -} - -void TDEAction::removeTDEAccel( TDEAccel* kaccel ) -{ - //kdDebug(129) << "TDEAction::removeTDEAccel( " << i << " ): this = " << this << endl; - TQValueList & accelList = d->m_kaccelList; - TQValueList::iterator itr = accelList.begin(); - const TQValueList::iterator itrEnd = accelList.end(); - - for( ; itr != itrEnd; ++itr) { - if( (*itr) == kaccel ) { - kaccel->remove( name() ); - accelList.remove( itr ); - disconnect( kaccel, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotDestroyed()) ); - break; - } - } -} - -#ifndef KDE_NO_COMPAT -// KDE 4: remove -void TDEAction::setAccel( int keyQt ) -{ - setShortcut( TDEShortcut(keyQt) ); -} -#endif // KDE 4: remove end - -void TDEAction::updateShortcut( int i ) -{ - int id = itemId( i ); - - TQWidget* w = container( i ); - if ( ::tqqt_cast( w ) ) { - TQPopupMenu* menu = static_cast(w); - updateShortcut( menu, id ); - } - else if ( ::tqqt_cast( w ) ) - static_cast(w)->setAccel( d->m_cut.keyCodeQt(), id ); -} - -void TDEAction::updateShortcut( TQPopupMenu* menu, int id ) -{ - //kdDebug(129) << "TDEAction::updateShortcut(): this = " << this << " d->m_kaccelList.count() = " << d->m_kaccelList.count() << endl; - // If the action has a TDEAccel object, - // show the string representation of its shortcut. - if ( d->m_kaccel || d->m_kaccelList.count() ) { - TQString s = menu->text( id ); - int i = s.find( '\t' ); - if ( i >= 0 ) - s.replace( i+1, s.length()-i, d->m_cut.seq(0).toString() ); - else - s += "\t" + d->m_cut.seq(0).toString(); - - menu->changeItem( id, s ); - } - // Otherwise insert the shortcut itself into the popup menu. - else { - // This is a fall-hack in case the TDEAction is missing a proper parent collection. - // It should be removed eventually. --ellis - menu->setAccel( d->m_cut.keyCodeQt(), id ); - kdDebug(129) << "TDEAction::updateShortcut(): name = \"" << name() << "\", cut = " << d->m_cut.toStringInternal() << "; No TDEAccel, probably missing a parent collection." << endl; - } -} - -const TDEShortcut& TDEAction::shortcut() const -{ - return d->m_cut; -} - -const TDEShortcut& TDEAction::shortcutDefault() const -{ - return d->m_cutDefault; -} - -TQString TDEAction::shortcutText() const -{ - return d->m_cut.toStringInternal(); -} - -void TDEAction::setShortcutText( const TQString& s ) -{ - setShortcut( TDEShortcut(s) ); -} - -#ifndef KDE_NO_COMPAT // Remove in KDE 4 -int TDEAction::accel() const -{ - return d->m_cut.keyCodeQt(); -} -#endif - -void TDEAction::setGroup( const TQString& grp ) -{ - d->m_group = grp; - - int len = containerCount(); - for( int i = 0; i < len; ++i ) - updateGroup( i ); -} - -void TDEAction::updateGroup( int ) -{ - // DO SOMETHING -} - -TQString TDEAction::group() const -{ - return d->m_group; -} - -bool TDEAction::isEnabled() const -{ - return d->isEnabled(); -} - -bool TDEAction::isShortcutConfigurable() const -{ - return d->m_configurable; -} - -void TDEAction::setToolTip( const TQString& tt ) -{ - d->setToolTip( tt ); - - int len = containerCount(); - for( int i = 0; i < len; ++i ) - updateToolTip( i ); -} - -void TDEAction::updateToolTip( int i ) -{ - TQWidget *w = container( i ); - - if ( ::tqqt_cast( w ) ) - TQToolTip::add( static_cast(w)->getWidget( itemId( i ) ), d->toolTip() ); -} - -TQString TDEAction::toolTip() const -{ - return d->toolTip(); -} - -int TDEAction::plug( TQWidget *w, int index ) -{ - //kdDebug(129) << "TDEAction::plug( " << w << ", " << index << " )" << endl; - if (!w ) { - kdWarning(129) << "TDEAction::plug called with 0 argument\n"; - return -1; - } - - // Ellis: print warning if there is a shortcut, but no TDEAccel available (often due to no widget available in the actioncollection) - // David: Well, it doesn't matter much, things still work (e.g. Undo in koffice) via TQAccel. - // We should probably re-enable the warning for things that only TDEAccel can do, though - e.g. WIN key (mapped to Meta). -#if 0 //ndef NDEBUG - TDEAccel* kaccel = kaccelCurrent(); - if( !d->m_cut.isNull() && !kaccel ) { - kdDebug(129) << "TDEAction::plug(): has no TDEAccel object; this = " << this << " name = " << name() << " parentCollection = " << m_parentCollection << endl; // ellis - } -#endif - - // Check if action is permitted - if (kapp && !kapp->authorizeTDEAction(name())) - return -1; - - plugShortcut(); - - if ( ::tqqt_cast( w ) ) - { - TQPopupMenu* menu = static_cast( w ); - int id; - // Don't insert shortcut into menu if it's already in a TDEAccel object. - int keyQt = (d->m_kaccelList.count() || d->m_kaccel) ? 0 : d->m_cut.keyCodeQt(); - - if ( d->hasIcon() ) - { - TDEInstance *instance; - if ( m_parentCollection ) - instance = m_parentCollection->instance(); - else - instance = TDEGlobal::instance(); - id = menu->insertItem( d->iconSet( KIcon::Small, 0, instance ), d->text(), this,//dsweet - TQT_SLOT( slotPopupActivated() ), keyQt, - -1, index ); - } - else - id = menu->insertItem( d->text(), this, - TQT_SLOT( slotPopupActivated() ), - keyQt, -1, index ); - - // If the shortcut is already in a TDEAccel object, then - // we need to set the menu item's shortcut text. - if ( d->m_kaccelList.count() || d->m_kaccel ) - updateShortcut( menu, id ); - - // call setItemEnabled only if the item really should be disabled, - // because that method is slow and the item is per default enabled - if ( !d->isEnabled() ) - menu->setItemEnabled( id, false ); - - if ( !d->whatsThis().isEmpty() ) - menu->TQMenuData::setWhatsThis( id, whatsThisWithIcon() ); - - addContainer( menu, id ); - connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - if ( m_parentCollection ) - m_parentCollection->connectHighlight( menu, this ); - - return d->m_containers.count() - 1; - } - else if ( ::tqqt_cast( w ) ) - { - TDEToolBar *bar = static_cast( w ); - - int id_ = getToolButtonID(); - TDEInstance *instance; - if ( m_parentCollection ) - instance = m_parentCollection->instance(); - else - instance = TDEGlobal::instance(); - - if ( icon().isEmpty() && !iconSet().pixmap().isNull() ) // old code using TQIconSet directly - { - bar->insertButton( iconSet().pixmap(), id_, TQT_SIGNAL( buttonClicked(int, TQt::ButtonState) ), this, - TQT_SLOT( slotButtonClicked(int, TQt::ButtonState) ), - d->isEnabled(), d->plainText(), index ); - } - else - { - TQString icon = d->iconName(); - if ( icon.isEmpty() ) - icon = "unknown"; - bar->insertButton( icon, id_, TQT_SIGNAL( buttonClicked(int, TQt::ButtonState) ), this, - TQT_SLOT( slotButtonClicked(int, TQt::ButtonState) ), - d->isEnabled(), d->plainText(), index, instance ); - } - - TDEToolBarButton* ktb = bar->getButton(id_); - ktb->setName( TQCString("toolbutton_")+name() ); - - if ( !d->whatsThis().isEmpty() ) - TQWhatsThis::add( bar->getButton(id_), whatsThisWithIcon() ); - - if ( !d->toolTip().isEmpty() ) - TQToolTip::add( bar->getButton(id_), d->toolTip() ); - - addContainer( bar, id_ ); - - connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - if ( m_parentCollection ) - m_parentCollection->connectHighlight( bar, this ); - - return containerCount() - 1; - } - - return -1; -} - -void TDEAction::unplug( TQWidget *w ) -{ - int i = findContainer( w ); - if ( i == -1 ) - return; - int id = itemId( i ); - - if ( ::tqqt_cast( w ) ) - { - TQPopupMenu *menu = static_cast( w ); - menu->removeItem( id ); - } - else if ( ::tqqt_cast( w ) ) - { - TDEToolBar *bar = static_cast( w ); - bar->removeItemDelayed( id ); - } - else if ( ::tqqt_cast( w ) ) - { - TQMenuBar *bar = static_cast( w ); - bar->removeItem( id ); - } - - removeContainer( i ); - if ( m_parentCollection ) - m_parentCollection->disconnectHighlight( w, this ); -} - -void TDEAction::plugAccel(TDEAccel *kacc, bool configurable) -{ - kdWarning(129) << "TDEAction::plugAccel(): call to deprecated action." << endl; - kdDebug(129) << kdBacktrace() << endl; - //kdDebug(129) << "TDEAction::plugAccel( kacc = " << kacc << " ): name \"" << name() << "\"" << endl; - if ( d->m_kaccel ) - unplugAccel(); - - // If the parent collection's accel ptr isn't set yet - //if ( m_parentCollection && !m_parentCollection->accel() ) - // m_parentCollection->setAccel( kacc ); - - // We can only plug this action into the given TDEAccel object - // if it does not already contain an action with the same name. - if ( !kacc->actions().actionPtr(name()) ) - { - d->m_kaccel = kacc; - d->m_kaccel->insert(name(), d->plainText(), TQString::null, - TDEShortcut(d->m_cut), - this, TQT_SLOT(slotActivated()), - configurable, isEnabled()); - connect(d->m_kaccel, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotDestroyed())); - //connect(d->m_kaccel, TQT_SIGNAL(keycodeChanged()), this, TQT_SLOT(slotKeycodeChanged())); - } - else - kdWarning(129) << "TDEAction::plugAccel( kacc = " << kacc << " ): TDEAccel object already contains an action name \"" << name() << "\"" << endl; // -- ellis -} - -void TDEAction::unplugAccel() -{ - //kdDebug(129) << "TDEAction::unplugAccel() " << this << " " << name() << endl; - if ( d->m_kaccel ) - { - d->m_kaccel->remove(name()); - d->m_kaccel = 0; - } -} - -void TDEAction::plugMainWindowAccel( TQWidget *w ) -{ - // Note: topLevelWidget() stops too early, we can't use it. - TQWidget * tl = w; - TQWidget * n; - while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store - tl = n; - - TDEMainWindow * mw = tqt_dynamic_cast(tl); // try to see if it's a kmainwindow - if (mw) - plugAccel( mw->accel() ); - else - kdDebug(129) << "TDEAction::plugMainWindowAccel: Toplevel widget isn't a TDEMainWindow, can't plug accel. " << tl << endl; -} - -void TDEAction::setEnabled(bool enable) -{ - //kdDebug(129) << "TDEAction::setEnabled( " << enable << " ): this = " << this << " d->m_kaccelList.count() = " << d->m_kaccelList.count() << endl; - if ( enable == d->isEnabled() ) - return; - -#ifndef KDE_NO_COMPAT - // KDE 4: remove - if (d->m_kaccel) - d->m_kaccel->setEnabled(name(), enable); -#endif // KDE 4: remove end - - const TQValueList & accelList = d->m_kaccelList; - TQValueList::const_iterator itr = accelList.constBegin(); - const TQValueList::const_iterator itrEnd = accelList.constEnd(); - - const char * const namePtr = name(); - - for ( ; itr != itrEnd; ++itr ) - (*itr)->setEnabled( namePtr, enable ); - - d->setEnabled( enable ); - - int len = containerCount(); - for( int i = 0; i < len; ++i ) - updateEnabled( i ); - - emit enabled( d->isEnabled() ); -} - -void TDEAction::updateEnabled( int i ) -{ - TQWidget *w = container( i ); - - if ( ::tqqt_cast( w ) ) - static_cast(w)->setItemEnabled( itemId( i ), d->isEnabled() ); - else if ( ::tqqt_cast( w ) ) - static_cast(w)->setItemEnabled( itemId( i ), d->isEnabled() ); - else if ( ::tqqt_cast( w ) ) - static_cast(w)->setItemEnabled( itemId( i ), d->isEnabled() ); -} - -void TDEAction::setShortcutConfigurable( bool b ) -{ - d->m_configurable = b; -} - -void TDEAction::setText( const TQString& text ) -{ -#ifndef KDE_NO_COMPAT - // KDE 4: remove - if (d->m_kaccel) { - TDEAccelAction* pAction = d->m_kaccel->actions().actionPtr(name()); - if (pAction) - pAction->setLabel( text ); - } -#endif // KDE 4: remove end - const TQValueList & accelList = d->m_kaccelList; - TQValueList::const_iterator itr = accelList.constBegin(); - const TQValueList::const_iterator itrEnd = accelList.constEnd(); - - const char * const namePtr = name(); - - for( ; itr != itrEnd; ++itr ) { - TDEAccelAction* const pAction = (*itr)->actions().actionPtr(namePtr); - if (pAction) - pAction->setLabel( text ); - } - - d->setText( text ); - - int len = containerCount(); - for( int i = 0; i < len; ++i ) - updateText( i ); -} - -void TDEAction::updateText( int i ) -{ - TQWidget *w = container( i ); - - if ( ::tqqt_cast( w ) ) { - int id = itemId( i ); - static_cast(w)->changeItem( id, d->text() ); - if (!d->m_cut.isNull()) - updateShortcut( static_cast(w), id ); - } - else if ( ::tqqt_cast( w ) ) - static_cast(w)->changeItem( itemId( i ), d->text() ); - else if ( ::tqqt_cast( w ) ) - { - TQWidget *button = static_cast(w)->getWidget( itemId( i ) ); - if ( ::tqqt_cast( button ) ) - static_cast(button)->setText( d->plainText() ); - } -} - -TQString TDEAction::text() const -{ - return d->text(); -} - -TQString TDEAction::plainText() const -{ - return d->plainText( ); -} - -void TDEAction::setIcon( const TQString &icon ) -{ - d->setIconName( icon ); - - // now handle any toolbars - int len = containerCount(); - for ( int i = 0; i < len; ++i ) - updateIcon( i ); -} - -void TDEAction::updateIcon( int id ) -{ - TQWidget* w = container( id ); - - if ( ::tqqt_cast( w ) ) { - int itemId_ = itemId( id ); - static_cast(w)->changeItem( itemId_, d->iconSet( KIcon::Small ), d->text() ); - if (!d->m_cut.isNull()) - updateShortcut( static_cast(w), itemId_ ); - } - else if ( ::tqqt_cast( w ) ) - static_cast(w)->changeItem( itemId( id ), d->iconSet( KIcon::Small ), d->text() ); - else if ( ::tqqt_cast( w ) ) - static_cast(w)->setButtonIcon( itemId( id ), d->iconName() ); -} - -TQString TDEAction::icon() const -{ - return d->iconName( ); -} - -void TDEAction::setIconSet( const TQIconSet &iconset ) -{ - d->setIconSet( iconset ); - - int len = containerCount(); - for( int i = 0; i < len; ++i ) - updateIconSet( i ); -} - - -void TDEAction::updateIconSet( int id ) -{ - TQWidget *w = container( id ); - - if ( ::tqqt_cast( w ) ) - { - int itemId_ = itemId( id ); - static_cast(w)->changeItem( itemId_, d->iconSet(), d->text() ); - if (!d->m_cut.isNull()) - updateShortcut( static_cast(w), itemId_ ); - } - else if ( ::tqqt_cast( w ) ) - static_cast(w)->changeItem( itemId( id ), d->iconSet(), d->text() ); - else if ( ::tqqt_cast( w ) ) - { - if ( icon().isEmpty() && d->hasIcon() ) // only if there is no named icon ( scales better ) - static_cast(w)->setButtonIconSet( itemId( id ), d->iconSet() ); - else - static_cast(w)->setButtonIconSet( itemId( id ), d->iconSet( KIcon::Small ) ); - } -} - -TQIconSet TDEAction::iconSet( KIcon::Group group, int size ) const -{ - return d->iconSet( group, size ); -} - -bool TDEAction::hasIcon() const -{ - return d->hasIcon(); -} - -void TDEAction::setWhatsThis( const TQString& text ) -{ - d->setWhatsThis( text ); - - int len = containerCount(); - for( int i = 0; i < len; ++i ) - updateWhatsThis( i ); -} - -void TDEAction::updateWhatsThis( int i ) -{ - TQPopupMenu* pm = popupMenu( i ); - if ( pm ) - { - pm->TQMenuData::setWhatsThis( itemId( i ), d->whatsThis() ); - return; - } - - TDEToolBar *tb = toolBar( i ); - if ( tb ) - { - TQWidget *w = tb->getButton( itemId( i ) ); - TQWhatsThis::remove( w ); - TQWhatsThis::add( w, d->whatsThis() ); - return; - } -} - -TQString TDEAction::whatsThis() const -{ - return d->whatsThis(); -} - -TQString TDEAction::whatsThisWithIcon() const -{ - TQString text = whatsThis(); - if (!d->iconName().isEmpty()) - return TQString::fromLatin1(" %2").arg(d->iconName() ).arg(text); - return text; -} - -TQWidget* TDEAction::container( int index ) const -{ - assert( index < containerCount() ); - return d->m_containers[ index ].m_container; -} - -TDEToolBar* TDEAction::toolBar( int index ) const -{ - return tqt_dynamic_cast( d->m_containers[ index ].m_container ); -} - -TQPopupMenu* TDEAction::popupMenu( int index ) const -{ - return tqt_dynamic_cast( d->m_containers[ index ].m_container ); -} - -TQWidget* TDEAction::representative( int index ) const -{ - return d->m_containers[ index ].m_representative; -} - -int TDEAction::itemId( int index ) const -{ - return d->m_containers[ index ].m_id; -} - -int TDEAction::containerCount() const -{ - return d->m_containers.count(); -} - -uint TDEAction::kaccelCount() const -{ - return d->m_kaccelList.count(); -} - -void TDEAction::addContainer( TQWidget* c, int id ) -{ - TDEActionPrivate::Container p; - p.m_container = c; - p.m_id = id; - d->m_containers.append( p ); -} - -void TDEAction::addContainer( TQWidget* c, TQWidget* w ) -{ - TDEActionPrivate::Container p; - p.m_container = c; - p.m_representative = w; - d->m_containers.append( p ); -} - -void TDEAction::activate() -{ - emit activated( TDEAction::EmulatedActivation, Qt::NoButton ); - slotActivated(); -} - -void TDEAction::slotActivated() -{ - const TQObject *senderObj = TQT_TQOBJECT_CONST(sender()); - if ( senderObj ) - { - if ( ::tqqt_cast( senderObj ) ) - emit activated( TDEAction::AccelActivation, Qt::NoButton ); - } - emit activated(); -} - -// This catches signals emitted by TDEActions inserted into QPopupMenu -// We do crude things inside it, because we need to know which -// TQPopupMenu emitted the signal. We need to be sure that it is -// only called by QPopupMenus, we plugged us in. -void TDEAction::slotPopupActivated() -{ - if( ::tqqt_cast(sender())) - { - int id = tqt_dynamic_cast(sender())->value().toInt(); - int pos = findContainer(id); - if(pos != -1) - { - TQPopupMenu* qpm = tqt_dynamic_cast( container(pos) ); - if(qpm) - { - TDEPopupMenu* kpm = tqt_dynamic_cast( qpm ); - TQt::ButtonState state; - if ( kpm ) // TDEPopupMenu? Nice, it stores the state. - state = kpm->state(); - else { // just a QPopupMenu? We'll ask for the state now then (small race condition?) - kdDebug(129) << "TDEAction::slotPopupActivated not a TDEPopupMenu -> using keyboardMouseState()" << endl; - state = TDEApplication::keyboardMouseState(); - } - emit activated( TDEAction::PopupMenuActivation, state ); - slotActivated(); - return; - } - } - } - - kdWarning(129)<<"Don't connect TDEAction::slotPopupActivated() to anything, expect into QPopupMenus which are in containers. Use slotActivated instead."<m_kaccel->actions().actionPtr(name()); - if( pAction ) - setShortcut(pAction->shortcut()); -} - -TDEActionCollection *TDEAction::parentCollection() const -{ - return m_parentCollection; -} - -void TDEAction::unplugAll() -{ - while ( containerCount() != 0 ) - unplug( container( 0 ) ); -} - -const KGuiItem& TDEAction::guiItem() const -{ - return *d; -} - -void TDEAction::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -/* vim: et sw=2 ts=2 - */ - -#include "kaction.moc" diff --git a/tdeui/kaction.h b/tdeui/kaction.h deleted file mode 100644 index b68ded272..000000000 --- a/tdeui/kaction.h +++ /dev/null @@ -1,676 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999 Reginald Stadlbauer - (C) 1999 Simon Hausmann - (C) 2000 Nicolas Hadacek - (C) 2000 Kurt Granroth - (C) 2000 Michael Koch - (C) 2001 Holger Freyther - (C) 2002 Ellis Whitehead - - 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. -*/ -//$Id$ - -#ifndef __kaction_h__ -#define __kaction_h__ - -#include -#include -#include -#include -#include -#include -#include -#include - -class TQMenuBar; -class TQPopupMenu; -class TQComboBox; -class TQPoint; -class TQIconSet; -class TQString; -class TDEToolBar; - -class TDEAccel; -class TDEAccelActions; -class TDEConfig; -class TDEConfigBase; -class KURL; -class TDEInstance; -class TDEToolBar; -class TDEActionCollection; -class TDEPopupMenu; -class TDEMainWindow; - -/** - * @short Class to encapsulate user-driven action or event - * - * The TDEAction class (and derived and super classes) provides a way to - * easily encapsulate a "real" user-selected action or event in your - * program. - * - * For instance, a user may want to @p paste the contents of - * the clipboard or @p scroll @p down a document or @p quit the - * application. These are all @p actions -- events that the - * user causes to happen. The TDEAction class allows the developer to - * deal with these actions in an easy and intuitive manner. - * - * Specifically, the TDEAction class encapsulated the various attributes - * to an event/action. For instance, an action might have an icon - * that goes along with it (a clipboard for a "paste" action or - * scissors for a "cut" action). The action might have some text to - * describe the action. It will certainly have a method or function - * that actually @p executes the action! All these attributes - * are contained within the TDEAction object. - * - * The advantage of dealing with Actions is that you can manipulate - * the Action without regard to the GUI representation of it. For - * instance, in the "normal" way of dealing with actions like "cut", - * you would manually insert a item for Cut into a menu and a button - * into a toolbar. If you want to disable the cut action for a moment - * (maybe nothing is selected), you would have to hunt down the pointer - * to the menu item and the toolbar button and disable both - * individually. Setting the menu item and toolbar item up uses very - * similar code - but has to be done twice! - * - * With the Action concept, you simply "plug" the Action into whatever - * GUI element you want. The TDEAction class will then take care of - * correctly defining the menu item (with icons, accelerators, text, - * etc) or toolbar button.. or whatever. From then on, if you - * manipulate the Action at all, the effect will propogate through all - * GUI representations of it. Back to the "cut" example: if you want - * to disable the Cut Action, you would simply do - * 'cutAction->setEnabled(false)' and the menuitem and button would - * instantly be disabled! - * - * This is the biggest advantage to the Action concept -- there is a - * one-to-one relationship between the "real" action and @p all - * GUI representations of it. - * - * TDEAction emits the activated() signal if the user activated the - * corresponding GUI element ( menu item, toolbar button, etc. ) - * - * If you are in the situation of wanting to map the activated() - * signal of multiple action objects to one slot, with a special - * argument bound to each action, then you might consider using - * TQSignalMapper . A tiny example: - * - * \code - * TQSignalMapper *desktopNumberMapper = new TQSignalMapper( this ); - * connect( desktopNumberMapper, TQT_SIGNAL( mapped( int ) ), - * this, TQT_SLOT( moveWindowToDesktop( int ) ) ); - * - * for ( uint i = 0; i < numberOfDesktops; ++i ) { - * TDEAction *desktopAction = new TDEAction( i18n( "Move Window to Desktop %i" ).arg( i ), ... ); - * connect( desktopAction, TQT_SIGNAL( activated() ), desktopNumberMapper, TQT_SLOT( map() ) ); - * desktopNumberMapper->setMapping( desktopAction, i ); - * } - * \endcode - * - * General Usage:\n - * - * The steps to using actions are roughly as follows - * - * @li Decide which attributes you want to associate with a given - * action (icons, text, keyboard shortcut, etc) - * @li Create the action using TDEAction (or derived or super class). - * @li "Plug" the Action into whatever GUI element you want. Typically, - * this will be a menu or toolbar. - * - * Detailed Example:\n - * - * Here is an example of enabling a "New [document]" action - * \code - * TDEAction *newAct = new TDEAction(i18n("&New"), "filenew", - * TDEStdAccel::shortcut(TDEStdAccel::New), - * this, TQT_SLOT(fileNew()), - * actionCollection(), "new"); - * \endcode - * This line creates our action. It says that wherever this action is - * displayed, it will use "&New" as the text, the standard icon, and - * the standard shortcut. It further says that whenever this action - * is invoked, it will use the fileNew() slot to execute it. - * - * \code - * TQPopupMenu *file = new TQPopupMenu; - * newAct->plug(file); - * \endcode - * That just inserted the action into the File menu. The point is, it's not - * important in which menu it is: all manipulation of the item is - * done through the newAct object. - * - * \code - * newAct->plug(toolBar()); - * \endcode - * And this inserted the Action into the main toolbar as a button. - * - * That's it! - * - * If you want to disable that action sometime later, you can do so - * with - * \code - * newAct->setEnabled(false) - * \endcode - * and both the menuitem in File and the toolbar button will instantly - * be disabled. - * - * Do not delete a TDEAction object without unplugging it from all its - * containers. The simplest way to do that is to use the unplugAll() - * as in the following example: - * \code - * newAct->unplugAll(); - * delete newAct; - * \endcode - * Normally you will not need to do this as TDEActionCollection manages - * everything for you. - * - * Note: if you are using a "standard" action like "new", "paste", - * "quit", or any other action described in the KDE UI Standards, - * please use the methods in the KStdAction class rather than - * defining your own. - * - * Usage Within the XML Framework:\n - * - * If you are using TDEAction within the context of the XML menu and - * toolbar building framework, then there are a few tiny changes. The - * first is that you must insert your new action into an action - * collection. The action collection (a TDEActionCollection) is, - * logically enough, a central collection of all of the actions - * defined in your application. The XML UI framework code in KXMLGUI - * classes needs access to this collection in order to build up the - * GUI (it's how the builder code knows which actions are valid and - * which aren't). - * - * Also, if you use the XML builder framework, then you do not ever - * have to plug your actions into containers manually. The framework - * does that for you. - * - * @see KStdAction - */ -class TDEUI_EXPORT TDEAction : public TQObject -{ - friend class TDEActionCollection; - Q_OBJECT - TQ_PROPERTY( int containerCount READ containerCount ) - TQ_PROPERTY( TQString plainText READ plainText ) - TQ_PROPERTY( TQString text READ text WRITE setText ) - TQ_PROPERTY( TQString shortcut READ shortcutText WRITE setShortcutText ) - TQ_PROPERTY( bool enabled READ isEnabled WRITE setEnabled ) - TQ_PROPERTY( TQString group READ group WRITE setGroup ) - TQ_PROPERTY( TQString whatsThis READ whatsThis WRITE setWhatsThis ) - TQ_PROPERTY( TQString toolTip READ toolTip WRITE setToolTip ) - TQ_PROPERTY( TQString icon READ icon WRITE setIcon ) -public: - /** - * Constructs an action with text, potential keyboard - * shortcut, and a TQT_SLOT to call when this action is invoked by - * the user. - * - * If you do not want or have a keyboard shortcut, - * set the @p cut param to 0. - * - * This is the most common TDEAction used when you do not have a - * corresponding icon (note that it won't appear in the current version - * of the "Edit ToolBar" dialog, because an action needs an icon to be - * plugged in a toolbar...). - * - * @param text The text that will be displayed. - * @param cut The corresponding keyboard shortcut. - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TDEActionCollection* parent, const char* name ); - - /** - * Constructs an action with text, icon, potential keyboard - * shortcut, and a TQT_SLOT to call when this action is invoked by - * the user. - * - * If you do not want or have a keyboard shortcut, set the - * @p cut param to 0. - * - * This is the other common TDEAction used. Use it when you - * @p do have a corresponding icon. - * - * @param text The text that will be displayed. - * @param pix The icon to display. - * @param cut The corresponding keyboard shortcut. - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TDEActionCollection* parent, const char* name ); - - /** - * Constructs an action with text, icon, potential keyboard - * shortcut, and a TQT_SLOT to call when this action is invoked by - * the user. The icon is loaded on demand later based on where it - * is plugged in. - * - * If you do not want or have a keyboard shortcut, set the - * @p cut param to 0. - * - * This is the other common TDEAction used. Use it when you - * @p do have a corresponding icon. - * - * @param text The text that will be displayed. - * @param pix The icon to display. - * @param cut The corresponding keyboard shortcut (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TDEActionCollection* parent, const char* name ); - - /** - * The same as the above constructor, but with a KGuiItem providing - * the text and icon. - * - * @param item The KGuiItem with the label and (optional) icon. - * @param cut The corresponding keyboard shortcut (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEAction( const KGuiItem& item, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TDEActionCollection* parent, const char* name ); - - /** - * @obsolete - */ - TDEAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, const char* name = 0 ); - /** - * @obsolete - */ - TDEAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); - /** - * @obsolete - */ - TDEAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - /** - * @obsolete - */ - TDEAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - /** - * @obsolete - */ - TDEAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); - /** - * @obsolete - */ - TDEAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, - const char* name = 0 ); - /** - * @obsolete - */ - TDEAction( TQObject* parent = 0, const char* name = 0 ); - - /** - * Standard destructor - */ - virtual ~TDEAction(); - - /** - * "Plug" or insert this action into a given widget. - * - * This will - * typically be a menu or a toolbar. From this point on, you will - * never need to directly manipulate the item in the menu or - * toolbar. You do all enabling/disabling/manipulation directly - * with your TDEAction object. - * - * @param widget The GUI element to display this action - * @param index The position into which the action is plugged. If - * this is negative, the action is inserted at the end. - */ - virtual int plug( TQWidget *widget, int index = -1 ); - - /** - * @deprecated. Shouldn't be used. No substitute available. - * - * "Plug" or insert this action into a given TDEAccel. - * - * @param accel The TDEAccel collection which holds this accel - * @param configurable If the shortcut is configurable via - * the TDEAccel configuration dialog (this is somehow deprecated since - * there is now a TDEAction key configuration dialog). - */ - virtual void plugAccel(TDEAccel *accel, bool configurable = true) KDE_DEPRECATED; - - /** - * "Unplug" or remove this action from a given widget. - * - * This will typically be a menu or a toolbar. This is rarely - * used in "normal" application. Typically, it would be used if - * your application has several views or modes, each with a - * completely different menu structure. If you simply want to - * disable an action for a given period, use setEnabled() - * instead. - * - * @param w Remove the action from this GUI element. - */ - virtual void unplug( TQWidget *w ); - - /** - * @deprecated. Complement method to plugAccel(). - * Disconnect this action from the TDEAccel. - */ - virtual void unplugAccel() KDE_DEPRECATED; - - /** - * returns whether the action is plugged into any container widget or not. - * @since 3.1 - */ - virtual bool isPlugged() const; - - /** - * returns whether the action is plugged into the given container - */ - bool isPlugged( const TQWidget *container ) const; - - /** - * returns whether the action is plugged into the given container with the given, container specific, id (often - * menu or toolbar id ) . - */ - virtual bool isPlugged( const TQWidget *container, int id ) const; - - /** - * returns whether the action is plugged into the given container with the given, container specific, representative - * container widget item. - */ - virtual bool isPlugged( const TQWidget *container, const TQWidget *_representative ) const; - - TQWidget* container( int index ) const; - int itemId( int index ) const; - TQWidget* representative( int index ) const; - int containerCount() const; - /// @since 3.1 - uint kaccelCount() const; - - virtual bool hasIcon() const; -#ifndef KDE_NO_COMPAT - bool hasIconSet() const { return hasIcon(); } -#endif - virtual TQString plainText() const; - - /** - * Get the text associated with this action. - */ - virtual TQString text() const; - - /** - * Get the keyboard shortcut associated with this action. - */ - virtual const TDEShortcut& shortcut() const; - /** - * Get the default shortcut for this action. - */ - virtual const TDEShortcut& shortcutDefault() const; - - // These two methods are for TQ_PROPERTY - TQString shortcutText() const; - void setShortcutText( const TQString& ); - - /** - * Returns true if this action is enabled. - */ - virtual bool isEnabled() const; - - /** - * Returns true if this action's shortcut is configurable. - */ - virtual bool isShortcutConfigurable() const; - - virtual TQString group() const; - - /** - * Get the What's this text for the action. - */ - virtual TQString whatsThis() const; - - /** - * Get the tooltip text for the action. - */ - virtual TQString toolTip() const; - - /** - * Get the TQIconSet from which the icons used to display this action will - * be chosen. - * - * In KDE4 set group default to KIcon::Small while removing the other - * iconSet() function. - */ - virtual TQIconSet iconSet( KIcon::Group group, int size=0 ) const; - /** - * Remove in KDE4 - */ - TQIconSet iconSet() const { return iconSet( KIcon::Small ); } - - virtual TQString icon() const; - - TDEActionCollection *parentCollection() const; - - /** - * @internal - * Generate a toolbar button id. Made public for reimplementations. - */ - static int getToolButtonID(); - - - void unplugAll(); - - /** - * @since 3.4 - */ - enum ActivationReason { UnknownActivation, EmulatedActivation, AccelActivation, PopupMenuActivation, ToolBarActivation }; - -public slots: - /** - * Sets the text associated with this action. The text is used for menu - * and toolbar labels etc. - */ - virtual void setText(const TQString &text); - - /** - * Sets the keyboard shortcut associated with this action. - */ - virtual bool setShortcut( const TDEShortcut& ); - - virtual void setGroup( const TQString& ); - - /** - * Sets the What's this text for the action. This text will be displayed when - * a widget that has been created by plugging this action into a container - * is clicked on in What's this mode. - * - * The What's this text can include QML markup as well as raw text. - */ - virtual void setWhatsThis( const TQString& text ); - - /** - * Sets the tooltip text for the action. - * This will be used as a tooltip for a toolbar button, as a - * statusbar help-text for a menu item, and it also appears - * in the toolbar editor, to describe the action. - * - * For the tooltip to show up on the statusbar you will need to connect - * a couple of the actionclass signals to the toolbar. - * The easiest way of doing this is in your main window class, when you create - * a statusbar. See the TDEActionCollection class for more details. - * - * @see TDEActionCollection - * - */ - virtual void setToolTip( const TQString& ); - - /** - * Sets the TQIconSet from which the icons used to display this action will - * be chosen. - */ - virtual void setIconSet( const TQIconSet &iconSet ); - - virtual void setIcon( const TQString& icon ); - - /** - * Enables or disables this action. All uses of this action (eg. in menus - * or toolbars) will be updated to reflect the state of the action. - */ - virtual void setEnabled(bool enable); - - /** - * Calls setEnabled( !disable ). - * @since 3.5 - */ - void setDisabled(bool disable) { return setEnabled(!disable); } - - /** - * Indicate whether the user may configure the action's shortcut. - */ - virtual void setShortcutConfigurable( bool ); - - /** - * Emulate user's interaction programmatically, by activating the action. - * The implementation simply emits activated(). - */ - virtual void activate(); - -protected slots: - virtual void slotDestroyed(); - virtual void slotKeycodeChanged(); - virtual void slotActivated(); - /// @since 3.4 - void slotPopupActivated(); // KDE4: make virtual - /// @since 3.4 - void slotButtonClicked( int, TQt::ButtonState state ); // KDE4: make virtual - -protected: - TDEToolBar* toolBar( int index ) const; - TQPopupMenu* popupMenu( int index ) const; - void removeContainer( int index ); - int findContainer( const TQWidget* widget ) const; - int findContainer( int id ) const; - void plugMainWindowAccel( TQWidget *w ); - - void addContainer( TQWidget* parent, int id ); - void addContainer( TQWidget* parent, TQWidget* representative ); - - virtual void updateShortcut( int i ); - virtual void updateShortcut( TQPopupMenu* menu, int id ); - virtual void updateGroup( int id ); - virtual void updateText(int i ); - virtual void updateEnabled(int i); - virtual void updateIconSet(int i); - virtual void updateIcon( int i); - virtual void updateToolTip( int id ); - virtual void updateWhatsThis( int i ); - - TDEActionCollection *m_parentCollection; - TQString whatsThisWithIcon() const; - /** - * Return the underlying KGuiItem - * @since 3.3 - */ - const KGuiItem& guiItem() const; - -signals: - /** - * Emitted when this action is activated - */ - void activated(); - /** - * This signal allows to know the reason why an action was activated: - * whether it was due to a toolbar button, popupmenu, keyboard accel, or programmatically. - * In the first two cases, it also allows to know which mouse button was - * used (Left or Middle), and whether keyboard modifiers were pressed (e.g. CTRL). - * - * Note that this signal is emitted before the normal activated() signal. - * Yes, BOTH signals are always emitted, so that connecting to activated() still works. - * Applications which care about reason and state can either ignore the activated() - * signal for a given action and react to this one instead, or store the - * reason and state until the activated() signal is emitted. - * - * @since 3.4 - */ - void activated( TDEAction::ActivationReason reason, TQt::ButtonState state ); - void enabled( bool ); - -private: - void initPrivate( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot ); - TDEAccel* kaccelCurrent(); - bool initShortcut( const TDEShortcut& ); - void plugShortcut(); - bool updateTDEAccelShortcut( TDEAccel* kaccel ); - void insertTDEAccel( TDEAccel* ); - /** @internal To be used exclusively by TDEActionCollection::removeWidget(). */ - void removeTDEAccel( TDEAccel* ); - -#ifndef KDE_NO_COMPAT -public: - /** - * @deprecated. Use shortcut(). - * Get the keyboard accelerator associated with this action. - */ - int accel() const KDE_DEPRECATED; - - TQString statusText() const - { return toolTip(); } - - /** - * @deprecated. Use setShortcut(). - * Sets the keyboard accelerator associated with this action. - */ - void setAccel( int key ) KDE_DEPRECATED; - - /** - * @deprecated. Use setToolTip instead (they do the same thing now). - */ - void setStatusText( const TQString &text ) - { setToolTip( text ); } - - /** - * @deprecated. for backwards compatibility. Use itemId() - */ - int menuId( int i ) { return itemId( i ); } -#endif // !KDE_NO_COMPAT - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEActionPrivate; - TDEActionPrivate* const d; -}; - -#include -#include - -#endif diff --git a/tdeui/kactionclasses.cpp b/tdeui/kactionclasses.cpp deleted file mode 100644 index 87c9932a3..000000000 --- a/tdeui/kactionclasses.cpp +++ /dev/null @@ -1,2421 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999 Reginald Stadlbauer - (C) 1999 Simon Hausmann - (C) 2000 Nicolas Hadacek - (C) 2000 Kurt Granroth - (C) 2000 Michael Koch - (C) 2001 Holger Freyther - (C) 2002 Ellis Whitehead - (C) 2002 Joseph Wenninger - (C) 2003 Andras Mantia - - 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. -*/ - -#include "kactionclasses.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class TDEToggleAction::TDEToggleActionPrivate -{ -public: - TDEToggleActionPrivate() - { - m_checked = false; - m_checkedGuiItem = 0; - } - - bool m_checked; - TQString m_exclusiveGroup; - KGuiItem* m_checkedGuiItem; -}; - -TDEToggleAction::TDEToggleAction( const TQString& text, const TDEShortcut& cut, - TQObject* parent, - const char* name ) - : TDEAction( text, cut, parent, name ) -{ - d = new TDEToggleActionPrivate; -} - -TDEToggleAction::TDEToggleAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name ) - : TDEAction( text, cut, receiver, slot, parent, name ) -{ - d = new TDEToggleActionPrivate; -} - -TDEToggleAction::TDEToggleAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDEAction( text, pix, cut, parent, name ) -{ - d = new TDEToggleActionPrivate; -} - -TDEToggleAction::TDEToggleAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDEAction( text, pix, cut, parent, name ) -{ - d = new TDEToggleActionPrivate; -} - -TDEToggleAction::TDEToggleAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, TQObject* parent, - const char* name ) - : TDEAction( text, pix, cut, receiver, slot, parent, name ) -{ - d = new TDEToggleActionPrivate; -} - -TDEToggleAction::TDEToggleAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, TQObject* parent, - const char* name ) - : TDEAction( text, pix, cut, receiver, slot, parent, name ) -{ - d = new TDEToggleActionPrivate; -} - -TDEToggleAction::TDEToggleAction( TQObject* parent, const char* name ) - : TDEAction( parent, name ) -{ - d = new TDEToggleActionPrivate; -} - -TDEToggleAction::~TDEToggleAction() -{ - delete d->m_checkedGuiItem; - delete d; -} - -int TDEToggleAction::plug( TQWidget* widget, int index ) -{ - if ( !::tqqt_cast( widget ) && !::tqqt_cast( widget ) ) - { - kdWarning() << "Can not plug TDEToggleAction in " << widget->className() << endl; - return -1; - } - if (kapp && !kapp->authorizeTDEAction(name())) - return -1; - - int _index = TDEAction::plug( widget, index ); - if ( _index == -1 ) - return _index; - - if ( ::tqqt_cast( widget ) ) { - TDEToolBar *bar = static_cast( widget ); - - bar->setToggle( itemId( _index ), true ); - bar->setButton( itemId( _index ), isChecked() ); - } - - if ( d->m_checked ) - updateChecked( _index ); - - return _index; -} - -void TDEToggleAction::setChecked( bool c ) -{ - if ( c == d->m_checked ) - return; - //kdDebug(129) << "TDEToggleAction::setChecked(" << c << ") " << this << " " << name() << endl; - - d->m_checked = c; - - int len = containerCount(); - - for( int i = 0; i < len; ++i ) - updateChecked( i ); - - if ( c && parent() && !exclusiveGroup().isEmpty() ) { - const TQObjectList list = parent()->childrenListObject(); - if ( !list.isEmpty() ) { - TQObjectListIt it( list ); - for( ; it.current(); ++it ) { - if ( ::tqqt_cast( it.current() ) && it.current() != this && - static_cast(it.current())->exclusiveGroup() == exclusiveGroup() ) { - TDEToggleAction *a = static_cast(it.current()); - if( a->isChecked() ) { - a->setChecked( false ); - emit a->toggled( false ); - } - } - } - } - } -} - -void TDEToggleAction::updateChecked( int id ) -{ - TQWidget *w = container( id ); - - if ( ::tqqt_cast( w ) ) { - TQPopupMenu* pm = static_cast(w); - int itemId_ = itemId( id ); - if ( !d->m_checkedGuiItem ) - pm->setItemChecked( itemId_, d->m_checked ); - else { - const KGuiItem* gui = d->m_checked ? d->m_checkedGuiItem : &guiItem(); - if ( d->m_checkedGuiItem->hasIcon() ) - pm->changeItem( itemId_, gui->iconSet( KIcon::Small ), gui->text() ); - else - pm->changeItem( itemId_, gui->text() ); - - // If the text doesn't change, then set the icon to be "pressed", otherwise - // there is too little difference between checked and unchecked. - if ( d->m_checkedGuiItem->text() == guiItem().text() ) - pm->setItemChecked( itemId_, d->m_checked ); - - if ( !d->m_checkedGuiItem->whatsThis().isEmpty() ) // if empty, we keep the initial one - pm->TQMenuData::setWhatsThis( itemId_, gui->whatsThis() ); - updateShortcut( pm, itemId_ ); - } - } - else if ( ::tqqt_cast( w ) ) // not handled in plug... - static_cast(w)->setItemChecked( itemId( id ), d->m_checked ); - else if ( ::tqqt_cast( w ) ) - { - TQWidget* r = static_cast( w )->getButton( itemId( id ) ); - if ( r && ::tqqt_cast( r ) ) { - static_cast( w )->setButton( itemId( id ), d->m_checked ); - if ( d->m_checkedGuiItem && d->m_checkedGuiItem->hasIcon() ) { - const KGuiItem* gui = d->m_checked ? d->m_checkedGuiItem : &guiItem(); - static_cast( w )->setButtonIconSet( itemId( id ), gui->iconSet( KIcon::Toolbar ) ); - } - } - } -} - -void TDEToggleAction::slotActivated() -{ - setChecked( !isChecked() ); - TDEAction::slotActivated(); - emit toggled( isChecked() ); -} - -bool TDEToggleAction::isChecked() const -{ - return d->m_checked; -} - -void TDEToggleAction::setExclusiveGroup( const TQString& name ) -{ - d->m_exclusiveGroup = name; -} - -TQString TDEToggleAction::exclusiveGroup() const -{ - return d->m_exclusiveGroup; -} - -void TDEToggleAction::setCheckedState( const KGuiItem& checkedItem ) -{ - delete d->m_checkedGuiItem; - d->m_checkedGuiItem = new KGuiItem( checkedItem ); -} - -TQString TDEToggleAction::toolTip() const -{ - if ( d->m_checkedGuiItem && d->m_checked ) - return d->m_checkedGuiItem->toolTip(); - else - return TDEAction::toolTip(); -} - -TDERadioAction::TDERadioAction( const TQString& text, const TDEShortcut& cut, - TQObject* parent, const char* name ) -: TDEToggleAction( text, cut, parent, name ) -{ -} - -TDERadioAction::TDERadioAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name ) -: TDEToggleAction( text, cut, receiver, slot, parent, name ) -{ -} - -TDERadioAction::TDERadioAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) -: TDEToggleAction( text, pix, cut, parent, name ) -{ -} - -TDERadioAction::TDERadioAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) -: TDEToggleAction( text, pix, cut, parent, name ) -{ -} - -TDERadioAction::TDERadioAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name ) -: TDEToggleAction( text, pix, cut, receiver, slot, parent, name ) -{ -} - -TDERadioAction::TDERadioAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name ) -: TDEToggleAction( text, pix, cut, receiver, slot, parent, name ) -{ -} - -TDERadioAction::TDERadioAction( TQObject* parent, const char* name ) -: TDEToggleAction( parent, name ) -{ -} - -void TDERadioAction::slotActivated() -{ - if ( isChecked() ) - { - const TQObject *senderObj = TQT_TQOBJECT_CONST(sender()); - - if ( !senderObj || !::tqqt_cast( senderObj ) ) - return; - - const_cast( static_cast( TQT_TQWIDGET_CONST(senderObj) ) )->on( true ); - - return; - } - - TDEToggleAction::slotActivated(); -} - -class TDESelectAction::TDESelectActionPrivate -{ -public: - TDESelectActionPrivate() - { - m_edit = false; - m_menuAccelsEnabled = true; - m_menu = 0; - m_current = -1; - m_comboWidth = -1; - m_maxComboViewCount = -1; - } - bool m_edit; - bool m_menuAccelsEnabled; - TQPopupMenu *m_menu; - int m_current; - int m_comboWidth; - TQStringList m_list; - int m_maxComboViewCount; - - TQString makeMenuText( const TQString &_text ) - { - if ( m_menuAccelsEnabled ) - return _text; - TQString text = _text; - uint i = 0; - while ( i < text.length() ) { - if ( text[ i ] == '&' ) { - text.insert( i, '&' ); - i += 2; - } - else - ++i; - } - return text; - } -}; - -TDESelectAction::TDESelectAction( const TQString& text, const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDEAction( text, cut, parent, name ) -{ - d = new TDESelectActionPrivate; -} - -TDESelectAction::TDESelectAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name ) - : TDEAction( text, cut, receiver, slot, parent, name ) -{ - d = new TDESelectActionPrivate; -} - -TDESelectAction::TDESelectAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDEAction( text, pix, cut, parent, name ) -{ - d = new TDESelectActionPrivate; -} - -TDESelectAction::TDESelectAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDEAction( text, pix, cut, parent, name ) -{ - d = new TDESelectActionPrivate; -} - -TDESelectAction::TDESelectAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, TQObject* parent, - const char* name ) - : TDEAction( text, pix, cut, receiver, slot, parent, name ) -{ - d = new TDESelectActionPrivate; -} - -TDESelectAction::TDESelectAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, TQObject* parent, - const char* name ) - : TDEAction( text, pix, cut, receiver, slot, parent, name ) -{ - d = new TDESelectActionPrivate; -} - -TDESelectAction::TDESelectAction( TQObject* parent, const char* name ) - : TDEAction( parent, name ) -{ - d = new TDESelectActionPrivate; -} - -TDESelectAction::~TDESelectAction() -{ - assert(d); - delete d->m_menu; - delete d; d = 0; -} - -void TDESelectAction::setCurrentItem( int id ) -{ - if ( id >= (int)d->m_list.count() ) { - Q_ASSERT(id < (int)d->m_list.count()); - return; - } - - if ( d->m_menu ) - { - if ( d->m_current >= 0 ) - d->m_menu->setItemChecked( d->m_current, false ); - if ( id >= 0 ) - d->m_menu->setItemChecked( id, true ); - } - - d->m_current = id; - - int len = containerCount(); - - for( int i = 0; i < len; ++i ) - updateCurrentItem( i ); - - // emit TDEAction::activated(); - // emit activated( currentItem() ); - // emit activated( currentText() ); -} - -void TDESelectAction::setComboWidth( int width ) -{ - if ( width < 0 ) - return; - - d->m_comboWidth=width; - - int len = containerCount(); - - for( int i = 0; i < len; ++i ) - updateComboWidth( i ); - -} - -void TDESelectAction::setMaxComboViewCount( int n ) -{ - d->m_maxComboViewCount = n; -} - -TQPopupMenu* TDESelectAction::popupMenu() const -{ - kdDebug(129) << "TDEAction::popupMenu()" << endl; // remove -- ellis - if ( !d->m_menu ) - { - d->m_menu = new TDEPopupMenu(0L, "TDESelectAction::popupMenu()"); - setupMenu(); - if ( d->m_current >= 0 ) - d->m_menu->setItemChecked( d->m_current, true ); - } - - return d->m_menu; -} - -void TDESelectAction::setupMenu() const -{ - if ( !d->m_menu ) - return; - d->m_menu->clear(); - - TQStringList::ConstIterator it = d->m_list.begin(); - for( uint id = 0; it != d->m_list.end(); ++it, ++id ) { - TQString text = *it; - if ( !text.isEmpty() ) - d->m_menu->insertItem( d->makeMenuText( text ), this, TQT_SLOT( slotActivated( int ) ), 0, id ); - else - d->m_menu->insertSeparator(); - } -} - -void TDESelectAction::changeItem( int index, const TQString& text ) -{ - if ( index < 0 || index >= (int)d->m_list.count() ) - { - kdWarning() << "TDESelectAction::changeItem Index out of scope" << endl; - return; - } - - d->m_list[ index ] = text; - - if ( d->m_menu ) - d->m_menu->changeItem( index, d->makeMenuText( text ) ); - - int len = containerCount(); - for( int i = 0; i < len; ++i ) - changeItem( i, index, text ); -} - -void TDESelectAction::changeItem( int id, int index, const TQString& text) -{ - if ( index < 0 ) - return; - - TQWidget* w = container( id ); - if ( ::tqqt_cast( w ) ) - { - TQWidget* r = (static_cast( w ))->getWidget( itemId( id ) ); - if ( ::tqqt_cast( r ) ) - { - TQComboBox *b = static_cast( r ); - b->changeItem(text, index ); - } - } -} - -void TDESelectAction::setItems( const TQStringList &lst ) -{ - d->m_list = lst; - d->m_current = -1; - - setupMenu(); - - int len = containerCount(); - for( int i = 0; i < len; ++i ) - updateItems( i ); - - // Disable if empty and not editable - setEnabled ( lst.count() > 0 || d->m_edit ); -} - -TQStringList TDESelectAction::items() const -{ - return d->m_list; -} - -TQString TDESelectAction::currentText() const -{ - if ( currentItem() < 0 ) - return TQString::null; - - return d->m_list[ currentItem() ]; -} - -int TDESelectAction::currentItem() const -{ - return d->m_current; -} - -void TDESelectAction::updateCurrentItem( int id ) -{ - if ( d->m_current < 0 ) - return; - - TQWidget* w = container( id ); - if ( ::tqqt_cast( w ) ) { - TQWidget* r = static_cast( w )->getWidget( itemId( id ) ); - if ( ::tqqt_cast( r ) ) { - TQComboBox *b = static_cast( r ); - b->setCurrentItem( d->m_current ); - } - } -} - -int TDESelectAction::comboWidth() const -{ - return d->m_comboWidth; -} - -void TDESelectAction::updateComboWidth( int id ) -{ - TQWidget* w = container( id ); - if ( ::tqqt_cast( w ) ) { - TQWidget* r = static_cast( w )->getWidget( itemId( id ) ); - if ( ::tqqt_cast( r ) ) { - TQComboBox *cb = static_cast( r ); - cb->setMinimumWidth( d->m_comboWidth ); - cb->setMaximumWidth( d->m_comboWidth ); - } - } -} - -void TDESelectAction::updateItems( int id ) -{ - kdDebug(129) << "TDEAction::updateItems( " << id << ", lst )" << endl; // remove -- ellis - TQWidget* w = container( id ); - if ( ::tqqt_cast( w ) ) { - TQWidget* r = static_cast( w )->getWidget( itemId( id ) ); - if ( ::tqqt_cast( r ) ) { - TQComboBox *cb = static_cast( r ); - cb->clear(); - TQStringList lst = comboItems(); - TQStringList::ConstIterator it = lst.begin(); - for( ; it != lst.end(); ++it ) - cb->insertItem( *it ); - // qt caches and never recalculates the sizeHint() - // qcombobox.cpp recommends calling setFont to invalidate the sizeHint - // setFont sets own_font = True, so we're a bit mean and calll - // unsetFont which calls setFont and then overwrites the own_font - cb->unsetFont(); - } - } -} - -int TDESelectAction::plug( TQWidget *widget, int index ) -{ - if (kapp && !kapp->authorizeTDEAction(name())) - return -1; - kdDebug(129) << "TDESelectAction::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis - if ( ::tqqt_cast( widget) ) - { - // Create the PopupMenu and store it in m_menu - (void)popupMenu(); - - TQPopupMenu* menu = static_cast( widget ); - int id; - if ( hasIcon() ) - id = menu->insertItem( iconSet(), text(), d->m_menu, -1, index ); - else - id = menu->insertItem( text(), d->m_menu, -1, index ); - - if ( !isEnabled() ) - menu->setItemEnabled( id, false ); - - TQString wth = whatsThis(); - if ( !wth.isEmpty() ) - menu->TQMenuData::setWhatsThis( id, wth ); - - addContainer( menu, id ); - connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - return containerCount() - 1; - } - else if ( ::tqqt_cast( widget ) ) - { - TDEToolBar* bar = static_cast( widget ); - int id_ = TDEAction::getToolButtonID(); - bar->insertCombo( comboItems(), id_, isEditable(), - TQT_SIGNAL( activated( const TQString & ) ), this, - TQT_SLOT( slotActivated( const TQString & ) ), isEnabled(), - toolTip(), -1, index ); - - TQComboBox *cb = bar->getCombo( id_ ); - if ( cb ) - { - if (!isEditable()) cb->setFocusPolicy(TQ_NoFocus); - cb->setMinimumWidth( cb->sizeHint().width() ); - if ( d->m_comboWidth > 0 ) - { - cb->setMinimumWidth( d->m_comboWidth ); - cb->setMaximumWidth( d->m_comboWidth ); - } - cb->setInsertionPolicy( TQComboBox::NoInsertion ); - TQWhatsThis::add( cb, whatsThis() ); - if ( d->m_maxComboViewCount != -1 ) cb->setSizeLimit( d->m_maxComboViewCount ); - } - - addContainer( bar, id_ ); - - connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - updateCurrentItem( containerCount() - 1 ); - - return containerCount() - 1; - } - else if ( ::tqqt_cast( widget ) ) - { - // Create the PopupMenu and store it in m_menu - (void)popupMenu(); - - TQMenuBar* menu = static_cast( widget ); - int id = menu->insertItem( text(), d->m_menu, -1, index ); - - if ( !isEnabled() ) - menu->setItemEnabled( id, false ); - - TQString wth = whatsThis(); - if ( !wth.isEmpty() ) - menu->TQMenuData::setWhatsThis( id, wth ); - - addContainer( menu, id ); - connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - return containerCount() - 1; - } - - kdWarning() << "Can not plug TDEAction in " << widget->className() << endl; - return -1; -} - -TQStringList TDESelectAction::comboItems() const -{ - if( d->m_menuAccelsEnabled ) { - TQStringList lst; - TQStringList::ConstIterator it = d->m_list.begin(); - for( ; it != d->m_list.end(); ++it ) - { - TQString item = *it; - int i = item.find( '&' ); - if ( i > -1 ) - item = item.remove( i, 1 ); - lst.append( item ); - } - return lst; - } - else - return d->m_list; -} - -void TDESelectAction::clear() -{ - if ( d->m_menu ) - d->m_menu->clear(); - - int len = containerCount(); - for( int i = 0; i < len; ++i ) - updateClear( i ); -} - -void TDESelectAction::updateClear( int id ) -{ - TQWidget* w = container( id ); - if ( ::tqqt_cast( w ) ) { - TQWidget* r = static_cast( w )->getWidget( itemId( id ) ); - if ( ::tqqt_cast( r ) ) { - TQComboBox *b = static_cast( r ); - b->clear(); - } - } -} - -void TDESelectAction::slotActivated( int id ) -{ - if ( d->m_current == id ) - return; - - setCurrentItem( id ); - // Delay this. Especially useful when the slot connected to activated() will re-create - // the menu, e.g. in the recent files action. This prevents a crash. - TQTimer::singleShot( 0, this, TQT_SLOT( slotActivated() ) ); -} - -void TDESelectAction::slotActivated( const TQString &text ) -{ - if ( isEditable() ) - { - TQStringList lst = d->m_list; - if(!lst.contains(text)) - { - lst.append( text ); - setItems( lst ); - } - } - - int i = d->m_list.findIndex( text ); - if ( i > -1 ) - setCurrentItem( i ); - else - setCurrentItem( comboItems().findIndex( text ) ); - // Delay this. Especially useful when the slot connected to activated() will re-create - // the menu, e.g. in the recent files action. This prevents a crash. - TQTimer::singleShot( 0, this, TQT_SLOT( slotActivated() ) ); -} - -void TDESelectAction::slotActivated() -{ - TDEAction::slotActivated(); - kdDebug(129) << "TDESelectAction::slotActivated currentItem=" << currentItem() << " currentText=" << currentText() << endl; - emit activated( currentItem() ); - emit activated( currentText() ); -} - -void TDESelectAction::setEditable( bool edit ) -{ - d->m_edit = edit; -} - -bool TDESelectAction::isEditable() const -{ - return d->m_edit; -} - -void TDESelectAction::setRemoveAmpersandsInCombo( bool b ) -{ - setMenuAccelsEnabled( b ); -} - -bool TDESelectAction::removeAmpersandsInCombo() const -{ - return menuAccelsEnabled( ); -} - -void TDESelectAction::setMenuAccelsEnabled( bool b ) -{ - d->m_menuAccelsEnabled = b; -} - -bool TDESelectAction::menuAccelsEnabled() const -{ - return d->m_menuAccelsEnabled; -} - -class TDEListAction::TDEListActionPrivate -{ -public: - TDEListActionPrivate() - { - m_current = 0; - } - int m_current; -}; - -TDEListAction::TDEListAction( const TQString& text, const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDESelectAction( text, cut, parent, name ) -{ - d = new TDEListActionPrivate; -} - -TDEListAction::TDEListAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name ) - : TDESelectAction( text, cut, parent, name ) -{ - d = new TDEListActionPrivate; - if ( receiver ) - connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot ); -} - -TDEListAction::TDEListAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDESelectAction( text, pix, cut, parent, name ) -{ - d = new TDEListActionPrivate; -} - -TDEListAction::TDEListAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDESelectAction( text, pix, cut, parent, name ) -{ - d = new TDEListActionPrivate; -} - -TDEListAction::TDEListAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, const TQObject* receiver, - const char* slot, TQObject* parent, - const char* name ) - : TDESelectAction( text, pix, cut, parent, name ) -{ - d = new TDEListActionPrivate; - if ( receiver ) - connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot ); -} - -TDEListAction::TDEListAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, const TQObject* receiver, - const char* slot, TQObject* parent, - const char* name ) - : TDESelectAction( text, pix, cut, parent, name ) -{ - d = new TDEListActionPrivate; - if ( receiver ) - connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot ); -} - -TDEListAction::TDEListAction( TQObject* parent, const char* name ) - : TDESelectAction( parent, name ) -{ - d = new TDEListActionPrivate; -} - -TDEListAction::~TDEListAction() -{ - delete d; d = 0; -} - -void TDEListAction::setCurrentItem( int index ) -{ - TDESelectAction::setCurrentItem( index ); - d->m_current = index; - - // emit TDEAction::activated(); - // emit activated( currentItem() ); - // emit activated( currentText() ); -} - -TQString TDEListAction::currentText() const -{ - return TDESelectAction::currentText(); -} - -int TDEListAction::currentItem() const -{ - return d->m_current; -} - -class TDERecentFilesAction::TDERecentFilesActionPrivate -{ -public: - TDERecentFilesActionPrivate() - { - m_maxItems = 0; - m_popup = 0; - } - uint m_maxItems; - TDEPopupMenu *m_popup; - TQMap m_shortNames; - TQMap m_urls; -}; - -TDERecentFilesAction::TDERecentFilesAction( const TQString& text, - const TDEShortcut& cut, - TQObject* parent, const char* name, - uint maxItems ) - : TDEListAction( text, cut, parent, name) -{ - d = new TDERecentFilesActionPrivate; - d->m_maxItems = maxItems; - - init(); -} - -TDERecentFilesAction::TDERecentFilesAction( const TQString& text, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, - TQObject* parent, const char* name, - uint maxItems ) - : TDEListAction( text, cut, parent, name) -{ - d = new TDERecentFilesActionPrivate; - d->m_maxItems = maxItems; - - init(); - - if ( receiver ) - connect( this, TQT_SIGNAL(urlSelected(const KURL&)), - receiver, slot ); -} - -TDERecentFilesAction::TDERecentFilesAction( const TQString& text, - const TQIconSet& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name, - uint maxItems ) - : TDEListAction( text, pix, cut, parent, name) -{ - d = new TDERecentFilesActionPrivate; - d->m_maxItems = maxItems; - - init(); -} - -TDERecentFilesAction::TDERecentFilesAction( const TQString& text, - const TQString& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name, - uint maxItems ) - : TDEListAction( text, pix, cut, parent, name) -{ - d = new TDERecentFilesActionPrivate; - d->m_maxItems = maxItems; - - init(); -} - -TDERecentFilesAction::TDERecentFilesAction( const TQString& text, - const TQIconSet& pix, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, - TQObject* parent, const char* name, - uint maxItems ) - : TDEListAction( text, pix, cut, parent, name) -{ - d = new TDERecentFilesActionPrivate; - d->m_maxItems = maxItems; - - init(); - - if ( receiver ) - connect( this, TQT_SIGNAL(urlSelected(const KURL&)), - receiver, slot ); -} - -TDERecentFilesAction::TDERecentFilesAction( const TQString& text, - const TQString& pix, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, - TQObject* parent, const char* name, - uint maxItems ) - : TDEListAction( text, pix, cut, parent, name) -{ - d = new TDERecentFilesActionPrivate; - d->m_maxItems = maxItems; - - init(); - - if ( receiver ) - connect( this, TQT_SIGNAL(urlSelected(const KURL&)), - receiver, slot ); -} - -TDERecentFilesAction::TDERecentFilesAction( TQObject* parent, const char* name, - uint maxItems ) - : TDEListAction( parent, name ) -{ - d = new TDERecentFilesActionPrivate; - d->m_maxItems = maxItems; - - init(); -} - -void TDERecentFilesAction::init() -{ - TDERecentFilesAction *that = const_cast(this); - that->d->m_popup = new TDEPopupMenu; - connect(d->m_popup, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(menuAboutToShow())); - connect(d->m_popup, TQT_SIGNAL(activated(int)), this, TQT_SLOT(menuItemActivated(int))); - connect( this, TQT_SIGNAL( activated( const TQString& ) ), - this, TQT_SLOT( itemSelected( const TQString& ) ) ); - - setMenuAccelsEnabled( false ); -} - -TDERecentFilesAction::~TDERecentFilesAction() -{ - delete d->m_popup; - delete d; d = 0; -} - -uint TDERecentFilesAction::maxItems() const -{ - return d->m_maxItems; -} - -void TDERecentFilesAction::setMaxItems( uint maxItems ) -{ - TQStringList lst = TDESelectAction::items(); - uint oldCount = lst.count(); - - // set new maxItems - d->m_maxItems = maxItems; - - // remove all items that are too much - while( lst.count() > maxItems ) - { - // remove last item - TQString lastItem = lst.last(); - d->m_shortNames.erase( lastItem ); - d->m_urls.erase( lastItem ); - lst.remove( lastItem ); - } - - // set new list if changed - if( lst.count() != oldCount ) - setItems( lst ); -} - -void TDERecentFilesAction::addURL( const KURL& url ) -{ - addURL( url, url.fileName() ); -} - -void TDERecentFilesAction::addURL( const KURL& url, const TQString& name ) -{ - if ( url.isLocalFile() && !TDEGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/")) - return; - const TQString file = url.pathOrURL(); - TQStringList lst = TDESelectAction::items(); - - // remove file if already in list - const TQStringList::Iterator end = lst.end(); - for ( TQStringList::Iterator it = lst.begin(); it != end; ++it ) - { - TQString title = (*it); - if ( title.endsWith( file + "]" ) ) - { - lst.remove( it ); - d->m_urls.erase( title ); - d->m_shortNames.erase( title ); - break; - } - } - // remove last item if already maxitems in list - if( lst.count() == d->m_maxItems ) - { - // remove last item - const TQString lastItem = lst.last(); - d->m_shortNames.erase( lastItem ); - d->m_urls.erase( lastItem ); - lst.remove( lastItem ); - } - - // add file to list - const TQString title = name + " [" + file + "]"; - d->m_shortNames.insert( title, name ); - d->m_urls.insert( title, url ); - lst.prepend( title ); - setItems( lst ); -} - -void TDERecentFilesAction::removeURL( const KURL& url ) -{ - TQStringList lst = TDESelectAction::items(); - TQString file = url.pathOrURL(); - - // remove url - TQStringList::Iterator end = lst.end(); - for ( TQStringList::Iterator it = lst.begin(); it != end; ++it ) - { - if ( (*it).endsWith( file + "]" )) - { - d->m_shortNames.erase( (*it) ); - d->m_urls.erase( (*it) ); - lst.remove( it ); - setItems( lst ); - break; - } - } -} - -void TDERecentFilesAction::clearURLList() -{ - clear(); - d->m_shortNames.clear(); - d->m_urls.clear(); -} - -void TDERecentFilesAction::loadEntries( TDEConfig* config, TQString groupname) -{ - TQString key; - TQString value; - TQString nameKey; - TQString nameValue; - TQString title; - TQString oldGroup; - TQStringList lst; - KURL url; - - oldGroup = config->group(); - - if (groupname.isEmpty()) - groupname = "RecentFiles"; - config->setGroup( groupname ); - - // read file list - for( unsigned int i = 1 ; i <= d->m_maxItems ; i++ ) - { - key = TQString( "File%1" ).arg( i ); - value = config->readPathEntry( key ); - url = KURL::fromPathOrURL( value ); - - // Don't restore if file doesn't exist anymore - if (url.isLocalFile() && !TQFile::exists(url.path())) - continue; - - nameKey = TQString( "Name%1" ).arg( i ); - nameValue = config->readPathEntry( nameKey, url.fileName() ); - title = nameValue + " [" + value + "]"; - if (!value.isNull()) - { - lst.append( title ); - d->m_shortNames.insert( title, nameValue ); - d->m_urls.insert( title, url ); - } - } - - // set file - setItems( lst ); - - config->setGroup( oldGroup ); -} - -void TDERecentFilesAction::saveEntries( TDEConfig* config, TQString groupname ) -{ - TQString key; - TQString value; - TQString oldGroup; - TQStringList lst = TDESelectAction::items(); - - oldGroup = config->group(); - - if (groupname.isEmpty()) - groupname = "RecentFiles"; - config->deleteGroup( groupname, true ); - config->setGroup( groupname ); - - // write file list - for( unsigned int i = 1 ; i <= lst.count() ; i++ ) - { - //kdDebug(129) << "Entry for " << lst[i-1] << d->m_urls[ lst[ i - 1 ] ] << endl; - key = TQString( "File%1" ).arg( i ); - value = d->m_urls[ lst[ i - 1 ] ].pathOrURL(); - config->writePathEntry( key, value ); - key = TQString( "Name%1" ).arg( i ); - value = d->m_shortNames[ lst[ i - 1 ] ]; - config->writePathEntry( key, value ); - } - - config->setGroup( oldGroup ); -} - -void TDERecentFilesAction::itemSelected( const TQString& text ) -{ - //return a copy of the URL since the slot where it is connected might call - //addURL or removeURL where the d->m_urls.erase( title ) could destroy the - //d->m_urls[ text ] and the emitted URL will be invalid in the rest of the slot - emit urlSelected( KURL(d->m_urls[ text ]) ); -} - -void TDERecentFilesAction::menuItemActivated( int id ) -{ - TQString text = d->m_popup->text(id); - //return a copy of the URL since the slot where it is connected might call - //addURL or removeURL where the d->m_urls.erase( title ) could destroy the - //d->m_urls[ text ] and the emitted URL will be invalid in the rest of the slot - emit urlSelected( KURL(d->m_urls[ text ]) ); -} - -void TDERecentFilesAction::menuAboutToShow() -{ - TDEPopupMenu *menu = d->m_popup; - menu->clear(); - TQStringList list = TDESelectAction::items(); - for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) - { - menu->insertItem(*it); - } -} - -int TDERecentFilesAction::plug( TQWidget *widget, int index ) -{ - if (kapp && !kapp->authorizeTDEAction(name())) - return -1; - // This is very related to TDEActionMenu::plug. - // In fact this class could be an interesting base class for TDEActionMenu - if ( ::tqqt_cast( widget ) ) - { - TDEToolBar *bar = (TDEToolBar *)widget; - - int id_ = TDEAction::getToolButtonID(); - - TDEInstance * instance; - if ( m_parentCollection ) - instance = m_parentCollection->instance(); - else - instance = TDEGlobal::instance(); - - bar->insertButton( icon(), id_, TQT_SIGNAL( clicked() ), this, - TQT_SLOT( slotClicked() ), isEnabled(), plainText(), - index, instance ); - - addContainer( bar, id_ ); - - connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - bar->setDelayedPopup( id_, d->m_popup, true); - - if ( !whatsThis().isEmpty() ) - TQWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() ); - - return containerCount() - 1; - } - - return TDEListAction::plug( widget, index ); -} - -void TDERecentFilesAction::slotClicked() -{ - TDEAction::slotActivated(); -} - -void TDERecentFilesAction::slotActivated(const TQString& text) -{ - TDEListAction::slotActivated(text); -} - - -void TDERecentFilesAction::slotActivated(int id) -{ - TDEListAction::slotActivated(id); -} - - -void TDERecentFilesAction::slotActivated() -{ - emit activated( currentItem() ); - emit activated( currentText() ); -} - -//KDE4: rename to urls() and return a KURL::List -TQStringList TDERecentFilesAction::items() const -{ - TQStringList lst = TDESelectAction::items(); - TQStringList result; - - for( unsigned int i = 1 ; i <= lst.count() ; i++ ) - { - result += d->m_urls[ lst[ i - 1 ] ].prettyURL(0, KURL::StripFileProtocol); - } - - return result; -} - -//KDE4: remove -TQStringList TDERecentFilesAction::completeItems() const -{ - return TDESelectAction::items(); -} - - -class TDEFontAction::TDEFontActionPrivate -{ -public: - TDEFontActionPrivate() - { - } - TQStringList m_fonts; -}; - -TDEFontAction::TDEFontAction( const TQString& text, - const TDEShortcut& cut, TQObject* parent, - const char* name ) - : TDESelectAction( text, cut, parent, name ) -{ - d = new TDEFontActionPrivate; - TDEFontChooser::getFontList( d->m_fonts, 0 ); - TDESelectAction::setItems( d->m_fonts ); - setEditable( true ); -} - -TDEFontAction::TDEFontAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name ) - : TDESelectAction( text, cut, receiver, slot, parent, name ) -{ - d = new TDEFontActionPrivate; - TDEFontChooser::getFontList( d->m_fonts, 0 ); - TDESelectAction::setItems( d->m_fonts ); - setEditable( true ); -} - -TDEFontAction::TDEFontAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDESelectAction( text, pix, cut, parent, name ) -{ - d = new TDEFontActionPrivate; - TDEFontChooser::getFontList( d->m_fonts, 0 ); - TDESelectAction::setItems( d->m_fonts ); - setEditable( true ); -} - -TDEFontAction::TDEFontAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDESelectAction( text, pix, cut, parent, name ) -{ - d = new TDEFontActionPrivate; - TDEFontChooser::getFontList( d->m_fonts, 0 ); - TDESelectAction::setItems( d->m_fonts ); - setEditable( true ); -} - -TDEFontAction::TDEFontAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name ) - : TDESelectAction( text, pix, cut, receiver, slot, parent, name ) -{ - d = new TDEFontActionPrivate; - TDEFontChooser::getFontList( d->m_fonts, 0 ); - TDESelectAction::setItems( d->m_fonts ); - setEditable( true ); -} - -TDEFontAction::TDEFontAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name ) - : TDESelectAction( text, pix, cut, receiver, slot, parent, name ) -{ - d = new TDEFontActionPrivate; - TDEFontChooser::getFontList( d->m_fonts, 0 ); - TDESelectAction::setItems( d->m_fonts ); - setEditable( true ); -} - -TDEFontAction::TDEFontAction( uint fontListCriteria, const TQString& text, - const TDEShortcut& cut, TQObject* parent, - const char* name ) - : TDESelectAction( text, cut, parent, name ) -{ - d = new TDEFontActionPrivate; - TDEFontChooser::getFontList( d->m_fonts, fontListCriteria ); - TDESelectAction::setItems( d->m_fonts ); - setEditable( true ); -} - -TDEFontAction::TDEFontAction( uint fontListCriteria, const TQString& text, const TQString& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDESelectAction( text, pix, cut, parent, name ) -{ - d = new TDEFontActionPrivate; - TDEFontChooser::getFontList( d->m_fonts, fontListCriteria ); - TDESelectAction::setItems( d->m_fonts ); - setEditable( true ); -} - -TDEFontAction::TDEFontAction( TQObject* parent, const char* name ) - : TDESelectAction( parent, name ) -{ - d = new TDEFontActionPrivate; - TDEFontChooser::getFontList( d->m_fonts, 0 ); - TDESelectAction::setItems( d->m_fonts ); - setEditable( true ); -} - -TDEFontAction::~TDEFontAction() -{ - delete d; - d = 0; -} - -/* - * Maintenance note: Keep in sync with TDEFontCombo::setCurrentFont() - */ -void TDEFontAction::setFont( const TQString &family ) -{ - TQString lowerName = family.lower(); - int i = 0; - for ( TQStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) - { - if ((*it).lower() == lowerName) - { - setCurrentItem(i); - return; - } - } - i = lowerName.find(" ["); - if (i>-1) - { - lowerName = lowerName.left(i); - i = 0; - for ( TQStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) - { - if ((*it).lower() == lowerName) - { - setCurrentItem(i); - return; - } - } - } - - lowerName += " ["; - i = 0; - for ( TQStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) - { - if ((*it).lower().startsWith(lowerName)) - { - setCurrentItem(i); - return; - } - } - - // nothing matched yet, try a fontconfig reverse lookup and - // check again to solve an alias - FcPattern *pattern = NULL; - FcConfig *config = NULL; - TQString realFamily; - TQRegExp regExp("[-:]"); - pattern = FcNameParse( (unsigned char*) family.ascii() ); - FcDefaultSubstitute(pattern); - FcConfigSubstitute (config, pattern, FcMatchPattern); - pattern = FcFontMatch(NULL, pattern, NULL); - realFamily = (char*)FcNameUnparse(pattern); - realFamily.remove(realFamily.find(regExp), realFamily.length()); - - if ( !realFamily.isEmpty() && realFamily != family ) - setFont( realFamily ); - else - kdDebug(129) << "Font not found " << family.lower() << endl; -} - -int TDEFontAction::plug( TQWidget *w, int index ) -{ - if (kapp && !kapp->authorizeTDEAction(name())) - return -1; - if ( ::tqqt_cast( w ) ) - { - TDEToolBar* bar = static_cast( w ); - int id_ = TDEAction::getToolButtonID(); - TDEFontCombo *cb = new TDEFontCombo( items(), bar ); - connect( cb, TQT_SIGNAL( activated( const TQString & ) ), - TQT_SLOT( slotActivated( const TQString & ) ) ); - cb->setEnabled( isEnabled() ); - bar->insertWidget( id_, comboWidth(), cb, index ); - cb->setMinimumWidth( cb->sizeHint().width() ); - - addContainer( bar, id_ ); - - connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - updateCurrentItem( containerCount() - 1 ); - - return containerCount() - 1; - } - else return TDESelectAction::plug( w, index ); -} - -class TDEFontSizeAction::TDEFontSizeActionPrivate -{ -public: - TDEFontSizeActionPrivate() - { - } -}; - -TDEFontSizeAction::TDEFontSizeAction( const TQString& text, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDESelectAction( text, cut, parent, name ) -{ - init(); -} - -TDEFontSizeAction::TDEFontSizeAction( const TQString& text, - const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name ) - : TDESelectAction( text, cut, receiver, slot, parent, name ) -{ - init(); -} - -TDEFontSizeAction::TDEFontSizeAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDESelectAction( text, pix, cut, parent, name ) -{ - init(); -} - -TDEFontSizeAction::TDEFontSizeAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDESelectAction( text, pix, cut, parent, name ) -{ - init(); -} - -TDEFontSizeAction::TDEFontSizeAction( const TQString& text, const TQIconSet& pix, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, TQObject* parent, - const char* name ) - : TDESelectAction( text, pix, cut, receiver, slot, parent, name ) -{ - init(); -} - -TDEFontSizeAction::TDEFontSizeAction( const TQString& text, const TQString& pix, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, TQObject* parent, - const char* name ) - : TDESelectAction( text, pix, cut, receiver, slot, parent, name ) -{ - init(); -} - -TDEFontSizeAction::TDEFontSizeAction( TQObject* parent, const char* name ) - : TDESelectAction( parent, name ) -{ - init(); -} - -TDEFontSizeAction::~TDEFontSizeAction() -{ - delete d; - d = 0; -} - -void TDEFontSizeAction::init() -{ - d = new TDEFontSizeActionPrivate; - - setEditable( true ); - TQFontDatabase fontDB; - TQValueList sizes = fontDB.standardSizes(); - TQStringList lst; - for ( TQValueList::Iterator it = sizes.begin(); it != sizes.end(); ++it ) - lst.append( TQString::number( *it ) ); - - setItems( lst ); -} - -void TDEFontSizeAction::setFontSize( int size ) -{ - if ( size == fontSize() ) { - setCurrentItem( items().findIndex( TQString::number( size ) ) ); - return; - } - - if ( size < 1 ) { - kdWarning() << "TDEFontSizeAction: Size " << size << " is out of range" << endl; - return; - } - - int index = items().findIndex( TQString::number( size ) ); - if ( index == -1 ) { - // Insert at the correct position in the list (to keep sorting) - TQValueList lst; - // Convert to list of ints - TQStringList itemsList = items(); - for (TQStringList::Iterator it = itemsList.begin() ; it != itemsList.end() ; ++it) - lst.append( (*it).toInt() ); - // New size - lst.append( size ); - // Sort the list - qHeapSort( lst ); - // Convert back to string list - TQStringList strLst; - for (TQValueList::Iterator it = lst.begin() ; it != lst.end() ; ++it) - strLst.append( TQString::number(*it) ); - TDESelectAction::setItems( strLst ); - // Find new current item - index = lst.findIndex( size ); - setCurrentItem( index ); - } - else - setCurrentItem( index ); - - - //emit TDEAction::activated(); - //emit activated( index ); - //emit activated( TQString::number( size ) ); - //emit fontSizeChanged( size ); -} - -int TDEFontSizeAction::fontSize() const -{ - return currentText().toInt(); -} - -void TDEFontSizeAction::slotActivated( int index ) -{ - TDESelectAction::slotActivated( index ); - - emit fontSizeChanged( items()[ index ].toInt() ); -} - -void TDEFontSizeAction::slotActivated( const TQString& size ) -{ - setFontSize( size.toInt() ); // insert sorted first - TDESelectAction::slotActivated( size ); - emit fontSizeChanged( size.toInt() ); -} - -class TDEActionMenu::TDEActionMenuPrivate -{ -public: - TDEActionMenuPrivate() - { - m_popup = new TDEPopupMenu(0L,"TDEActionMenu::TDEActionMenuPrivate"); - m_delayed = true; - m_stickyMenu = true; - } - ~TDEActionMenuPrivate() - { - delete m_popup; m_popup = 0; - } - TDEPopupMenu *m_popup; - bool m_delayed; - bool m_stickyMenu; -}; - -TDEActionMenu::TDEActionMenu( TQObject* parent, const char* name ) - : TDEAction( parent, name ) -{ - d = new TDEActionMenuPrivate; - setShortcutConfigurable( false ); -} - -TDEActionMenu::TDEActionMenu( const TQString& text, TQObject* parent, - const char* name ) - : TDEAction( text, 0, parent, name ) -{ - d = new TDEActionMenuPrivate; - setShortcutConfigurable( false ); -} - -TDEActionMenu::TDEActionMenu( const TQString& text, const TQIconSet& icon, - TQObject* parent, const char* name ) - : TDEAction( text, icon, 0, parent, name ) -{ - d = new TDEActionMenuPrivate; - setShortcutConfigurable( false ); -} - -TDEActionMenu::TDEActionMenu( const TQString& text, const TQString& icon, - TQObject* parent, const char* name ) - : TDEAction( text, icon, 0, parent, name ) -{ - d = new TDEActionMenuPrivate; - setShortcutConfigurable( false ); -} - -TDEActionMenu::~TDEActionMenu() -{ - unplugAll(); - kdDebug(129) << "TDEActionMenu::~TDEActionMenu()" << endl; // ellis - delete d; d = 0; -} - -void TDEActionMenu::popup( const TQPoint& global ) -{ - popupMenu()->popup( global ); -} - -TDEPopupMenu* TDEActionMenu::popupMenu() const -{ - return d->m_popup; -} - -void TDEActionMenu::insert( TDEAction* cmd, int index ) -{ - if ( cmd ) - cmd->plug( d->m_popup, index ); -} - -void TDEActionMenu::remove( TDEAction* cmd ) -{ - if ( cmd ) - cmd->unplug( d->m_popup ); -} - -bool TDEActionMenu::delayed() const { - return d->m_delayed; -} - -void TDEActionMenu::setDelayed(bool _delayed) { - d->m_delayed = _delayed; -} - -bool TDEActionMenu::stickyMenu() const { - return d->m_stickyMenu; -} - -void TDEActionMenu::setStickyMenu(bool sticky) { - d->m_stickyMenu = sticky; -} - -int TDEActionMenu::plug( TQWidget* widget, int index ) -{ - if (kapp && !kapp->authorizeTDEAction(name())) - return -1; - kdDebug(129) << "TDEActionMenu::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis - if ( ::tqqt_cast( widget ) ) - { - TQPopupMenu* menu = static_cast( widget ); - int id; - if ( hasIcon() ) - id = menu->insertItem( iconSet(), text(), d->m_popup, -1, index ); - else - id = menu->insertItem( text(), d->m_popup, -1, index ); - - if ( !isEnabled() ) - menu->setItemEnabled( id, false ); - - addContainer( menu, id ); - connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - if ( m_parentCollection ) - m_parentCollection->connectHighlight( menu, this ); - - return containerCount() - 1; - } - else if ( ::tqqt_cast( widget ) ) - { - TDEToolBar *bar = static_cast( widget ); - - int id_ = TDEAction::getToolButtonID(); - - if ( icon().isEmpty() && !iconSet().isNull() ) - bar->insertButton( iconSet().pixmap(), id_, TQT_SIGNAL( clicked() ), this, - TQT_SLOT( slotActivated() ), isEnabled(), plainText(), - index ); - else - { - TDEInstance *instance; - - if ( m_parentCollection ) - instance = m_parentCollection->instance(); - else - instance = TDEGlobal::instance(); - - bar->insertButton( icon(), id_, TQT_SIGNAL( clicked() ), this, - TQT_SLOT( slotActivated() ), isEnabled(), plainText(), - index, instance ); - } - - addContainer( bar, id_ ); - - if (!whatsThis().isEmpty()) - TQWhatsThis::add( bar->getButton(id_), whatsThis() ); - - connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - if (delayed()) { - bar->setDelayedPopup( id_, popupMenu(), stickyMenu() ); - } else { - bar->getButton(id_)->setPopup(popupMenu(), stickyMenu() ); - } - - if ( m_parentCollection ) - m_parentCollection->connectHighlight( bar, this ); - - return containerCount() - 1; - } - else if ( ::tqqt_cast( widget ) ) - { - TQMenuBar *bar = static_cast( widget ); - - int id; - - id = bar->insertItem( text(), popupMenu(), -1, index ); - - if ( !isEnabled() ) - bar->setItemEnabled( id, false ); - - addContainer( bar, id ); - connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - return containerCount() - 1; - } - - return -1; -} - -//////// - -TDEToolBarPopupAction::TDEToolBarPopupAction( const TQString& text, - const TQString& icon, - const TDEShortcut& cut, - TQObject* parent, const char* name ) - : TDEAction( text, icon, cut, parent, name ) -{ - m_popup = 0; - m_delayed = true; - m_stickyMenu = true; -} - -TDEToolBarPopupAction::TDEToolBarPopupAction( const TQString& text, - const TQString& icon, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, TQObject* parent, - const char* name ) - : TDEAction( text, icon, cut, receiver, slot, parent, name ) -{ - m_popup = 0; - m_delayed = true; - m_stickyMenu = true; -} - -TDEToolBarPopupAction::TDEToolBarPopupAction( const KGuiItem& item, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, TDEActionCollection* parent, - const char* name ) - : TDEAction( item, cut, receiver, slot, parent, name ) -{ - m_popup = 0; - m_delayed = true; - m_stickyMenu = true; -} - -TDEToolBarPopupAction::~TDEToolBarPopupAction() -{ - delete m_popup; -} - -bool TDEToolBarPopupAction::delayed() const { - return m_delayed; -} - -void TDEToolBarPopupAction::setDelayed(bool delayed) { - m_delayed = delayed; -} - -bool TDEToolBarPopupAction::stickyMenu() const { - return m_stickyMenu; -} - -void TDEToolBarPopupAction::setStickyMenu(bool sticky) { - m_stickyMenu = sticky; -} - -int TDEToolBarPopupAction::plug( TQWidget *widget, int index ) -{ - if (kapp && !kapp->authorizeTDEAction(name())) - return -1; - // This is very related to TDEActionMenu::plug. - // In fact this class could be an interesting base class for TDEActionMenu - if ( ::tqqt_cast( widget ) ) - { - TDEToolBar *bar = (TDEToolBar *)widget; - - int id_ = TDEAction::getToolButtonID(); - - if ( icon().isEmpty() && !iconSet().isNull() ) { - bar->insertButton( iconSet().pixmap(), id_, TQT_SIGNAL( buttonClicked(int, TQt::ButtonState) ), this, - TQT_SLOT( slotButtonClicked(int, TQt::ButtonState) ), - isEnabled(), plainText(), - index ); - } else { - TDEInstance * instance; - if ( m_parentCollection ) - instance = m_parentCollection->instance(); - else - instance = TDEGlobal::instance(); - - bar->insertButton( icon(), id_, TQT_SIGNAL( buttonClicked(int, TQt::ButtonState) ), this, - TQT_SLOT( slotButtonClicked(int, TQt::ButtonState) ), - isEnabled(), plainText(), - index, instance ); - } - - addContainer( bar, id_ ); - - connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - if (delayed()) { - bar->setDelayedPopup( id_, popupMenu(), stickyMenu() ); - } else { - bar->getButton(id_)->setPopup(popupMenu(), stickyMenu()); - } - - if ( !whatsThis().isEmpty() ) - TQWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() ); - - return containerCount() - 1; - } - - return TDEAction::plug( widget, index ); -} - -TDEPopupMenu *TDEToolBarPopupAction::popupMenu() const -{ - if ( !m_popup ) { - TDEToolBarPopupAction *that = const_cast(this); - that->m_popup = new TDEPopupMenu; - } - return m_popup; -} - -//////// - -TDEToggleToolBarAction::TDEToggleToolBarAction( const char* toolBarName, - const TQString& text, TDEActionCollection* parent, const char* name ) - : TDEToggleAction( text, TDEShortcut(), parent, name ) - , m_toolBarName( toolBarName ) - , m_toolBar( 0L ) -{ -} - -TDEToggleToolBarAction::TDEToggleToolBarAction( TDEToolBar *toolBar, const TQString &text, - TDEActionCollection *parent, const char *name ) - : TDEToggleAction( text, TDEShortcut(), parent, name ) - , m_toolBarName( 0 ), m_toolBar( toolBar ) -{ -} - -TDEToggleToolBarAction::~TDEToggleToolBarAction() -{ -} - -int TDEToggleToolBarAction::plug( TQWidget* w, int index ) -{ - if (kapp && !kapp->authorizeTDEAction(name())) - return -1; - - if ( !m_toolBar ) { - // Note: topLevelWidget() stops too early, we can't use it. - TQWidget * tl = w; - TQWidget * n; - while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store - tl = n; - - TDEMainWindow * mw = tqt_dynamic_cast(tl); // try to see if it's a kmainwindow - - if ( mw ) - m_toolBar = mw->toolBar( m_toolBarName ); - } - - if( m_toolBar ) { - setChecked( m_toolBar->isVisible() ); - connect( m_toolBar, TQT_SIGNAL(visibilityChanged(bool)), this, TQT_SLOT(setChecked(bool)) ); - // Also emit toggled when the toolbar's visibility changes (see comment in header) - connect( m_toolBar, TQT_SIGNAL(visibilityChanged(bool)), this, TQT_SIGNAL(toggled(bool)) ); - } else { - setEnabled( false ); - } - - return TDEToggleAction::plug( w, index ); -} - -void TDEToggleToolBarAction::setChecked( bool c ) -{ - if( m_toolBar && c != m_toolBar->isVisible() ) { - if( c ) { - m_toolBar->show(); - } else { - m_toolBar->hide(); - } - TQMainWindow* mw = m_toolBar->mainWindow(); - if ( mw && ::tqqt_cast( mw ) ) - static_cast( mw )->setSettingsDirty(); - } - TDEToggleAction::setChecked( c ); -} - -//////// - -TDEToggleFullScreenAction::TDEToggleFullScreenAction( const TDEShortcut &cut, - const TQObject* receiver, const char* slot, - TQObject* parent, TQWidget* window, - const char* name ) - : TDEToggleAction( TQString::null, cut, receiver, slot, parent, name ), - window( NULL ) -{ - setWindow( window ); -} - -TDEToggleFullScreenAction::~TDEToggleFullScreenAction() -{ -} - -void TDEToggleFullScreenAction::setWindow( TQWidget* w ) -{ - if( window ) - window->removeEventFilter( this ); - window = w; - if( window ) - window->installEventFilter( this ); -} - -void TDEToggleFullScreenAction::setChecked( bool c ) -{ - if (c) - { - setText(i18n("Exit F&ull Screen Mode")); - setIcon("window_nofullscreen"); - } - else - { - setText(i18n("F&ull Screen Mode")); - setIcon("window_fullscreen"); - } - TDEToggleAction::setChecked( c ); -} - -bool TDEToggleFullScreenAction::eventFilter( TQObject* o, TQEvent* e ) -{ - if( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(window) ) - if( e->type() == TQEvent::WindowStateChange ) - { - if( window->isFullScreen() != isChecked()) - slotActivated(); // setChecked( window->isFullScreen()) wouldn't emit signals - } - return false; -} - -//////// - -KWidgetAction::KWidgetAction( TQWidget* widget, - const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TDEActionCollection* parent, const char* name ) - : TDEAction( text, cut, receiver, slot, parent, name ) - , m_widget( widget ) - , m_autoSized( false ) -{ - connect( this, TQT_SIGNAL(enabled(bool)), widget, TQT_SLOT(setEnabled(bool)) ); -} - -KWidgetAction::~KWidgetAction() -{ -} - -void KWidgetAction::setAutoSized( bool autoSized ) -{ - if( m_autoSized == autoSized ) - return; - - m_autoSized = autoSized; - - if( !m_widget || !isPlugged() ) - return; - - TDEToolBar* toolBar = (TDEToolBar*)m_widget->parent(); - int i = findContainer( toolBar ); - if ( i == -1 ) - return; - int id = itemId( i ); - - toolBar->setItemAutoSized( id, m_autoSized ); -} - -int KWidgetAction::plug( TQWidget* w, int index ) -{ - if (kapp && !kapp->authorizeTDEAction(name())) - return -1; - - if ( !::tqqt_cast( w ) ) { - kdError() << "KWidgetAction::plug: KWidgetAction must be plugged into TDEToolBar." << endl; - return -1; - } - if ( !m_widget ) { - kdError() << "KWidgetAction::plug: Widget was deleted or null!" << endl; - return -1; - } - - TDEToolBar* toolBar = static_cast( w ); - - int id = TDEAction::getToolButtonID(); - - m_widget->reparent( toolBar, TQPoint() ); - toolBar->insertWidget( id, 0, m_widget, index ); - toolBar->setItemAutoSized( id, m_autoSized ); - - TQWhatsThis::add( m_widget, whatsThis() ); - addContainer( toolBar, id ); - - connect( toolBar, TQT_SIGNAL( toolbarDestroyed() ), this, TQT_SLOT( slotToolbarDestroyed() ) ); - connect( toolBar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - return containerCount() - 1; -} - -void KWidgetAction::unplug( TQWidget *w ) -{ - if( !m_widget || !isPlugged() ) - return; - - TDEToolBar* toolBar = (TDEToolBar*)m_widget->parent(); - if ( toolBar == w ) - { - disconnect( toolBar, TQT_SIGNAL( toolbarDestroyed() ), this, TQT_SLOT( slotToolbarDestroyed() ) ); - m_widget->reparent( 0L, TQPoint(), false /*showIt*/ ); - } - TDEAction::unplug( w ); -} - -void KWidgetAction::slotToolbarDestroyed() -{ - //Q_ASSERT( m_widget ); // When exiting the app the widget could be destroyed before the toolbar. - Q_ASSERT( isPlugged() ); - if( !m_widget || !isPlugged() ) - return; - - // Don't let a toolbar being destroyed, delete my widget. - m_widget->reparent( 0L, TQPoint(), false /*showIt*/ ); -} - -//////// - -TDEActionSeparator::TDEActionSeparator( TQObject *parent, const char *name ) - : TDEAction( parent, name ) -{ -} - -TDEActionSeparator::~TDEActionSeparator() -{ -} - -int TDEActionSeparator::plug( TQWidget *widget, int index ) -{ - if ( ::tqqt_cast( widget) ) - { - TQPopupMenu* menu = static_cast( widget ); - - int id = menu->insertSeparator( index ); - - addContainer( menu, id ); - connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - return containerCount() - 1; - } - else if ( ::tqqt_cast( widget ) ) - { - TQMenuBar *menuBar = static_cast( widget ); - - int id = menuBar->insertSeparator( index ); - - addContainer( menuBar, id ); - - connect( menuBar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - return containerCount() - 1; - } - else if ( ::tqqt_cast( widget ) ) - { - TDEToolBar *toolBar = static_cast( widget ); - - int id = toolBar->insertSeparator( index ); - - addContainer( toolBar, id ); - - connect( toolBar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - return containerCount() - 1; - } - - return -1; -} - -TDEPasteTextAction::TDEPasteTextAction( const TQString& text, - const TQString& icon, - const TDEShortcut& cut, - const TQObject* receiver, - const char* slot, TQObject* parent, - const char* name) - : TDEAction( text, icon, cut, receiver, slot, parent, name ) -{ - m_popup = new TDEPopupMenu; - connect(m_popup, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(menuAboutToShow())); - connect(m_popup, TQT_SIGNAL(activated(int)), this, TQT_SLOT(menuItemActivated(int))); - m_popup->setCheckable(true); - m_mixedMode = true; -} - -TDEPasteTextAction::~TDEPasteTextAction() -{ - delete m_popup; -} - -void TDEPasteTextAction::setMixedMode(bool mode) -{ - m_mixedMode = mode; -} - -int TDEPasteTextAction::plug( TQWidget *widget, int index ) -{ - if (kapp && !kapp->authorizeTDEAction(name())) - return -1; - if ( ::tqqt_cast( widget ) ) - { - TDEToolBar *bar = (TDEToolBar *)widget; - - int id_ = TDEAction::getToolButtonID(); - - TDEInstance * instance; - if ( m_parentCollection ) - instance = m_parentCollection->instance(); - else - instance = TDEGlobal::instance(); - - bar->insertButton( icon(), id_, TQT_SIGNAL( clicked() ), this, - TQT_SLOT( slotActivated() ), isEnabled(), plainText(), - index, instance ); - - addContainer( bar, id_ ); - - connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - bar->setDelayedPopup( id_, m_popup, true ); - - if ( !whatsThis().isEmpty() ) - TQWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() ); - - return containerCount() - 1; - } - - return TDEAction::plug( widget, index ); -} - -void TDEPasteTextAction::menuAboutToShow() -{ - m_popup->clear(); - TQStringList list; - DCOPClient *client = kapp->dcopClient(); - if (client->isAttached() && client->isApplicationRegistered("klipper")) { - DCOPRef klipper("klipper","klipper"); - DCOPReply reply = klipper.call("getClipboardHistoryMenu"); - if (reply.isValid()) - list = reply; - } - TQString clipboardText = tqApp->clipboard()->text(TQClipboard::Clipboard); - if (list.isEmpty()) - list << clipboardText; - bool found = false; - for ( TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) - { - TQString text = KStringHandler::cEmSqueeze((*it).simplifyWhiteSpace(), m_popup->fontMetrics(), 20); - text.replace("&", "&&"); - int id = m_popup->insertItem(text); - if (!found && *it == clipboardText) - { - m_popup->setItemChecked(id, true); - found = true; - } - } -} - -void TDEPasteTextAction::menuItemActivated( int id) -{ - DCOPClient *client = kapp->dcopClient(); - if (client->isAttached() && client->isApplicationRegistered("klipper")) { - DCOPRef klipper("klipper","klipper"); - DCOPReply reply = klipper.call("getClipboardHistoryItem(int)", m_popup->indexOf(id)); - if (!reply.isValid()) - return; - TQString clipboardText = reply; - reply = klipper.call("setClipboardContents(TQString)", clipboardText); - if (reply.isValid()) - kdDebug(129) << "Clipboard: " << TQString(tqApp->clipboard()->text(TQClipboard::Clipboard)) << endl; - } - TQTimer::singleShot(20, this, TQT_SLOT(slotActivated())); -} - -void TDEPasteTextAction::slotActivated() -{ - if (!m_mixedMode) { - TQWidget *w = tqApp->widgetAt(TQCursor::pos(), true); - TQMimeSource *data = TQApplication::clipboard()->data(); - if (!data->provides("text/plain") && w) { - m_popup->popup(w->mapToGlobal(TQPoint(0, w->height()))); - } else - TDEAction::slotActivated(); - } else - TDEAction::slotActivated(); -} - - -void TDEToggleAction::virtual_hook( int id, void* data ) -{ TDEAction::virtual_hook( id, data ); } - -void TDERadioAction::virtual_hook( int id, void* data ) -{ TDEToggleAction::virtual_hook( id, data ); } - -void TDESelectAction::virtual_hook( int id, void* data ) -{ TDEAction::virtual_hook( id, data ); } - -void TDEListAction::virtual_hook( int id, void* data ) -{ TDESelectAction::virtual_hook( id, data ); } - -void TDERecentFilesAction::virtual_hook( int id, void* data ) -{ TDEListAction::virtual_hook( id, data ); } - -void TDEFontAction::virtual_hook( int id, void* data ) -{ TDESelectAction::virtual_hook( id, data ); } - -void TDEFontSizeAction::virtual_hook( int id, void* data ) -{ TDESelectAction::virtual_hook( id, data ); } - -void TDEActionMenu::virtual_hook( int id, void* data ) -{ TDEAction::virtual_hook( id, data ); } - -void TDEToolBarPopupAction::virtual_hook( int id, void* data ) -{ TDEAction::virtual_hook( id, data ); } - -void TDEToggleToolBarAction::virtual_hook( int id, void* data ) -{ TDEToggleAction::virtual_hook( id, data ); } - -void TDEToggleFullScreenAction::virtual_hook( int id, void* data ) -{ TDEToggleAction::virtual_hook( id, data ); } - -void KWidgetAction::virtual_hook( int id, void* data ) -{ TDEAction::virtual_hook( id, data ); } - -void TDEActionSeparator::virtual_hook( int id, void* data ) -{ TDEAction::virtual_hook( id, data ); } - -void TDEPasteTextAction::virtual_hook( int id, void* data ) -{ TDEAction::virtual_hook( id, data ); } - -/* vim: et sw=2 ts=2 - */ - -#include "kactionclasses.moc" diff --git a/tdeui/kactionclasses.h b/tdeui/kactionclasses.h deleted file mode 100644 index 07078a722..000000000 --- a/tdeui/kactionclasses.h +++ /dev/null @@ -1,1436 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999 Reginald Stadlbauer - (C) 1999 Simon Hausmann - (C) 2000 Nicolas Hadacek - (C) 2000 Kurt Granroth - (C) 2000 Michael Koch - (C) 2001 Holger Freyther - (C) 2002 Ellis Whitehead - (C) 2003 Andras Mantia - - 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. -*/ -//$Id$ - -#ifndef __kactionclasses_h__ -#define __kactionclasses_h__ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -class TQMenuBar; -class TQPopupMenu; -class TQComboBox; -class TQPoint; -class TQIconSet; -class TQString; -class TDEToolBar; - -class TDEAccel; -class TDEAccelActions; -class TDEConfig; -class TDEConfigBase; -class KURL; -class TDEInstance; -class TDEToolBar; -class TDEActionCollection; -class TDEPopupMenu; -class TDEMainWindow; - -/** - * @short Checkbox like action. - * - * Checkbox like action. - * - * This action provides two states: checked or not. - * - */ -class TDEUI_EXPORT TDEToggleAction : public TDEAction -{ - Q_OBJECT - - TQ_PROPERTY( bool checked READ isChecked WRITE setChecked ) - TQ_PROPERTY( TQString exclusiveGroup READ exclusiveGroup WRITE setExclusiveGroup ) -public: - - /** - * Constructs a toggle action with text and potential keyboard - * accelerator but nothing else. Use this only if you really - * know what you are doing. - * - * @param text The text that will be displayed. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToggleAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToggleAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The icons that go with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToggleAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The dynamically loaded icon that goes with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToggleAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The icons that go with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToggleAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The dynamically loaded icon that goes with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToggleAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name = 0 ); - - /** - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToggleAction( TQObject* parent = 0, const char* name = 0 ); - - /** - * Destructor - */ - virtual ~TDEToggleAction(); - - /** - * "Plug" or insert this action into a given widget. - * - * This will typically be a menu or a toolbar. From this point - * on, you will never need to directly manipulate the item in the - * menu or toolbar. You do all enabling/disabling/manipulation - * directly with your TDEToggleAction object. - * - * @param widget The GUI element to display this action. - * @param index The index of the item. - */ - virtual int plug( TQWidget* widget, int index = -1 ); - - /** - * Returns the actual state of the action. - */ - bool isChecked() const; - - /** - * @return which "exclusive group" this action is part of. - * @see setExclusiveGroup - */ - TQString exclusiveGroup() const; - - /** - * Defines which "exclusive group" this action is part of. - * In a given exclusive group, only one toggle action can be checked - * at a any moment. Checking an action unchecks the other actions - * of the group. - */ - virtual void setExclusiveGroup( const TQString& name ); - - /** - * Defines the text (and icon, tooltip, whatsthis) that should be displayed - * instead of the normal text, when the action is checked. - * This feature replaces the checkmark that usually appears in front of the text, in menus. - * It is useful when the text is mainly a verb: e.g. "Show " - * should turn into "Hide " when activated. - * - * If hasIcon(), the icon is kept for the 'checked state', unless - * @p checkedItem defines an icon explicitely. Same thing for tooltip and whatsthis. - * @since 3.3 - */ - void setCheckedState( const KGuiItem& checkedItem ); - - /// Reimplemented for internal reasons - virtual TQString toolTip() const; - -public slots: - /** - * Sets the state of the action. - */ - virtual void setChecked( bool ); - -protected slots: - virtual void slotActivated(); - -protected: - virtual void updateChecked( int id ); - -signals: - void toggled( bool ); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEToggleActionPrivate; - TDEToggleActionPrivate *d; -}; - -/** - * @short Radiobox like action. - * - * An action that operates like a radio button. At any given time - * only a single action from the group will be active. - */ -class TDEUI_EXPORT TDERadioAction : public TDEToggleAction -{ - Q_OBJECT - -public: - /** - * Constructs a radio action with text and potential keyboard - * accelerator but nothing else. Use this only if you really - * know what you are doing. - * - * @param text The text that will be displayed. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDERadioAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDERadioAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The icons that go with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDERadioAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The dynamically loaded icon that goes with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDERadioAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The icons that go with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDERadioAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The dynamically loaded icon that goes with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDERadioAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name = 0 ); - - /** - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDERadioAction( TQObject* parent = 0, const char* name = 0 ); - -protected: - virtual void slotActivated(); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDERadioActionPrivate; - TDERadioActionPrivate *d; -}; - -/** - * @short Action for selecting one of several items - * - * Action for selecting one of several items. - * - * This action shows up a submenu with a list of items. - * One of them can be checked. If the user clicks on an item - * this item will automatically be checked, - * the formerly checked item becomes unchecked. - * There can be only one item checked at a time. - */ -class TDEUI_EXPORT TDESelectAction : public TDEAction -{ - Q_OBJECT - - TQ_PROPERTY( int currentItem READ currentItem WRITE setCurrentItem ) - TQ_PROPERTY( TQStringList items READ items WRITE setItems ) - TQ_PROPERTY( bool editable READ isEditable WRITE setEditable ) - TQ_PROPERTY( int comboWidth READ comboWidth WRITE setComboWidth ) - TQ_PROPERTY( TQString currentText READ currentText ) - TQ_PROPERTY( bool menuAccelsEnabled READ menuAccelsEnabled WRITE setMenuAccelsEnabled ) -public: - - /** - * Constructs a select action with text and potential keyboard - * accelerator but nothing else. Use this only if you really - * know what you are doing. - * - * @param text The text that will be displayed. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDESelectAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDESelectAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The icons that go with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDESelectAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The dynamically loaded icon that goes with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDESelectAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The icons that go with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDESelectAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The dynamically loaded icon that goes with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDESelectAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name = 0 ); - - /** - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDESelectAction( TQObject* parent = 0, const char* name = 0 ); - - /** - * Destructor - */ - virtual ~TDESelectAction(); - - /** - * "Plug" or insert this action into a given widget. - * - * This will typically be a menu or a toolbar. - * From this point on, you will never need to directly - * manipulate the item in the menu or toolbar. - * You do all enabling/disabling/manipulation directly with your TDESelectAction object. - * - * @param widget The GUI element to display this action. - * @param index The index of the item. - */ - virtual int plug( TQWidget* widget, int index = -1 ); - - /** - * When this action is plugged into a toolbar, it creates a combobox. - * @return true if the combo editable. - */ - virtual bool isEditable() const; - - /** - * @return the items that can be selected with this action. - * Use setItems to set them. - */ - virtual TQStringList items() const; - - /** - * Changes the text of item @param index to @param text . - */ - virtual void changeItem( int index, const TQString& text ); - - /** - * Returns the text of the currently selected item. - */ - virtual TQString currentText() const; - - /** - * Returns the index of the current item. - * @see setCurrentItem - */ - virtual int currentItem() const; - - /** - * When this action is plugged into a toolbar, it creates a combobox. - * This returns the maximum width set by setComboWidth - */ - virtual int comboWidth() const; - - /** - * Sets the maximum items that are visible at once if the action - * is a combobox, that is the number of items in the combobox's viewport - * Only works before the action is plugged - * @since 3.5 - */ - void setMaxComboViewCount( int n ); - - /** - * Returns a pointer to the popup menu used by this action. - */ - TQPopupMenu* popupMenu() const; - - /** - * @deprecated See setMenuAccelsEnabled . - * @since 3.1 - */ - void setRemoveAmpersandsInCombo( bool b ) KDE_DEPRECATED; - /// @since 3.1 - bool removeAmpersandsInCombo() const; - - /** - * Sets whether any occurrence of the ampersand character ( & ) in items - * should be interpreted as keyboard accelerator for items displayed in a - * menu or not. - * @since 3.1 - */ - void setMenuAccelsEnabled( bool b ); - /// @since 3.1 - bool menuAccelsEnabled() const; - - virtual bool isShortcutConfigurable() const { return false; } - -public slots: - /** - * Sets the currently checked item. - * - * @param index Index of the item (remember the first item is zero). - */ - virtual void setCurrentItem( int index ); - - /** - * Sets the items to be displayed in this action - * You need to call this. - */ - virtual void setItems( const TQStringList &lst ); - - /** - * Clears up all the items in this action - */ - virtual void clear(); - - /** - * When this action is plugged into a toolbar, it creates a combobox. - * This makes the combo editable or read-only. - */ - virtual void setEditable( bool ); - - /** - * When this action is plugged into a toolbar, it creates a combobox. - * This gives a _maximum_ size to the combobox. - * The minimum size is automatically given by the contents (the items). - */ - virtual void setComboWidth( int width ); - -protected: - virtual void changeItem( int id, int index, const TQString& text ); - - /** - * Depending on the menuAccelsEnabled property this method will return the - * actions items in a way for inclusion in a combobox with the ampersand - * character removed from all items or not. - * @since 3.1 - */ - TQStringList comboItems() const; - -protected slots: - virtual void slotActivated( int id ); - virtual void slotActivated( const TQString &text ); - virtual void slotActivated(); - -signals: - /** - * This signal is emitted when an item is selected; @param index indicated - * the item selected. - */ - void activated( int index ); - /** - * This signal is emitted when an item is selected; @param text indicates - * the item selected. - */ - void activated( const TQString& text ); - -protected: - virtual void updateCurrentItem( int id ); - - virtual void updateComboWidth( int id ); - - virtual void updateItems( int id ); - - virtual void updateClear( int id ); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - void setupMenu() const; - class TDESelectActionPrivate; - TDESelectActionPrivate *d; - -}; - -/// Remove this class in KDE-4.0. It doesn't add _anything_ to TDESelectAction -/** - * @deprecated Use TDESelectAction instead. - */ -class TDEUI_EXPORT_DEPRECATED TDEListAction : public TDESelectAction -{ - Q_OBJECT - -public: - /** - * Constructs a list action with text and potential keyboard - * accelerator but nothing else. Use this only if you really - * know what you are doing. - * - * @param text The text that will be displayed. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEListAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, - const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEListAction( const TQString& text, const TDEShortcut& cut, const TQObject* receiver, - const char* slot, TQObject* parent, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The icons that go with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEListAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The dynamically loaded icon that goes with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEListAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The icons that go with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEListAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, - const char* name = 0 ); - - /** - * @param text The text that will be displayed. - * @param pix The dynamically loaded icon that goes with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEListAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, - const char* name = 0 ); - - /** - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEListAction( TQObject* parent = 0, const char* name = 0 ); - - /** - * Destructor - */ - virtual ~TDEListAction(); - - - virtual TQString currentText() const; - virtual int currentItem() const; - - -public slots: - /** - * Sets the currently checked item. - * - * @param index Index of the item (remember the first item is zero). - */ - virtual void setCurrentItem( int index ); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEListActionPrivate; - TDEListActionPrivate *d; -}; - -/** - * @short Recent files action - * - * This class is an action to handle a recent files submenu. - * The best way to create the action is to use KStdAction::openRecent. - * Then you simply need to call loadEntries on startup, saveEntries - * on shutdown, addURL when your application loads/saves a file. - * - * @author Michael Koch - */ -class TDEUI_EXPORT TDERecentFilesAction : public TDEListAction // TODO public TDESelectAction -{ - Q_OBJECT - - TQ_PROPERTY( uint maxItems READ maxItems WRITE setMaxItems ) -public: - /** - * @param text The text that will be displayed. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - * @param maxItems The maximum number of files to display - */ - TDERecentFilesAction( const TQString& text, const TDEShortcut& cut, - TQObject* parent, const char* name = 0, - uint maxItems = 10 ); - - /** - * @param text The text that will be displayed. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke when a URL is selected. - * Its signature is of the form slotURLSelected( const KURL & ). - * @param parent This action's parent. - * @param name An internal name for this action. - * @param maxItems The maximum number of files to display - */ - TDERecentFilesAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name = 0, - uint maxItems = 10 ); - - /** - * @param text The text that will be displayed. - * @param pix The icons that go with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - * @param maxItems The maximum number of files to display - */ - TDERecentFilesAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, - TQObject* parent, const char* name = 0, - uint maxItems = 10 ); - - /** - * @param text The text that will be displayed. - * @param pix The dynamically loaded icon that goes with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - * @param maxItems The maximum number of files to display - */ - TDERecentFilesAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, - TQObject* parent, const char* name = 0, - uint maxItems = 10 ); - - /** - * @param text The text that will be displayed. - * @param pix The icons that go with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke when a URL is selected. - * Its signature is of the form slotURLSelected( const KURL & ). - * @param parent This action's parent. - * @param name An internal name for this action. - * @param maxItems The maximum number of files to display - */ - TDERecentFilesAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name = 0, - uint maxItems = 10 ); - - /** - * @param text The text that will be displayed. - * @param pix The dynamically loaded icon that goes with this action. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke when a URL is selected. - * Its signature is of the form slotURLSelected( const KURL & ). - * @param parent This action's parent. - * @param name An internal name for this action. - * @param maxItems The maximum number of files to display - */ - TDERecentFilesAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name = 0, - uint maxItems = 10 ); - - /** - * @param parent This action's parent. - * @param name An internal name for this action. - * @param maxItems The maximum number of files to display - */ - TDERecentFilesAction( TQObject* parent = 0, const char* name = 0, - uint maxItems = 10 ); - - /** - * Destructor. - */ - virtual ~TDERecentFilesAction(); - - virtual int plug( TQWidget *widget, int index = -1 ); - - /** - * Returns the maximum of items in the recent files list. - */ - uint maxItems() const; - -//KDE4: remove completeItems() and rename items() to urls(), to get the list of URLs added to -// the action. - /** - * @return the items that can be selected with this action. - * The returned items do not contain the pretty name that can be set by addURL, - * matching the pre-3.5 behavior. - */ - - virtual TQStringList items() const; - - /** - * @return the items that can be selected with this action. - * The returned items contain the pretty name that can be set by addURL. - * @since 3.5 - */ - TQStringList completeItems() const; - -public slots: - /** - * Sets the maximum of items in the recent files list. - * The default for this value is 10 set in the constructor. - * - * If this value is lesser than the number of items currently - * in the recent files list the last items are deleted until - * the number of items are equal to the new maximum. - */ - void setMaxItems( uint maxItems ); - - /** - * Loads the recent files entries from a given TDEConfig object. - * You can provide the name of the group used to load the entries. - * If the groupname is empty, entries are load from a group called 'RecentFiles' - * - * This method does not effect the active group of TDEConfig. - */ - void loadEntries( TDEConfig* config, TQString groupname=TQString::null ); - - /** - * Saves the current recent files entries to a given TDEConfig object. - * You can provide the name of the group used to load the entries. - * If the groupname is empty, entries are saved to a group called 'RecentFiles' - * - * This method does not effect the active group of TDEConfig. - */ - void saveEntries( TDEConfig* config, TQString groupname=TQString::null ); - - /** - * Add URL to recent files list. - * - * @param url The URL of the file - */ - void addURL( const KURL& url ); - - /** - * Add URL to recent files list. - * - * @param url The URL of the file - * @param name The user visible pretty name that appears before the URL - * @since 3.5 - */ - void addURL( const KURL& url, const TQString& name ); //KDE4: Combine the above two methods - - /** - * Remove an URL from the recent files list. - * - * @param url The URL of the file - */ - void removeURL( const KURL& url ); - - /** - * Removes all entries from the recent files list. - */ - void clearURLList(); - -signals: - - /** - * This signal gets emited when the user selects an URL. - * - * @param url The URL thats the user selected. - */ - void urlSelected( const KURL& url ); - -protected slots: - void itemSelected( const TQString& string ); - void menuAboutToShow(); - void menuItemActivated( int id ); - void slotClicked(); - virtual void slotActivated(int); - virtual void slotActivated(const TQString& ); - virtual void slotActivated(); - -protected: - virtual void virtual_hook( int id, void* data ); - -private: - void init(); - - class TDERecentFilesActionPrivate; - TDERecentFilesActionPrivate *d; -}; - -class TDEUI_EXPORT TDEFontAction : public TDESelectAction -{ - Q_OBJECT - - TQ_PROPERTY( TQString font READ font WRITE setFont ) -public: - TDEFontAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, - const char* name = 0 ); - TDEFontAction( const TQString& text, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, - const char* name = 0 ); - TDEFontAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - TDEFontAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - TDEFontAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, - const char* name = 0 ); - TDEFontAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, TQObject* parent, - const char* name = 0 ); - -// The ctors with fontListCriteria were added after 3.3-beta1. -// This define is used in koffice. Remove when koffice has a dependency on tdelibs-3.3 or more. -#define KFONTACTION_HAS_CRITERIA_ARG - TDEFontAction( uint fontListCriteria, const TQString& text, - const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, - const char* name = 0 ); - TDEFontAction( uint fontListCriteria, const TQString& text, const TQString& pix, - const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - - TDEFontAction( TQObject* parent = 0, const char* name = 0 ); - ~TDEFontAction(); - - TQString font() const { - return currentText(); - } - - int plug( TQWidget*widget, int index = -1 ); - -public slots: - void setFont( const TQString &family ); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEFontActionPrivate; - TDEFontActionPrivate *d; -}; - -class TDEUI_EXPORT TDEFontSizeAction : public TDESelectAction -{ - Q_OBJECT - - TQ_PROPERTY( int fontSize READ fontSize WRITE setFontSize ) -public: - TDEFontSizeAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, - const char* name = 0 ); - TDEFontSizeAction( const TQString& text, const TDEShortcut& cut, const TQObject* receiver, - const char* slot, TQObject* parent, const char* name = 0 ); - TDEFontSizeAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - TDEFontSizeAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - TDEFontSizeAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name = 0 ); - TDEFontSizeAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent, const char* name = 0 ); - TDEFontSizeAction( TQObject* parent = 0, const char* name = 0 ); - - virtual ~TDEFontSizeAction(); - - virtual int fontSize() const; - -public slots: - virtual void setFontSize( int size ); - -protected slots: - virtual void slotActivated( int ); - virtual void slotActivated( const TQString& ); - virtual void slotActivated() { TDEAction::slotActivated(); } - -signals: - void fontSizeChanged( int ); - -private: - void init(); - - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEFontSizeActionPrivate; - TDEFontSizeActionPrivate *d; -}; - - -/** - * A TDEActionMenu is an action that holds a sub-menu of other actions. - * insert() and remove() allow to insert and remove actions into this action-menu. - * Plugged in a popupmenu, it will create a submenu. - * Plugged in a toolbar, it will create a button with a popup menu. - * - * This is the action used by the XMLGUI since it holds other actions. - * If you want a submenu for selecting one tool among many (without icons), see TDESelectAction. - * See also setDelayed about the main action. - */ -class TDEUI_EXPORT TDEActionMenu : public TDEAction -{ - Q_OBJECT - - TQ_PROPERTY( bool delayed READ delayed WRITE setDelayed ) - TQ_PROPERTY( bool stickyMenu READ stickyMenu WRITE setStickyMenu ) - -public: - TDEActionMenu( const TQString& text, TQObject* parent = 0, - const char* name = 0 ); - TDEActionMenu( const TQString& text, const TQIconSet& icon, - TQObject* parent = 0, const char* name = 0 ); - TDEActionMenu( const TQString& text, const TQString& icon, - TQObject* parent = 0, const char* name = 0 ); - TDEActionMenu( TQObject* parent = 0, const char* name = 0 ); - virtual ~TDEActionMenu(); - - virtual void insert( TDEAction*, int index = -1 ); - virtual void remove( TDEAction* ); - - TDEPopupMenu* popupMenu() const; - void popup( const TQPoint& global ); - - /** - * Returns true if this action creates a delayed popup menu - * when plugged in a TDEToolbar. - */ - bool delayed() const; - /** - * If set to true, this action will create a delayed popup menu - * when plugged in a TDEToolbar. Otherwise it creates a normal popup. - * Default: delayed - * - * Remember that if the "main" action (the toolbar button itself) - * cannot be clicked, then you should call setDelayed(false). - * - * On the opposite, if the main action can be clicked, it can only happen - * in a toolbar: in a menu, the parent of a submenu can't be activated. - * To get a "normal" menu item when plugged a menu (and no submenu) - * use TDEToolBarPopupAction. - */ - void setDelayed(bool _delayed); - - /** - * Returns true if this action creates a sticky popup menu. - * See setStickyMenu(). - */ - bool stickyMenu() const; - /** - * If set to true, this action will create a sticky popup menu - * when plugged in a TDEToolbar. - * "Sticky", means it's visible until a selection is made or the mouse is - * clicked elsewhere. This feature allows you to make a selection without - * having to press and hold down the mouse while making a selection. - * Default: sticky. - */ - void setStickyMenu(bool sticky); - - virtual int plug( TQWidget* widget, int index = -1 ); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEActionMenuPrivate; - TDEActionMenuPrivate *d; -}; - -/** - * This action is a normal action everywhere, except in a toolbar - * where it also has a popupmenu (optionnally delayed). This action is designed - * for history actions (back/forward, undo/redo) and for any other action - * that has more detail in a toolbar than in a menu (e.g. tool chooser - * with "Other" leading to a dialog...). - */ -class TDEUI_EXPORT TDEToolBarPopupAction : public TDEAction -{ - Q_OBJECT - - TQ_PROPERTY( bool delayed READ delayed WRITE setDelayed ) - TQ_PROPERTY( bool stickyMenu READ stickyMenu WRITE setStickyMenu ) - -public: - //Not all constructors - because we need an icon, since this action only makes - // sense when being plugged at least in a toolbar. - /** - * Create a TDEToolBarPopupAction, with a text, an icon, an optional accelerator, - * parent and name. - * - * @param text The text that will be displayed. - * @param icon The icon to display. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToolBarPopupAction( const TQString& text, const TQString& icon, const TDEShortcut& cut = TDEShortcut(), - TQObject* parent = 0, const char* name = 0 ); - - /** - * Create a TDEToolBarPopupAction, with a text, an icon, an accelerator, - * a slot connected to the action, parent and name. - * - * If you do not want or have a keyboard accelerator, set the - * @p cut param to 0. - * - * @param text The text that will be displayed. - * @param icon The icon to display. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's owner. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToolBarPopupAction( const TQString& text, const TQString& icon, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent = 0, const char* name = 0 ); - - /** - * Create a TDEToolBarPopupAction, with a KGuiItem, an accelerator, - * a slot connected to the action, parent and name. The text and the - * icon are taken from the KGuiItem. - * - * If you do not want or have a keyboard accelerator, set the - * @p cut param to 0. - * - * @param item The text and icon that will be displayed. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's owner. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToolBarPopupAction( const KGuiItem& item, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TDEActionCollection* parent, const char* name ); - - virtual ~TDEToolBarPopupAction(); - - virtual int plug( TQWidget *widget, int index = -1 ); - - /** - * The popup menu that is shown when clicking (some time) on the toolbar - * button. You may want to plug items into it on creation, or connect to - * aboutToShow for a more dynamic menu. - */ - TDEPopupMenu *popupMenu() const; - - /** - * Returns true if this action creates a delayed popup menu - * when plugged in a TDEToolbar. - */ - bool delayed() const; - /** - * If set to true, this action will create a delayed popup menu - * when plugged in a TDEToolbar. Otherwise it creates a normal popup. - * Default: delayed. - */ - void setDelayed(bool delayed); - /** - * Returns true if this action creates a sticky popup menu. - * See setStickyMenu(). - */ - bool stickyMenu() const; - /** - * If set to true, this action will create a sticky popup menu - * when plugged in a TDEToolbar. - * "Sticky", means it's visible until a selection is made or the mouse is - * clicked elsewhere. This feature allows you to make a selection without - * having to press and hold down the mouse while making a selection. - * Only available if delayed() is true. - * Default: sticky. - */ - void setStickyMenu(bool sticky); - -private: - TDEPopupMenu *m_popup; - bool m_delayed:1; - bool m_stickyMenu:1; -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEToolBarPopupActionPrivate; - TDEToolBarPopupActionPrivate *d; -}; - -/** - * An action that takes care of everything associated with - * showing or hiding a toolbar by a menu action. It will - * show or hide the toolbar with the given name when - * activated, and check or uncheck itself if the toolbar - * is manually shown or hidden. - * - * If you need to perfom some additional action when the - * toolbar is shown or hidden, connect to the toggled(bool) - * signal. It will be emitted after the toolbar's - * visibility has changed, whenever it changes. - * @since 3.1 - */ -class TDEUI_EXPORT TDEToggleToolBarAction : public TDEToggleAction -{ - Q_OBJECT - -public: - /** - * Create a TDEToggleToolbarAction that manages the toolbar - * named toolBarName. This can be either the name of a - * toolbar in an xml ui file, or a toolbar programmatically - * created with that name. - */ - TDEToggleToolBarAction( const char* toolBarName, const TQString& text, - TDEActionCollection* parent, const char* name ); - TDEToggleToolBarAction( TDEToolBar *toolBar, const TQString &text, - TDEActionCollection *parent, const char *name ); - virtual ~TDEToggleToolBarAction(); - - virtual int plug( TQWidget * widget, int index = -1 ); - - TDEToolBar *toolBar() { return m_toolBar; } - -public slots: - virtual void setChecked( bool ); - -private: - TQCString m_toolBarName; - TQGuardedPtr m_toolBar; -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEToggleToolBarActionPrivate; - TDEToggleToolBarActionPrivate *d; -}; - -/** - * An action for switching between to/from full screen mode. Note that - * TQWidget::isFullScreen() may reflect the new or the old state - * depending on how the action was triggered (by the application or - * from the window manager). Also don't try to track the window state - * yourself. Rely on this action's state (isChecked()) instead. - * - * Important: If you need to set/change the fullscreen state manually, - * use the relevant TQWidget function (showFullScreen etc.), do not - * call directly the slot connected to the toggled() signal. The slot - * still needs to explicitly set the window state though. - * @since 3.2 - */ -class TDEUI_EXPORT TDEToggleFullScreenAction : public TDEToggleAction -{ - Q_OBJECT - -public: - /** - * Create a TDEToggleFullScreenAction - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param window the window that will switch to/from full screen mode - * @param name An internal name for this action. - */ - TDEToggleFullScreenAction( const TDEShortcut &cut, - const TQObject* receiver, const char* slot, - TQObject* parent, TQWidget* window, - const char* name ); - virtual ~TDEToggleFullScreenAction(); - - /** - * Sets the window that will be related to this action. - */ - void setWindow( TQWidget* window ); -public slots: - virtual void setChecked( bool ); -protected: - /** - * @internal - */ - virtual bool eventFilter( TQObject* o, TQEvent* e ); -private: - TQWidget* window; -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEToggleFullScreenActionPrivate; - TDEToggleFullScreenActionPrivate *d; -}; - - -/** - * An action that automatically embeds a widget into a - * toolbar. - */ -class TDEUI_EXPORT KWidgetAction : public TDEAction -{ - Q_OBJECT - -public: - /** - * Create an action that will embed widget into a toolbar - * when plugged. This action may only be plugged into - * a toolbar. - */ - KWidgetAction( TQWidget* widget, const TQString& text, - const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TDEActionCollection* parent, const char* name ); - virtual ~KWidgetAction(); - - /** - * Returns the widget associated with this action. - */ - TQWidget* widget() { return m_widget; } - - void setAutoSized( bool ); - - /** - * Plug the action. The widget passed to the constructor - * will be reparented to w, which must inherit TDEToolBar. - */ - virtual int plug( TQWidget* widget, int index = -1 ); - /** - * Unplug the action. Ensures that the action is not - * destroyed. It will be hidden and reparented to 0L instead. - */ - virtual void unplug( TQWidget *w ); -protected slots: - void slotToolbarDestroyed(); -private: - TQGuardedPtr m_widget; - bool m_autoSized; -protected: - virtual void virtual_hook( int id, void* data ); -private: - class KWidgetActionPrivate; - KWidgetActionPrivate *d; -}; - -class TDEUI_EXPORT TDEActionSeparator : public TDEAction -{ - Q_OBJECT - -public: - TDEActionSeparator( TQObject* parent = 0, const char* name = 0 ); - virtual ~TDEActionSeparator(); - - virtual int plug( TQWidget *widget, int index = -1 ); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEActionSeparatorPrivate; - TDEActionSeparatorPrivate *d; -}; - -/** - * An action for pasting text from the clipboard. - * It's useful for text handling applications as - * when plugged into a toolbar it provides a menu - * with the clipboard history if klipper is running. - * If klipper is not running, the menu has only one - * item: the current clipboard content. - * - * @since 3.2 - */ -class TDEUI_EXPORT TDEPasteTextAction: public TDEAction -{ - Q_OBJECT - -public: - /** - * Create a TDEPasteTextAction, with a text, an icon, an accelerator, - * a slot connected to the action, parent and name. - * - * If you do not want or have a keyboard accelerator, set the - * @p cut param to 0. - * - * @param text The text that will be displayed. - * @param icon The icon to display. - * @param cut The corresponding keyboard accelerator (shortcut). - * @param receiver The SLOT's owner. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEPasteTextAction( const TQString& text, const TQString& icon, const TDEShortcut& cut, - const TQObject* receiver, const char* slot, - TQObject* parent = 0, const char* name = 0 ); - - virtual ~TDEPasteTextAction(); - - /** - * Controls the behavior of the clipboard history menu popup. - * - * @param mode If false and the clipboard contains a non-text object - * the popup menu with the clipboard history will appear - * immediately as the user clicks the toolbar action; if - * true, the action works like the standard paste action - * even if the current clipboard object is not text. - * Default value is true. - */ - void setMixedMode(bool mode); - - virtual int plug( TQWidget *widget, int index = -1 ); - -protected slots: - void menuAboutToShow(); - void menuItemActivated( int id); - virtual void slotActivated(); - -protected: - virtual void virtual_hook( int id, void* data ); - -private: - TDEPopupMenu *m_popup; - bool m_mixedMode; - class TDEPasteTextActionPrivate; - TDEPasteTextActionPrivate *d; -}; - -#endif diff --git a/tdeui/kactioncollection.cpp b/tdeui/kactioncollection.cpp deleted file mode 100644 index 74f273994..000000000 --- a/tdeui/kactioncollection.cpp +++ /dev/null @@ -1,802 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999 Reginald Stadlbauer - (C) 1999 Simon Hausmann - (C) 2000 Nicolas Hadacek - (C) 2000 Kurt Granroth - (C) 2000 Michael Koch - (C) 2001 Holger Freyther - (C) 2002 Ellis Whitehead - (C) 2002 Joseph Wenninger - - 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. -*/ - -#include "kactioncollection.h" -#include "kactionshortcutlist.h" -#include "ktoolbar.h" -#include "kxmlguifactory.h" -#include "kxmlguiclient.h" - -#include -#include -#include -#include - -#include -#include -#include - -class TDEActionCollection::TDEActionCollectionPrivate -{ -public: - TDEActionCollectionPrivate() - { - m_instance = 0; - //m_bOneTDEAccelOnly = false; - //m_iWidgetCurrent = 0; - m_bAutoConnectShortcuts = true; - m_widget = 0; - m_kaccel = m_builderTDEAccel = 0; - m_dctHighlightContainers.setAutoDelete( true ); - m_highlight = false; - m_currentHighlightAction = 0; - m_statusCleared = true; - m_parentGUIClient = 0L; - } - - TDEInstance *m_instance; - TQString m_sXMLFile; - bool m_bAutoConnectShortcuts; - //bool m_bOneTDEAccelOnly; - //int m_iWidgetCurrent; - //TQValueList m_widgetList; - //TQValueList m_kaccelList; - TQValueList m_docList; - TQWidget *m_widget; - TDEAccel *m_kaccel; - TDEAccel *m_builderTDEAccel; - - TQAsciiDict m_actionDict; - TQPtrDict< TQPtrList > m_dctHighlightContainers; - bool m_highlight; - TDEAction *m_currentHighlightAction; - bool m_statusCleared; - const KXMLGUIClient *m_parentGUIClient; -}; - -TDEActionCollection::TDEActionCollection( TQWidget *parent, const char *name, - TDEInstance *instance ) - : TQObject( parent, name ) -{ - kdDebug(129) << "TDEActionCollection::TDEActionCollection( " << parent << ", " << name << " ): this = " << this << endl; // ellis - d = new TDEActionCollectionPrivate; - if( parent ) - setWidget( parent ); - //d->m_bOneTDEAccelOnly = (d->m_kaccelList.count() > 0); - setInstance( instance ); -} - - -TDEActionCollection::TDEActionCollection( TQWidget *watch, TQObject* parent, const char *name, - TDEInstance *instance ) - : TQObject( parent, name ) -{ - kdDebug(129) << "TDEActionCollection::TDEActionCollection( " << watch << ", " << parent << ", " << name << " ): this = " << this << endl; //ellis - d = new TDEActionCollectionPrivate; - if( watch ) - setWidget( watch ); - //d->m_bOneTDEAccelOnly = (d->m_kaccelList.count() > 0); - setInstance( instance ); -} - -#ifndef KDE_NO_COMPAT -// KDE 4: remove -TDEActionCollection::TDEActionCollection( TQObject *parent, const char *name, - TDEInstance *instance ) - : TQObject( parent, name ) -{ - kdWarning(129) << "TDEActionCollection::TDEActionCollection( TQObject *parent, const char *name, TDEInstance *instance )" << endl; //ellis - kdDebug(129) << kdBacktrace() << endl; - d = new TDEActionCollectionPrivate; - TQWidget* w = tqt_dynamic_cast( parent ); - if( w ) - setWidget( w ); - //d->m_bOneTDEAccelOnly = (d->m_kaccelList.count() > 0); - setInstance( instance ); -} - -TDEActionCollection::TDEActionCollection( const TDEActionCollection © ) - : TQObject() -{ - kdWarning(129) << "TDEActionCollection::TDEActionCollection( const TDEActionCollection & ): function is severely deprecated." << endl; - d = new TDEActionCollectionPrivate; - *this = copy; -} -#endif // KDE 4: remove end - -TDEActionCollection::TDEActionCollection( const char *name, const KXMLGUIClient *parent ) - : TQObject( 0L, name ) -{ - d = new TDEActionCollectionPrivate; - d->m_parentGUIClient=parent; - d->m_instance=parent->instance(); -} - - -TDEActionCollection::~TDEActionCollection() -{ - kdDebug(129) << "TDEActionCollection::~TDEActionCollection(): this = " << this << endl; - for ( TQAsciiDictIterator it( d->m_actionDict ); it.current(); ++it ) { - TDEAction* pAction = it.current(); - if ( pAction->m_parentCollection == this ) - pAction->m_parentCollection = 0L; - } - - delete d->m_kaccel; - delete d->m_builderTDEAccel; - delete d; d = 0; -} - -void TDEActionCollection::setWidget( TQWidget* w ) -{ - //if ( d->m_actionDict.count() > 0 ) { - // kdError(129) << "TDEActionCollection::setWidget(): must be called before any actions are added to collection!" << endl; - // kdDebug(129) << kdBacktrace() << endl; - //} - //else - if ( !d->m_widget ) { - d->m_widget = w; - d->m_kaccel = new TDEAccel( w, this, "TDEActionCollection-TDEAccel" ); - } - else if ( d->m_widget != w ) - kdWarning(129) << "TDEActionCollection::setWidget(): tried to change widget from " << d->m_widget << " to " << w << endl; -} - -void TDEActionCollection::setAutoConnectShortcuts( bool b ) -{ - d->m_bAutoConnectShortcuts = b; -} - -bool TDEActionCollection::isAutoConnectShortcuts() -{ - return d->m_bAutoConnectShortcuts; -} - -bool TDEActionCollection::addDocCollection( TDEActionCollection* pDoc ) -{ - d->m_docList.append( pDoc ); - return true; -} - -void TDEActionCollection::beginXMLPlug( TQWidget *widget ) -{ - kdDebug(129) << "TDEActionCollection::beginXMLPlug( buildWidget = " << widget << " ): this = " << this << " d->m_builderTDEAccel = " << d->m_builderTDEAccel << endl; - - if( widget && !d->m_builderTDEAccel ) { - d->m_builderTDEAccel = new TDEAccel( widget, this, "TDEActionCollection-BuilderTDEAccel" ); - } -} - -void TDEActionCollection::endXMLPlug() -{ - kdDebug(129) << "TDEActionCollection::endXMLPlug(): this = " << this << endl; - //s_kaccelXML = 0; -} - -void TDEActionCollection::prepareXMLUnplug() -{ - kdDebug(129) << "TDEActionCollection::prepareXMLUnplug(): this = " << this << endl; - unplugShortcuts( d->m_kaccel ); - - if( d->m_builderTDEAccel ) { - unplugShortcuts( d->m_builderTDEAccel ); - delete d->m_builderTDEAccel; - d->m_builderTDEAccel = 0; - } -} - -void TDEActionCollection::unplugShortcuts( TDEAccel* kaccel ) -{ - for ( TQAsciiDictIterator it( d->m_actionDict ); it.current(); ++it ) { - TDEAction* pAction = it.current(); - pAction->removeTDEAccel( kaccel ); - } - - for( uint i = 0; i < d->m_docList.count(); i++ ) - d->m_docList[i]->unplugShortcuts( kaccel ); -} - -/*void TDEActionCollection::addWidget( TQWidget* w ) -{ - if( !d->m_bOneTDEAccelOnly ) { - kdDebug(129) << "TDEActionCollection::addWidget( " << w << " ): this = " << this << endl; - for( uint i = 0; i < d->m_widgetList.count(); i++ ) { - if( d->m_widgetList[i] == w ) { - d->m_iWidgetCurrent = i; - return; - } - } - d->m_iWidgetCurrent = d->m_widgetList.count(); - d->m_widgetList.append( w ); - d->m_kaccelList.append( new TDEAccel( w, this, "TDEActionCollection-TDEAccel" ) ); - } -} - -void TDEActionCollection::removeWidget( TQWidget* w ) -{ - if( !d->m_bOneTDEAccelOnly ) { - kdDebug(129) << "TDEActionCollection::removeWidget( " << w << " ): this = " << this << endl; - for( uint i = 0; i < d->m_widgetList.count(); i++ ) { - if( d->m_widgetList[i] == w ) { - // Remove TDEAccel object from children. - TDEAccel* pTDEAccel = d->m_kaccelList[i]; - for ( TQAsciiDictIterator it( d->m_actionDict ); it.current(); ++it ) { - TDEAction* pAction = it.current(); - if ( pAction->m_parentCollection == this ) { - pAction->removeTDEAccel( pTDEAccel ); - } - } - delete pTDEAccel; - - d->m_widgetList.remove( d->m_widgetList.at( i ) ); - d->m_kaccelList.remove( d->m_kaccelList.at( i ) ); - - if( d->m_iWidgetCurrent == (int)i ) - d->m_iWidgetCurrent = -1; - else if( d->m_iWidgetCurrent > (int)i ) - d->m_iWidgetCurrent--; - return; - } - } - kdWarning(129) << "TDEActionCollection::removeWidget( " << w << " ): widget not in list." << endl; - } -} - -bool TDEActionCollection::ownsTDEAccel() const -{ - return d->m_bOneTDEAccelOnly; -} - -uint TDEActionCollection::widgetCount() const -{ - return d->m_widgetList.count(); -} - -const TDEAccel* TDEActionCollection::widgetTDEAccel( uint i ) const -{ - return d->m_kaccelList[i]; -}*/ - -TDEAccel* TDEActionCollection::kaccel() -{ - //if( d->m_kaccelList.count() > 0 ) - // return d->m_kaccelList[d->m_iWidgetCurrent]; - //else - // return 0; - return d->m_kaccel; -} - -const TDEAccel* TDEActionCollection::kaccel() const -{ - //if( d->m_kaccelList.count() > 0 ) - // return d->m_kaccelList[d->m_iWidgetCurrent]; - //else - // return 0; - return d->m_kaccel; -} - -// Return the key to use in d->m_actionDict for the given action. -// Usually name(), except when unnamed. -static const char* actionDictKey( TDEAction* action, char* buffer ) -{ - const char* name = action->name(); - if( !qstrcmp( name, "unnamed" ) ) - { - sprintf(buffer, "unnamed-%p", (void *)action); - return buffer; - } - return name; -} - -void TDEActionCollection::_insert( TDEAction* action ) -{ - char unnamed_name[100]; - const char *name = actionDictKey( action, unnamed_name ); - TDEAction *a = d->m_actionDict[ name ]; - if ( a == action ) - return; - - d->m_actionDict.insert( name, action ); - - emit inserted( action ); -} - -void TDEActionCollection::_remove( TDEAction* action ) -{ - char unnamed_name[100]; - const char *name = actionDictKey( action, unnamed_name ); - - TDEAction *a = d->m_actionDict.take( name ); - if ( !a || a != action ) - return; - - emit removed( action ); - // note that we delete the action without its parent collection set to 0. - // This triggers kaccel::remove, to remove any shortcut. - delete a; -} - -TDEAction* TDEActionCollection::_take( TDEAction* action ) -{ - char unnamed_name[100]; - const char *name = actionDictKey( action, unnamed_name ); - - TDEAction *a = d->m_actionDict.take( name ); - if ( !a || a != action ) - return 0; - - if ( a->m_parentCollection == this ) - a->m_parentCollection = 0; - - emit removed( action ); - - return a; -} - -void TDEActionCollection::_clear() -{ - TQAsciiDictIterator it( d->m_actionDict ); - while ( it.current() ) - _remove( it.current() ); -} - -void TDEActionCollection::insert( TDEAction* action ) { _insert( action ); } -void TDEActionCollection::remove( TDEAction* action ) { _remove( action ); } -TDEAction* TDEActionCollection::take( TDEAction* action ) { return _take( action ); } -void TDEActionCollection::clear() { _clear(); } -TDEAccel* TDEActionCollection::accel() { return kaccel(); } -const TDEAccel* TDEActionCollection::accel() const { return kaccel(); } -TDEAccel* TDEActionCollection::builderTDEAccel() const { return d->m_builderTDEAccel; } - -TDEAction* TDEActionCollection::action( const char* name, const char* classname ) const -{ - TDEAction* pAction = 0; - - if ( !classname && name ) - pAction = d->m_actionDict[ name ]; - - else { - TQAsciiDictIterator it( d->m_actionDict ); - for( ; it.current(); ++it ) - { - if ( ( !name || !strcmp( it.current()->name(), name ) ) && - ( !classname || !strcmp( it.current()->className(), classname ) ) ) { - pAction = it.current(); - break; - } - } - } - - if( !pAction ) { - for( uint i = 0; i < d->m_docList.count() && !pAction; i++ ) - pAction = d->m_docList[i]->action( name, classname ); - } - - return pAction; -} - -TDEAction* TDEActionCollection::action( int index ) const -{ - TQAsciiDictIterator it( d->m_actionDict ); - it += index; - return it.current(); -// return d->m_actions.at( index ); -} - -bool TDEActionCollection::readShortcutSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig ) -{ - return TDEActionShortcutList(this).readSettings( sConfigGroup, pConfig ); -} - -bool TDEActionCollection::writeShortcutSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig ) const -{ - return TDEActionShortcutList((TDEActionCollection*)this).writeSettings( sConfigGroup, pConfig ); -} - -uint TDEActionCollection::count() const -{ - return d->m_actionDict.count(); -} - -TQStringList TDEActionCollection::groups() const -{ - TQStringList lst; - - TQAsciiDictIterator it( d->m_actionDict ); - for( ; it.current(); ++it ) - if ( !it.current()->group().isEmpty() && !lst.contains( it.current()->group() ) ) - lst.append( it.current()->group() ); - - return lst; -} - -TDEActionPtrList TDEActionCollection::actions( const TQString& group ) const -{ - TDEActionPtrList lst; - - TQAsciiDictIterator it( d->m_actionDict ); - for( ; it.current(); ++it ) - if ( it.current()->group() == group ) - lst.append( it.current() ); - else if ( it.current()->group().isEmpty() && group.isEmpty() ) - lst.append( it.current() ); - - return lst; -} - -TDEActionPtrList TDEActionCollection::actions() const -{ - TDEActionPtrList lst; - - TQAsciiDictIterator it( d->m_actionDict ); - for( ; it.current(); ++it ) - lst.append( it.current() ); - - return lst; -} - -void TDEActionCollection::setInstance( TDEInstance *instance ) -{ - if ( instance ) - d->m_instance = instance; - else - d->m_instance = TDEGlobal::instance(); -} - -TDEInstance *TDEActionCollection::instance() const -{ - return d->m_instance; -} - -void TDEActionCollection::setXMLFile( const TQString& sXMLFile ) -{ - d->m_sXMLFile = sXMLFile; -} - -const TQString& TDEActionCollection::xmlFile() const -{ - return d->m_sXMLFile; -} - -void TDEActionCollection::setHighlightingEnabled( bool enable ) -{ - d->m_highlight = enable; -} - -bool TDEActionCollection::highlightingEnabled() const -{ - return d->m_highlight; -} - -void TDEActionCollection::connectHighlight( TQWidget *container, TDEAction *action ) -{ - if ( !d->m_highlight ) - return; - - TQPtrList *actionList = d->m_dctHighlightContainers[ container ]; - - if ( !actionList ) - { - actionList = new TQPtrList; - - if ( ::tqqt_cast( container ) ) - { - connect( container, TQT_SIGNAL( highlighted( int ) ), - this, TQT_SLOT( slotMenuItemHighlighted( int ) ) ); - connect( container, TQT_SIGNAL( aboutToHide() ), - this, TQT_SLOT( slotMenuAboutToHide() ) ); - } - else if ( ::tqqt_cast( container ) ) - { - connect( container, TQT_SIGNAL( highlighted( int, bool ) ), - this, TQT_SLOT( slotToolBarButtonHighlighted( int, bool ) ) ); - } - - connect( container, TQT_SIGNAL( destroyed() ), - this, TQT_SLOT( slotDestroyed() ) ); - - d->m_dctHighlightContainers.insert( container, actionList ); - } - - actionList->append( action ); -} - -void TDEActionCollection::disconnectHighlight( TQWidget *container, TDEAction *action ) -{ - if ( !d->m_highlight ) - return; - - TQPtrList *actionList = d->m_dctHighlightContainers[ container ]; - - if ( !actionList ) - return; - - actionList->removeRef( action ); - - if ( actionList->isEmpty() ) - d->m_dctHighlightContainers.remove( container ); -} - -void TDEActionCollection::slotMenuItemHighlighted( int id ) -{ - if ( !d->m_highlight ) - return; - - if ( d->m_currentHighlightAction ) - emit actionHighlighted( d->m_currentHighlightAction, false ); - - TQWidget *container = const_cast(TQT_TQWIDGET_CONST( sender() )); - - d->m_currentHighlightAction = findAction( container, id ); - - if ( !d->m_currentHighlightAction ) - { - if ( !d->m_statusCleared ) - emit clearStatusText(); - d->m_statusCleared = true; - return; - } - - d->m_statusCleared = false; - emit actionHighlighted( d->m_currentHighlightAction ); - emit actionHighlighted( d->m_currentHighlightAction, true ); - emit actionStatusText( d->m_currentHighlightAction->toolTip() ); -} - -void TDEActionCollection::slotMenuAboutToHide() -{ - if ( d->m_currentHighlightAction ) - emit actionHighlighted( d->m_currentHighlightAction, false ); - d->m_currentHighlightAction = 0; - - if ( !d->m_statusCleared ) - emit clearStatusText(); - d->m_statusCleared = true; -} - -void TDEActionCollection::slotToolBarButtonHighlighted( int id, bool highlight ) -{ - if ( !d->m_highlight ) - return; - - TQWidget *container = const_cast(TQT_TQWIDGET_CONST( sender() )); - - TDEAction *action = findAction( container, id ); - - if ( !action ) - { - d->m_currentHighlightAction = 0; - // use tooltip groups for toolbar status text stuff instead (Simon) -// emit clearStatusText(); - return; - } - - emit actionHighlighted( action, highlight ); - - if ( highlight ) - d->m_currentHighlightAction = action; - else - { - d->m_currentHighlightAction = 0; -// emit clearStatusText(); - } -} - -void TDEActionCollection::slotDestroyed() -{ - d->m_dctHighlightContainers.remove( reinterpret_cast( const_cast(TQT_TQOBJECT_CONST(sender())) ) ); -} - -TDEAction *TDEActionCollection::findAction( TQWidget *container, int id ) -{ - TQPtrList *actionList = d->m_dctHighlightContainers[ reinterpret_cast( container ) ]; - - if ( !actionList ) - return 0; - - TQPtrListIterator it( *actionList ); - for (; it.current(); ++it ) - if ( it.current()->isPlugged( container, id ) ) - return it.current(); - - return 0; -} - -const KXMLGUIClient *TDEActionCollection::parentGUIClient() const -{ - return d->m_parentGUIClient; -} - -#ifndef KDE_NO_COMPAT -// KDE 4: remove -TDEActionCollection TDEActionCollection::operator+(const TDEActionCollection &c ) const -{ - kdWarning(129) << "TDEActionCollection::operator+(): function is severely deprecated." << endl; - TDEActionCollection ret( *this ); - - TQValueList actions = c.actions(); - TQValueList::ConstIterator it = actions.begin(); - TQValueList::ConstIterator end = actions.end(); - for (; it != end; ++it ) - ret.insert( *it ); - - return ret; -} - -TDEActionCollection &TDEActionCollection::operator=( const TDEActionCollection © ) -{ - kdWarning(129) << "TDEActionCollection::operator=(): function is severely deprecated." << endl; - //d->m_bOneTDEAccelOnly = copy.d->m_bOneTDEAccelOnly; - //d->m_iWidgetCurrent = copy.d->m_iWidgetCurrent; - //d->m_widgetList = copy.d->m_widgetList; - //d->m_kaccelList = copy.d->m_kaccelList; - d->m_widget = copy.d->m_widget; - d->m_kaccel = copy.d->m_kaccel; - d->m_actionDict = copy.d->m_actionDict; - setInstance( copy.instance() ); - return *this; -} - -TDEActionCollection &TDEActionCollection::operator+=( const TDEActionCollection &c ) -{ - kdWarning(129) << "TDEActionCollection::operator+=(): function is severely deprecated." << endl; - TQAsciiDictIterator it(c.d->m_actionDict); - for ( ; it.current(); ++it ) - insert( it.current() ); - - return *this; -} -#endif // KDE 4: remove end - -//--------------------------------------------------------------------- -// TDEActionShortcutList -//--------------------------------------------------------------------- - -TDEActionShortcutList::TDEActionShortcutList( TDEActionCollection* pColl ) -: m_actions( *pColl ) - { } -TDEActionShortcutList::~TDEActionShortcutList() - { } -uint TDEActionShortcutList::count() const - { return m_actions.count(); } -TQString TDEActionShortcutList::name( uint i ) const - { return m_actions.action(i)->name(); } -TQString TDEActionShortcutList::label( uint i ) const - { return m_actions.action(i)->text(); } -TQString TDEActionShortcutList::whatsThis( uint i ) const - { return m_actions.action(i)->whatsThis(); } -const TDEShortcut& TDEActionShortcutList::shortcut( uint i ) const - { return m_actions.action(i)->shortcut(); } -const TDEShortcut& TDEActionShortcutList::shortcutDefault( uint i ) const - { return m_actions.action(i)->shortcutDefault(); } -bool TDEActionShortcutList::isConfigurable( uint i ) const - { return m_actions.action(i)->isShortcutConfigurable(); } -bool TDEActionShortcutList::setShortcut( uint i, const TDEShortcut& cut ) - { return m_actions.action(i)->setShortcut( cut ); } -const TDEInstance* TDEActionShortcutList::instance() const - { return m_actions.instance(); } -TQVariant TDEActionShortcutList::getOther( Other, uint ) const - { return TQVariant(); } -bool TDEActionShortcutList::setOther( Other, uint, TQVariant ) - { return false; } -const TDEAction *TDEActionShortcutList::action( uint i) const - { return m_actions.action(i); } - -bool TDEActionShortcutList::save() const -{ - const KXMLGUIClient* guiClient=m_actions.parentGUIClient(); - const TQString xmlFile=guiClient ? guiClient->xmlFile() : m_actions.xmlFile(); - kdDebug(129) << "TDEActionShortcutList::save(): xmlFile = " << xmlFile << endl; - - if( m_actions.xmlFile().isEmpty() ) - return writeSettings(); - - TQString attrShortcut = TQString::fromLatin1("shortcut"); - TQString attrAccel = TQString::fromLatin1("accel"); // Depricated attribute - - // Read XML file - TQString sXml( KXMLGUIFactory::readConfigFile( xmlFile, false, instance() ) ); - TQDomDocument doc; - doc.setContent( sXml ); - - // Process XML data - - // Get hold of ActionProperties tag - TQDomElement elem = KXMLGUIFactory::actionPropertiesElement( doc ); - - // now, iterate through our actions - uint nSize = count(); - for( uint i = 0; i < nSize; i++ ) { - const TQString& sName = name(i); - - bool bSameAsDefault = (shortcut(i) == shortcutDefault(i)); - //kdDebug(129) << "name = " << sName << " shortcut = " << shortcut(i).toStringInternal() << " def = " << shortcutDefault(i).toStringInternal() << endl; - - // now see if this element already exists - // and create it if necessary (unless bSameAsDefault) - TQDomElement act_elem = KXMLGUIFactory::findActionByName( elem, sName, !bSameAsDefault ); - if ( act_elem.isNull() ) - continue; - - act_elem.removeAttribute( attrAccel ); - if( bSameAsDefault ) { - act_elem.removeAttribute( attrShortcut ); - //kdDebug(129) << "act_elem.attributes().count() = " << act_elem.attributes().count() << endl; - if( act_elem.attributes().count() == 1 ) - elem.removeChild( act_elem ); - } else { - act_elem.setAttribute( attrShortcut, shortcut(i).toStringInternal() ); - } - } - - // Write back to XML file - return KXMLGUIFactory::saveConfigFile( doc, guiClient ? guiClient->localXMLFile() : m_actions.xmlFile(), instance() ); -} - -//--------------------------------------------------------------------- -// TDEActionPtrShortcutList -//--------------------------------------------------------------------- - -TDEActionPtrShortcutList::TDEActionPtrShortcutList( TDEActionPtrList& list ) -: m_actions( list ) - { } -TDEActionPtrShortcutList::~TDEActionPtrShortcutList() - { } -uint TDEActionPtrShortcutList::count() const - { return m_actions.count(); } -TQString TDEActionPtrShortcutList::name( uint i ) const - { return m_actions[i]->name(); } -TQString TDEActionPtrShortcutList::label( uint i ) const - { return m_actions[i]->text(); } -TQString TDEActionPtrShortcutList::whatsThis( uint i ) const - { return m_actions[i]->whatsThis(); } -const TDEShortcut& TDEActionPtrShortcutList::shortcut( uint i ) const - { return m_actions[i]->shortcut(); } -const TDEShortcut& TDEActionPtrShortcutList::shortcutDefault( uint i ) const - { return m_actions[i]->shortcutDefault(); } -bool TDEActionPtrShortcutList::isConfigurable( uint i ) const - { return m_actions[i]->isShortcutConfigurable(); } -bool TDEActionPtrShortcutList::setShortcut( uint i, const TDEShortcut& cut ) - { return m_actions[i]->setShortcut( cut ); } -TQVariant TDEActionPtrShortcutList::getOther( Other, uint ) const - { return TQVariant(); } -bool TDEActionPtrShortcutList::setOther( Other, uint, TQVariant ) - { return false; } -bool TDEActionPtrShortcutList::save() const - { return false; } - -void TDEActionShortcutList::virtual_hook( int id, void* data ) -{ TDEShortcutList::virtual_hook( id, data ); } - -void TDEActionPtrShortcutList::virtual_hook( int id, void* data ) -{ TDEShortcutList::virtual_hook( id, data ); } - -void TDEActionCollection::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -/* vim: et sw=2 ts=2 - */ - -#include "kactioncollection.moc" diff --git a/tdeui/kactioncollection.h b/tdeui/kactioncollection.h deleted file mode 100644 index 9ef517579..000000000 --- a/tdeui/kactioncollection.h +++ /dev/null @@ -1,393 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999 Reginald Stadlbauer - (C) 1999 Simon Hausmann - (C) 2000 Nicolas Hadacek - (C) 2000 Kurt Granroth - (C) 2000 Michael Koch - (C) 2001 Holger Freyther - (C) 2002 Ellis Whitehead - - 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 __kactioncollection_h__ -#define __kactioncollection_h__ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -class TQMenuBar; -class TQPopupMenu; -class TQComboBox; -class TQPoint; -class TQIconSet; -class TQString; -class TDEToolBar; - -class TDEAccel; -class TDEAccelActions; -class TDEConfig; -class TDEConfigBase; -class KURL; -class TDEInstance; -class TDEToolBar; -class TDEActionCollection; -class TDEPopupMenu; -class TDEMainWindow; -class KXMLGUIClient; - -typedef TQValueList TDEActionPtrList; - -/** - * A managed set of TDEAction objects. - * - * If you set the tooltips on TDEActions and want the tooltip to show in statusbar - * (recommended) then you will need to connect a couple of the actionclass signals - * to the toolbar. - * The easiest way of doing this is in your TDEMainWindow subclass, where you create - * a statusbar, do: - * - * \code - * actionCollection()->setHighlightingEnabled(true); - * connect(actionCollection(), TQT_SIGNAL( actionStatusText( const TQString & ) ), - * statusBar(), TQT_SLOT( message( const TQString & ) ) ); - * connect(actionCollection(), TQT_SIGNAL( clearStatusText() ), - * statusBar(), TQT_SLOT( clear() ) ); - * \endcode - */ -class TDEUI_EXPORT TDEActionCollection : public TQObject -{ - friend class TDEAction; - friend class KXMLGUIClient; - - Q_OBJECT - -public: - TDEActionCollection( TQWidget *parent, const char *name = 0, TDEInstance *instance = 0 ); - /** - * Use this constructor if you want the collection's actions to restrict - * their accelerator keys to @p watch rather than the @p parent. If - * you don't require shortcuts, you can pass a null to the @p watch parameter. - */ - TDEActionCollection( TQWidget *watch, TQObject* parent, const char *name = 0, TDEInstance *instance = 0 ); -#ifndef KDE_NO_COMPAT - TDEActionCollection( const TDEActionCollection © ); -#endif - virtual ~TDEActionCollection(); - - /** - * This sets the widget to which the keyboard shortcuts should be attached. - * You only need to call this if a null pointer was passed in the constructor. - */ - virtual void setWidget( TQWidget *widget ); - - /** - * This indicates whether new actions which are created in this collection - * should have their keyboard shortcuts automatically connected on - * construction. Set to 'false' if you will be loading XML-based settings. - * This is automatically done by KParts. The default is 'true'. - * @see isAutoConnectShortcuts() - */ - void setAutoConnectShortcuts( bool ); - - /** - * This indicates whether new actions which are created in this collection - * have their keyboard shortcuts automatically connected on - * construction. - * @see setAutoConnectShortcuts() - */ - bool isAutoConnectShortcuts(); - - /** - * This sets the default shortcut scope for new actions created in this - * collection. The default is ScopeUnspecified. Ideally the default - * would have been ScopeWidget, but that would cause some backwards - * compatibility problems. - */ - //void setDefaultScope( TDEAction::Scope ); - - /** - * Doc/View model. This lets you add the action collection of a document - * to a view's action collection. - */ - bool addDocCollection( TDEActionCollection* pDoc ); - - /** Returns the number of widgets which this collection is associated with. */ - //uint widgetCount() const; - - /** - * Returns true if the collection has its own TDEAccel object. This will be - * the case if it was constructed with a valid widget ptr or if setWidget() - * was called. - */ - //bool ownsTDEAccel() const; - - /** @deprecated Deprecated because of ambiguous name. Use kaccel() */ - virtual TDEAccel* accel() KDE_DEPRECATED; - /** @deprecated Deprecated because of ambiguous name. Use kaccel() */ - virtual const TDEAccel* accel() const KDE_DEPRECATED; - - /** Returns the TDEAccel object of the most recently set widget. */ - TDEAccel* kaccel(); - /** Returns the TDEAccel object of the most recently set widget. Const version for convenience. */ - const TDEAccel* kaccel() const; - - /** @internal, for TDEAction::kaccelCurrent() */ - TDEAccel* builderTDEAccel() const; - /** Returns the TDEAccel object associated with widget #. */ - //TDEAccel* widgetTDEAccel( uint i ); - //const TDEAccel* widgetTDEAccel( uint i ) const; - - /** Returns the number of actions in the collection */ - virtual uint count() const; - bool isEmpty() const { return (count() == 0); } - /** - * Return the TDEAction* at position "index" in the action collection. - * @see count() - */ - virtual TDEAction* action( int index ) const; - /** - * Find an action (optionally, of a given subclass of TDEAction) in the action collection. - * @param name Name of the TDEAction. - * @param classname Name of the TDEAction subclass. - * @return A pointer to the first TDEAction in the collection which matches the parameters or - * null if nothing matches. - */ - virtual TDEAction* action( const char* name, const char* classname = 0 ) const; - - /** Returns a list of all the groups of all the TDEActions in this action collection. - * @see TDEAction::group() - * @see TDEAction::setGroup() - */ - virtual TQStringList groups() const; - /** - * Returns the list of actions in a particular group managed by this action collection. - * @param group The name of the group. - */ - virtual TDEActionPtrList actions( const TQString& group ) const; - /** Returns the list of actions managed by this action collection. */ - virtual TDEActionPtrList actions() const; - - /** - * Used for reading shortcut configuration from a non-XML rc file. - */ - bool readShortcutSettings( const TQString& sConfigGroup = TQString::null, TDEConfigBase* pConfig = 0 ); - /** - * Used for writing shortcut configuration to a non-XML rc file. - */ - bool writeShortcutSettings( const TQString& sConfigGroup = TQString::null, TDEConfigBase* pConfig = 0 ) const; - - void setInstance( TDEInstance *instance ); - /** The instance with which this class is associated. */ - TDEInstance *instance() const; - - /** - * @deprecated - */ - void setXMLFile( const TQString& ); - /** - * @deprecated - */ - const TQString& xmlFile() const; - - //TODO FOR KDE4 make this default true - /** - * Enable highlighting notification for specific TDEActions. - * This is false by default, so, by default, the highlighting - * signals will not be emitted. - * - * @see connectHighlight() - * @see disconnectHighlight() - * @see actionHighlighted() - * @see actionHighlighted() - * @see highlightingEnabled() - */ - void setHighlightingEnabled( bool enable ); - /** - * Return whether highlighting notifications are enabled. - * @see connectHighlight() - * @see disconnectHighlight() - * @see actionHighlighted() - * @see setHighlightingEnabled() - * @see actionHighlighted() - */ - bool highlightingEnabled() const; - - /** - * Call this function if you want to receive a signal whenever a TDEAction is highlighted in a menu or a toolbar. - * This is only needed if you do not add this action to this container. - * You will generally not need to call this function. - * - * @param container A container in which the TDEAction is plugged (must inherit TQPopupMenu or TDEToolBar) - * @param action The action you are interested in - * @see disconnectHighlight() - * @see actionHighlighted() - * @see setHighlightingEnabled() - * @see highlightingEnabled() - * @see actionHighlighted() - */ - void connectHighlight( TQWidget *container, TDEAction *action ); - /** - * Disconnect highlight notifications for a particular pair of contianer and action. - * This is only needed if you do not add this action to this container. - * You will generally not need to call this function. - * - * @param container A container in which the TDEAction is plugged (must inherit TQPopupMenu or TDEToolBar) - * @param action The action you are interested in - * @see connectHighlight() - * @see actionHighlighted() - * @see setHighlightingEnabled() - * @see highlightingEnabled() - * @see actionHighlighted() - */ - void disconnectHighlight( TQWidget *container, TDEAction *action ); - - /** - * The parent KXMLGUIClient, return 0L if not available. - */ - const KXMLGUIClient *parentGUIClient() const; - -signals: - void inserted( TDEAction* ); - void removed( TDEAction* ); - - /** Emitted when @p action is highlighted. - * This is only emitted if you have setHighlightingEnabled() - * @see connectHighlight() - * @see disconnectHighlight() - * @see actionHighlighted() - * @see setHighlightingEnabled() - * @see highlightingEnabled() - */ - void actionHighlighted( TDEAction *action ); - /** Emitted when @p action is highlighed or loses highlighting. - * This is only emitted if you have setHighlightingEnabled() - * @see connectHighlight() - * @see disconnectHighlight() - * @see actionHighlighted() - * @see setHighlightingEnabled() - * @see highlightingEnabled() - */ - void actionHighlighted( TDEAction *action, bool highlight ); - /** Emitted when an action is highlighted, with text - * being the tooltip for the action. - * This is only emitted if you have setHighlightingEnabled() - * - * This is useful to connect to KStatusBar::message(). See - * this class overview for more information. - * - * @see setHighlightingEnabled() - */ - void actionStatusText( const TQString &text ); - /** Emitted when an action loses highlighting. - * This is only emitted if you have setHighlightingEnabled() - * - * @see setHighlightingEnabled() - */ - void clearStatusText(); - -private: - /** - * @internal Only to be called by KXMLGUIFactory::addClient(). - * When actions are being connected, TDEAction needs to know what - * widget it should connect widget-scope actions to, and what - * main window it should connect - */ - void beginXMLPlug( TQWidget *widget ); - void endXMLPlug(); - /** @internal. Only to be called by KXMLGUIFactory::removeClient() */ - void prepareXMLUnplug(); - void unplugShortcuts( TDEAccel* kaccel ); - - void _clear(); - void _insert( TDEAction* ); - void _remove( TDEAction* ); - TDEAction* _take( TDEAction* ); - -private slots: - void slotMenuItemHighlighted( int id ); - void slotToolBarButtonHighlighted( int id, bool highlight ); - void slotMenuAboutToHide(); - void slotDestroyed(); - -private: - TDEAction *findAction( TQWidget *container, int id ); - -#ifndef KDE_NO_COMPAT -public: - TDEActionCollection( TQObject *parent, const char *name = 0, TDEInstance *instance = 0 ); -#endif - -public: - /** - * Add an action to the collection. - * Generally you don't have to call this. The action inserts itself automatically - * into its parent collection. This can be useful however for a short-lived - * collection (e.g. for a popupmenu, where the signals from the collection are needed too). - * (don't forget that in the simple case, a list of actions should be a simple TDEActionPtrList). - * If you manually insert actions into a 2nd collection, don't forget to take them out - * again before destroying the collection. - * @param action The TDEAction to add. - */ - void insert( TDEAction* action); - - /** - * Removes an action from the collection and deletes it. - * Since the TDEAction destructor removes the action from the collection, you generally - * don't have to call this. - * @param action The TDEAction to remove. - */ - void remove( TDEAction* action ); - - /** - * Removes an action from the collection. - * Since the TDEAction destructor removes the action from the collection, you generally - * don't have to call this. - * @return NULL if not found else returns action. - * @param action the TDEAction to remove. - */ - TDEAction* take( TDEAction* action ); - -#ifndef KDE_NO_COMPAT - TDEActionCollection operator+ ( const TDEActionCollection& ) const; - TDEActionCollection& operator= ( const TDEActionCollection& ); - TDEActionCollection& operator+= ( const TDEActionCollection& ); -#endif // !KDE_NO_COMPAT - - // KDE4: clear() doesn't need to be a slot -public slots: - /** - * Clears the entire actionCollection, deleting all actions. - * @see remove - */ - void clear(); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - TDEActionCollection( const char* name, const KXMLGUIClient* parent ); - class TDEActionCollectionPrivate; - TDEActionCollectionPrivate *d; -}; - -#endif diff --git a/tdeui/kactionselector.cpp b/tdeui/kactionselector.cpp deleted file mode 100644 index e913f01f6..000000000 --- a/tdeui/kactionselector.cpp +++ /dev/null @@ -1,540 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002 Anders Lund - - 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. -*/ - - -#include "kactionselector.h" - -#include -#include -#include // for spacingHint() -#include -#include -#include -#include -#include -#include -#include -#include - -class TDEActionSelectorPrivate { - public: - TQListBox *availableListBox, *selectedListBox; - TQToolButton *btnAdd, *btnRemove, *btnUp, *btnDown; - TQLabel *lAvailable, *lSelected; - bool moveOnDoubleClick, keyboardEnabled; - TDEActionSelector::ButtonIconSize iconSize; - TQString addIcon, removeIcon, upIcon, downIcon; - TDEActionSelector::InsertionPolicy availableInsertionPolicy, selectedInsertionPolicy; - bool showUpDownButtons; -}; - -//BEGIN Constructor/destructor - -TDEActionSelector::TDEActionSelector( TQWidget *parent, const char *name ) - : TQWidget( parent, name ) -{ - d = new TDEActionSelectorPrivate(); - d->moveOnDoubleClick = true; - d->keyboardEnabled = true; - d->iconSize = SmallIcon; - d->addIcon = TQApplication::reverseLayout()? "back" : "forward"; - d->removeIcon = TQApplication::reverseLayout()? "forward" : "back"; - d->upIcon = "up"; - d->downIcon = "down"; - d->availableInsertionPolicy = Sorted; - d->selectedInsertionPolicy = BelowCurrent; - d->showUpDownButtons = true; - - //int isz = IconSize( KIcon::Small ); - - TQHBoxLayout *lo = new TQHBoxLayout( this ); - lo->setSpacing( KDialog::spacingHint() ); - - TQVBoxLayout *loAv = new TQVBoxLayout( lo ); - d->lAvailable = new TQLabel( i18n("&Available:"), this ); - loAv->addWidget( d->lAvailable ); - d->availableListBox = new TQListBox( this ); - loAv->addWidget( d->availableListBox ); - d->lAvailable->setBuddy( d->availableListBox ); - - TQVBoxLayout *loHBtns = new TQVBoxLayout( lo ); - loHBtns->addStretch( 1 ); - d->btnAdd = new TQToolButton( this ); - loHBtns->addWidget( d->btnAdd ); - d->btnRemove = new TQToolButton( this ); - loHBtns->addWidget( d->btnRemove ); - loHBtns->addStretch( 1 ); - - TQVBoxLayout *loS = new TQVBoxLayout( lo ); - d->lSelected = new TQLabel( i18n("&Selected:"), this ); - loS->addWidget( d->lSelected ); - d->selectedListBox = new TQListBox( this ); - loS->addWidget( d->selectedListBox ); - d->lSelected->setBuddy( d->selectedListBox ); - - TQVBoxLayout *loVBtns = new TQVBoxLayout( lo ); - loVBtns->addStretch( 1 ); - d->btnUp = new TQToolButton( this ); - d->btnUp->setAutoRepeat( true ); - loVBtns->addWidget( d->btnUp ); - d->btnDown = new TQToolButton( this ); - d->btnDown->setAutoRepeat( true ); - loVBtns->addWidget( d->btnDown ); - loVBtns->addStretch( 1 ); - - loadIcons(); - - connect( d->btnAdd, TQT_SIGNAL(clicked()), this, TQT_SLOT(buttonAddClicked()) ); - connect( d->btnRemove, TQT_SIGNAL(clicked()), this, TQT_SLOT(buttonRemoveClicked()) ); - connect( d->btnUp, TQT_SIGNAL(clicked()), this, TQT_SLOT(buttonUpClicked()) ); - connect( d->btnDown, TQT_SIGNAL(clicked()), this, TQT_SLOT(buttonDownClicked()) ); - connect( d->availableListBox, TQT_SIGNAL(doubleClicked(TQListBoxItem*)), - this, TQT_SLOT(itemDoubleClicked(TQListBoxItem*)) ); - connect( d->selectedListBox, TQT_SIGNAL(doubleClicked(TQListBoxItem*)), - this, TQT_SLOT(itemDoubleClicked(TQListBoxItem*)) ); - connect( d->availableListBox, TQT_SIGNAL(currentChanged(TQListBoxItem*)), - this, TQT_SLOT(slotCurrentChanged(TQListBoxItem *)) ); - connect( d->selectedListBox, TQT_SIGNAL(currentChanged(TQListBoxItem*)), - this, TQT_SLOT(slotCurrentChanged(TQListBoxItem *)) ); - - d->availableListBox->installEventFilter( this ); - d->selectedListBox->installEventFilter( this ); -} - -TDEActionSelector::~TDEActionSelector() -{ - delete d; -} - -//END Constructor/destroctor - -//BEGIN Public Methods - -TQListBox *TDEActionSelector::availableListBox() const -{ - return d->availableListBox; -} - -TQListBox *TDEActionSelector::selectedListBox() const -{ - return d->selectedListBox; -} - -void TDEActionSelector::setButtonIcon( const TQString &icon, MoveButton button ) -{ - switch ( button ) - { - case ButtonAdd: - d->addIcon = icon; - d->btnAdd->setIconSet( SmallIconSet( icon, d->iconSize ) ); - break; - case ButtonRemove: - d->removeIcon = icon; - d->btnRemove->setIconSet( SmallIconSet( icon, d->iconSize ) ); - break; - case ButtonUp: - d->upIcon = icon; - d->btnUp->setIconSet( SmallIconSet( icon, d->iconSize ) ); - break; - case ButtonDown: - d->downIcon = icon; - d->btnDown->setIconSet( SmallIconSet( icon, d->iconSize ) ); - break; - default: - kdDebug(13001)<<"TDEActionSelector::setButtonIcon: DAINBREAD!"<btnAdd->setIconSet( iconset ); - break; - case ButtonRemove: - d->btnRemove->setIconSet( iconset ); - break; - case ButtonUp: - d->btnUp->setIconSet( iconset ); - break; - case ButtonDown: - d->btnDown->setIconSet( iconset ); - break; - default: - kdDebug(13001)<<"TDEActionSelector::setButtonIconSet: DAINBREAD!"<btnAdd->setTextLabel( tip ); - break; - case ButtonRemove: - d->btnRemove->setTextLabel( tip ); - break; - case ButtonUp: - d->btnUp->setTextLabel( tip ); - break; - case ButtonDown: - d->btnDown->setTextLabel( tip ); - break; - default: - kdDebug(13001)<<"TDEActionSelector::setButtonToolTip: DAINBREAD!"<btnAdd, text ); - break; - case ButtonRemove: - TQWhatsThis::add( d->btnRemove, text ); - break; - case ButtonUp: - TQWhatsThis::add( d->btnUp, text ); - break; - case ButtonDown: - TQWhatsThis::add( d->btnDown, text ); - break; - default: - kdDebug(13001)<<"TDEActionSelector::setButtonWhatsThis: DAINBREAD!"<btnAdd->setEnabled( d->availableListBox->currentItem() > -1 ); - d->btnRemove->setEnabled( d->selectedListBox->currentItem() > -1 ); - d->btnUp->setEnabled( d->selectedListBox->currentItem() > 0 ); - d->btnDown->setEnabled( d->selectedListBox->currentItem() > -1 && - d->selectedListBox->currentItem() < (int)d->selectedListBox->count() - 1 ); -} - -//END Public Methods - -//BEGIN Properties - -bool TDEActionSelector::moveOnDoubleClick() const -{ - return d->moveOnDoubleClick; -} - -void TDEActionSelector::setMoveOnDoubleClick( bool b ) -{ - d->moveOnDoubleClick = b; -} - -bool TDEActionSelector::keyboardEnabled() const -{ - return d->keyboardEnabled; -} - -void TDEActionSelector::setKeyboardEnabled( bool b ) -{ - d->keyboardEnabled = b; -} - -TQString TDEActionSelector::availableLabel() const -{ - return d->lAvailable->text(); -} - -void TDEActionSelector::setAvailableLabel( const TQString &text ) -{ - d->lAvailable->setText( text ); -} - -TQString TDEActionSelector::selectedLabel() const -{ - return d->lSelected->text(); -} - -void TDEActionSelector::setSelectedLabel( const TQString &text ) -{ - d->lSelected->setText( text ); -} - -TDEActionSelector::ButtonIconSize TDEActionSelector::buttonIconSize() const -{ - return d->iconSize; -} - -void TDEActionSelector::setButtonIconSize( ButtonIconSize size ) -{ - d->iconSize = size; - // reload icons - loadIcons(); -} - -TDEActionSelector::InsertionPolicy TDEActionSelector::availableInsertionPolicy() const -{ - return d->availableInsertionPolicy; -} - -void TDEActionSelector::setAvailableInsertionPolicy( InsertionPolicy p ) -{ - d->availableInsertionPolicy = p; -} - -TDEActionSelector::InsertionPolicy TDEActionSelector::selectedInsertionPolicy() const -{ - return d->selectedInsertionPolicy; -} - -void TDEActionSelector::setSelectedInsertionPolicy( InsertionPolicy p ) -{ - d->selectedInsertionPolicy = p; -} - -bool TDEActionSelector::showUpDownButtons() const -{ - return d->showUpDownButtons; -} - -void TDEActionSelector::setShowUpDownButtons( bool show ) -{ - d->showUpDownButtons = show; - if ( show ) - { - d->btnUp->show(); - d->btnDown->show(); - } - else - { - d->btnUp->hide(); - d->btnDown->hide(); - } -} - -//END Properties - -//BEGIN Public Slots - -void TDEActionSelector::polish() -{ - setButtonsEnabled(); -} - -//END Public Slots - -//BEGIN Protected -void TDEActionSelector::keyPressEvent( TQKeyEvent *e ) -{ - if ( ! d->keyboardEnabled ) return; - if ( (e->state() & TQt::ControlButton) ) - { - switch ( e->key() ) - { - case Key_Right: - buttonAddClicked(); - break; - case Key_Left: - buttonRemoveClicked(); - break; - case Key_Up: - buttonUpClicked(); - break; - case Key_Down: - buttonDownClicked(); - break; - default: - e->ignore(); - return; - } - } -} - -bool TDEActionSelector::eventFilter( TQObject *o, TQEvent *e ) -{ - if ( d->keyboardEnabled && e->type() == TQEvent::KeyPress ) - { - if ( (((TQKeyEvent*)e)->state() & TQt::ControlButton) ) - { - switch ( ((TQKeyEvent*)e)->key() ) - { - case Key_Right: - buttonAddClicked(); - break; - case Key_Left: - buttonRemoveClicked(); - break; - case Key_Up: - buttonUpClicked(); - break; - case Key_Down: - buttonDownClicked(); - break; - default: - return TQWidget::eventFilter( o, e ); - break; - } - return true; - } - else if ( o->inherits( TQLISTBOX_OBJECT_NAME_STRING ) ) - { - switch ( ((TQKeyEvent*)e)->key() ) - { - case Key_Return: - case Key_Enter: - TQListBox *lb = (TQListBox*)o; - int index = lb->currentItem(); - if ( index < 0 ) break; - moveItem( lb->item( index ) ); - return true; - } - } - } - return TQWidget::eventFilter( o, e ); -} - -//END Protected - -//BEGIN Private Slots - -void TDEActionSelector::buttonAddClicked() -{ - // move all selected items from available to selected listbox - TQListBoxItem *item = d->availableListBox->firstItem(); - while ( item ) { - if ( item->isSelected() ) { - d->availableListBox->takeItem( item ); - d->selectedListBox->insertItem( item, insertionIndex( d->selectedListBox, d->selectedInsertionPolicy ) ); - d->selectedListBox->setCurrentItem( item ); - emit added( item ); - item = d->availableListBox->firstItem(); - } else - item = item->next(); - } - if ( d->selectedInsertionPolicy == Sorted ) - d->selectedListBox->sort(); - d->selectedListBox->setFocus(); -} - -void TDEActionSelector::buttonRemoveClicked() -{ - // move all selected items from selected to available listbox - TQListBoxItem *item = d->selectedListBox->firstItem(); - while ( item ) { - if ( item->isSelected() ) { - d->selectedListBox->takeItem( item ); - d->availableListBox->insertItem( item, insertionIndex( d->availableListBox, d->availableInsertionPolicy ) ); - d->availableListBox->setCurrentItem( item ); - emit removed( item ); - item = d->selectedListBox->firstItem(); - } else - item = item->next(); - } - if ( d->availableInsertionPolicy == Sorted ) - d->availableListBox->sort(); - d->availableListBox->setFocus(); -} - -void TDEActionSelector::buttonUpClicked() -{ - int c = d->selectedListBox->currentItem(); - if ( c < 1 ) return; - TQListBoxItem *item = d->selectedListBox->item( c ); - d->selectedListBox->takeItem( item ); - d->selectedListBox->insertItem( item, c-1 ); - d->selectedListBox->setCurrentItem( item ); - emit movedUp( item ); -} - -void TDEActionSelector::buttonDownClicked() -{ - int c = d->selectedListBox->currentItem(); - if ( c < 0 || c == int( d->selectedListBox->count() ) - 1 ) return; - TQListBoxItem *item = d->selectedListBox->item( c ); - d->selectedListBox->takeItem( item ); - d->selectedListBox->insertItem( item, c+1 ); - d->selectedListBox->setCurrentItem( item ); - emit movedDown( item ); -} - -void TDEActionSelector::itemDoubleClicked( TQListBoxItem *item ) -{ - if ( d->moveOnDoubleClick ) - moveItem( item ); -} - -//END Private Slots - -//BEGIN Private Methods - -void TDEActionSelector::loadIcons() -{ - d->btnAdd->setIconSet( SmallIconSet( d->addIcon, d->iconSize ) ); - d->btnRemove->setIconSet( SmallIconSet( d->removeIcon, d->iconSize ) ); - d->btnUp->setIconSet( SmallIconSet( d->upIcon, d->iconSize ) ); - d->btnDown->setIconSet( SmallIconSet( d->downIcon, d->iconSize ) ); -} - -void TDEActionSelector::moveItem( TQListBoxItem *item ) -{ - TQListBox *lbFrom = item->listBox(); - TQListBox *lbTo; - if ( lbFrom == d->availableListBox ) - lbTo = d->selectedListBox; - else if ( lbFrom == d->selectedListBox ) - lbTo = d->availableListBox; - else //?! somewhat unlikely... - return; - - InsertionPolicy p = ( lbTo == d->availableListBox ) ? - d->availableInsertionPolicy : d->selectedInsertionPolicy; - - lbFrom->takeItem( item ); - lbTo->insertItem( item, insertionIndex( lbTo, p ) ); - lbTo->setFocus(); - lbTo->setCurrentItem( item ); - - if ( p == Sorted ) - lbTo->sort(); - if ( lbTo == d->selectedListBox ) - emit added( item ); - else - emit removed( item ); -} - -int TDEActionSelector::insertionIndex( TQListBox *lb, InsertionPolicy policy ) -{ - int index; - switch ( policy ) - { - case BelowCurrent: - index = lb->currentItem(); - if ( index > -1 ) index += 1; - break; - case AtTop: - index = 0; - break; - default: - index = -1; - } - return index; -} - -//END Private Methods -#include "kactionselector.moc" diff --git a/tdeui/kactionselector.h b/tdeui/kactionselector.h deleted file mode 100644 index 7cdd20116..000000000 --- a/tdeui/kactionselector.h +++ /dev/null @@ -1,402 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002 Anders Lund - - 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 _KACTION_SELECTOR_H_ -#define _KACTION_SELECTOR_H_ - -#include - -#include - -class TQListBox; -class TQListBoxItem; -class TQKeyEvent; -class TQEvent; -class TQIconSet; - -class TDEActionSelectorPrivate; - -/** - @short A widget for selecting and arranging actions/objects - - This widget allows the user to select from a set of objects and arrange - the order of the selected ones using two list boxes labeled "Available" - and "Used" with horizontal arrows in between to move selected objects between - the two, and vertical arrows on the right to arrange the order of the selected - objects. - - The widget moves objects to the other listbox when doubleclicked if - the property moveOnDoubleClick is set to true (default). See moveOnDoubleClick() - and setMoveOnDoubleClick(). - - The user control the widget using the keyboard if enabled (default), - see keyboardEnabled. - - Note that this may conflist with keyboard selection in the selected list box, - if you set that to anything else than TQListBox::Single (which is the default). - - To use it, simply construct an instance and then add items to the two listboxes, - available through lbAvailable() and lbSelected(). Whenever you want, you can retrieve - the selected options using TQListBox methods on lbSelected(). - - This way, you can use your own TQListBoxItem class, allowing you to easily - store object data in those. - - When an item is moved to a listbox, it is placed below the current item - of that listbox. - - Standard arrow icons are used, but you can use icons of your own choice if desired, - see setButtonIcon(). It is also possible to set tooltips and whatsthis help - for the buttons. See setButtonTooltip() and setButtonWhatsThis(). - - To set whatsthis or tooltips for the listboxes, access them through - availableListbox() and selectedListBox(). - - All the moving buttons are automatically set enabled as expected. - - Signals are sent each time an item is moved, allowing you to follow the - users actions if you need to. See addedToSelection(), removedFromSelection(), - movedUp() and movedDown() - - @author Anders Lund -*/ - -class TDEUI_EXPORT TDEActionSelector : public TQWidget { - Q_OBJECT - TQ_ENUMS( ButtonIconSize InsertionPolicy ) - TQ_PROPERTY( bool moveOnDoubleClick READ moveOnDoubleClick WRITE setMoveOnDoubleClick ) - TQ_PROPERTY( bool keyboardEnabled READ keyboardEnabled WRITE setKeyboardEnabled ) - TQ_PROPERTY( TQString availableLabel READ availableLabel WRITE setAvailableLabel ) - TQ_PROPERTY( TQString selectedLabel READ selectedLabel WRITE setSelectedLabel ) - TQ_PROPERTY( ButtonIconSize buttonIconSize READ buttonIconSize WRITE setButtonIconSize ) - TQ_PROPERTY( InsertionPolicy availableInsertionPolicy READ availableInsertionPolicy WRITE setAvailableInsertionPolicy ) - TQ_PROPERTY( InsertionPolicy selectedInsertionPolicy READ selectedInsertionPolicy WRITE setSelectedInsertionPolicy ) - TQ_PROPERTY( bool showUpDownButtons READ showUpDownButtons WRITE setShowUpDownButtons ) - -public: - TDEActionSelector( TQWidget *parent=0, const char *name=0 ); - ~TDEActionSelector(); - - /** - @return The TQListBox holding the available actions - */ - TQListBox *availableListBox() const; - - /** - @return The TQListBox holding the selected actions - */ - TQListBox *selectedListBox() const; - - /** - This enum indentifies the moving buttons - */ - enum MoveButton { - ButtonAdd, - ButtonRemove, - ButtonUp, - ButtonDown - }; - - /** - This enum identifies the icon sizes, used for the move buttons. - The values correspond to the following pixel sizes: - @li SmallIcon - the return value of IconSize( KIcon::Small ), the user defined size - of a small icon in KDE. This is the default setting. - @li Small - 16px - @li Medium - 22px - @li Large - 32px - @li XLarge - 48px - */ - enum ButtonIconSize { - SmallIcon, - Small, - Medium, - Large, - XLarge - }; - - /** - This enum defines policies for where to insert moved items in a listbox. - The following policies are currently defined: - @li BelowCurrent - The item is inserted below the listbox' - currentItem() or at the end if there is no curent item. - @li Sorted - The listbox is sort()ed after one or more items are inserted. - @li AtTop - The item is inserted at index 0 in the listbox. - @li AtBottom - The item is inserted at the end of the listbox. - - @sa availableInsertionPolicy(), setAvailableInsertionPolicy(), - selectedInsertionPolicy(), setSelectedInsertionPolicy(). - */ - enum InsertionPolicy { - BelowCurrent, - Sorted, - AtTop, - AtBottom - }; - - /** - @return Wheather moveOnDoubleClcik is enabled. - - If enabled, an item in any listbox will be moved to the other one whenever - doubleclicked. - @sa setMoveOnDoubleClick() - */ - bool moveOnDoubleClick() const; - - /** - Sets moveOnDoubleClick to @p enable - @sa moveOnDoubleClick() - */ - void setMoveOnDoubleClick( bool enable ); - - /** - @return Weather keyboard control is enabled. - - When Keyboard control is enabled, the widget will react to - the following keyboard actions: - @li CTRL + Right - simulate clicking the add button - @li CTRL + Left - simulate clicking the remove button - @li CTRL + Up - simulate clicking the up button - @li CTRL + Down - simulate clicking the down button - - Additionally, pressing RETURN or ENTER on one of the list boxes - will cause the current item of that listbox to be moved to the other - listbox. - - The keyboard actions are enabled by default. - - @sa setKeyboardEnabled() - */ - bool keyboardEnabled() const; - - /** - Sets the keyboard enabled depending on @p enable. - @sa keyboardEnabled() - */ - void setKeyboardEnabled( bool enable ); - - /** - @return The text of the label for the available items listbox. - */ - TQString availableLabel() const; - - /** - Sets the label for the available items listbox to @p text. - Note that this label has the listbox as its @e buddy, so that - if you have a single ampersand in the text, the following character - will become the accellerator to focus te listbox. - */ - void setAvailableLabel( const TQString & text ); - - /** - @return the label of the selected items listbox. - */ - TQString selectedLabel() const; - - /** - Sets the label for the selected items listbox to @p text. - Note that this label has the listbox as its @e buddy, so that - if you have a single ampersand in the text, the following character - will become the accellerator to focus te listbox. - */ - void setSelectedLabel( const TQString & text ); - - /** - @return the current ButtonIconSize. - */ - ButtonIconSize buttonIconSize() const; - - /** - Sets the button icon size. - See ButtonIconSize for the possible values and their pixel meaning. - */ - void setButtonIconSize( ButtonIconSize size ); - - /** - @return The current insertion policy for the available listbox. - The default policy for the available listbox is Sorted. - See also InsertionPolicy, setAvailableInsertionPolicy(). - */ - InsertionPolicy availableInsertionPolicy() const; - - /** - Sets the insertion policy for the available listbox. - See also InsertionPolicy, availableInsertionPolicy(). - */ - void setAvailableInsertionPolicy( InsertionPolicy policy ); - - /** - @return The current insertion policy for the selected listbox. - The default policy for the selected listbox is BelowCurrent. - See also InsertionPolicy, setSelectedInsertionPolicy(). - */ - InsertionPolicy selectedInsertionPolicy() const; - - /** - Sets the insertion policy for the selected listbox. - See also InsertionPolicy, selectedInsertionPolicy(). - */ - void setSelectedInsertionPolicy( InsertionPolicy policy ); - - /** - @return wheather the Up and Down buttons should be displayed. - */ - bool showUpDownButtons() const; - - /** - Sets wheather the Up and Down buttons should be displayed - according to @p show - */ - void setShowUpDownButtons( bool show ); - - /** - Sets the pixmap of the button @p button to @p icon. - It calls SmallIconSet(pm) to generate the icon set. - */ - void setButtonIcon( const TQString &icon, MoveButton button ); - - /** - Sets the iconset for button @p button to @p iconset. - You can use this method to et a costum icon set. Either - created by TQIconSet, or use the application instance of - KIconLoader (recommended). - */ - void setButtonIconSet( const TQIconSet &iconset, MoveButton button ); - - /** - Sets the tooltip for the button @p button to @p tip. - */ - void setButtonTooltip( const TQString &tip, MoveButton button ); - - /** - Sets the whatsthis help for button @p button to @p text. - */ - void setButtonWhatsThis( const TQString &text, MoveButton button ); - - /** - Sets the enabled state of all moving buttons to reflect the current - options. - - Be sure to call this if you add or removes items to either listbox after the - widget is show()n - */ - void setButtonsEnabled(); - -signals: - /** - Emitted when an item is moved to the "selected" listbox. - */ - void added( TQListBoxItem *item ); - - /** - Emitted when an item is moved out of the "selected" listbox. - */ - void removed( TQListBoxItem *item ); - - /** - Emitted when an item is moved upwards in the "selected" listbox. - */ - void movedUp( TQListBoxItem *item ); - - /** - Emitted when an item is moved downwards in the "selected" listbox. - */ - void movedDown( TQListBoxItem *item ); - - /** - Emitted when an item is moved to the "selected" listbox. - */ -// void addedToSelection( TQListBoxItem *item ); - -public slots: - /** - Reimplemented for internal reasons. - (calls setButtonsEnabled()) - */ - void polish(); - -protected: - /** - Reimplamented for internal reasons. - */ - void keyPressEvent( TQKeyEvent * ); - - /** - Reimplemented for internal reasons. - */ - bool eventFilter( TQObject *, TQEvent * ); - -private slots: - /** - Move selected item from available box to the selected box - */ - void buttonAddClicked(); - - /** - Move selected item from selected box to available box - */ - void buttonRemoveClicked(); - - /** - Move selected item in selected box upwards - */ - void buttonUpClicked(); - - /** - Move seleted item in selected box downwards - */ - void buttonDownClicked(); - - /** - Moves the item @p item to the other listbox if moveOnDoubleClick is enabled. - */ - void itemDoubleClicked( TQListBoxItem *item ); - - /** - connected to both list boxes to set the buttons enabled - */ - void slotCurrentChanged( TQListBoxItem * ) { setButtonsEnabled(); } - -private: - - /** - Move item @p item to the other listbox - */ - void moveItem( TQListBoxItem *item ); - - /** - loads the icons for the move buttons. - */ - void loadIcons(); - - /** - @return the index to insert an item into listbox @p lb, - given InsertionPolicy @p policy. - - Note that if policy is Sorted, this will return -1. - Sort the listbox after inserting the item in that case. - */ - int insertionIndex( TQListBox *lb, InsertionPolicy policy ); - - /** @private - Private data storage - */ - TDEActionSelectorPrivate *d; -}; - -#endif // _KACTION_SELECTOR_H_ diff --git a/tdeui/kactionshortcutlist.h b/tdeui/kactionshortcutlist.h deleted file mode 100644 index ac8ac020d..000000000 --- a/tdeui/kactionshortcutlist.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef _KACTIONSHORTCUTLIST_H -#define _KACTIONSHORTCUTLIST_H - -#include -#include - -//--------------------------------------------------------------------- -// class TDEActionShortcutList -//--------------------------------------------------------------------- - -class TDEAccelShortcutListPrivate; -class TDEUI_EXPORT TDEActionShortcutList : public TDEShortcutList -{ - public: - TDEActionShortcutList( TDEActionCollection* ); - virtual ~TDEActionShortcutList(); - - virtual uint count() const; - virtual TQString name( uint index ) const; - virtual TQString label( uint index ) const; - virtual TQString whatsThis( uint index ) const; - virtual const TDEShortcut& shortcut( uint index ) const; - virtual const TDEShortcut& shortcutDefault( uint index ) const; - virtual bool isConfigurable( uint index ) const; - virtual bool setShortcut( uint index, const TDEShortcut& shortcut ); - - virtual const TDEInstance* instance() const; - - virtual TQVariant getOther( Other, uint index ) const; - virtual bool setOther( Other, uint index, TQVariant ); - - virtual bool save() const; - - const TDEAction *action( uint ) const; - - protected: - TDEActionCollection& m_actions; - - protected: - virtual void virtual_hook( int id, void* data ); - private: - TDEAccelShortcutListPrivate* d; -}; - -//--------------------------------------------------------------------- -// class TDEActionPtrShortcutList -//--------------------------------------------------------------------- - -class TDEAccelShortcutListPrivate; -class TDEUI_EXPORT TDEActionPtrShortcutList : public TDEShortcutList -{ - public: - TDEActionPtrShortcutList( TDEActionPtrList& ); - virtual ~TDEActionPtrShortcutList(); - - virtual uint count() const; - virtual TQString name( uint index ) const; - virtual TQString label( uint index ) const; - virtual TQString whatsThis( uint index ) const; - virtual const TDEShortcut& shortcut( uint index ) const; - virtual const TDEShortcut& shortcutDefault( uint index ) const; - virtual bool isConfigurable( uint index ) const; - virtual bool setShortcut( uint index, const TDEShortcut& shortcut); - - virtual TQVariant getOther( Other, uint index ) const; - virtual bool setOther( Other, uint index, TQVariant ); - - virtual bool save() const; - - protected: - TDEActionPtrList& m_actions; - - protected: - virtual void virtual_hook( int id, void* data ); - private: - TDEAccelShortcutListPrivate* d; -}; - -#endif // !_KACTIONSHORTCUTLIST_H diff --git a/tdeui/kfontcombo.cpp b/tdeui/kfontcombo.cpp deleted file mode 100644 index 8ce088f8b..000000000 --- a/tdeui/kfontcombo.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (c) 2001 Malte Starostik - - 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. -*/ - - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kfontcombo.h" -#include "kfontcombo.moc" - -#include -#include -#include -#include -#include -#include -#include - -#include - - -struct TDEFontComboPrivate -{ - TDEFontComboPrivate() - : bold(false), - italic(false), - underline(false), - strikeOut(false), - modified(false), - size(0), - lineSpacing(0) - { - } - - bool bold : 1; - bool italic : 1; - bool underline : 1; - bool strikeOut : 1; - bool displayFonts : 1; - bool modified : 1; - int size; - int lineSpacing; - TQString defaultFamily; -}; - -class TDEFontListItem : public TQListBoxItem -{ -public: - TDEFontListItem(const TQString &fontName, TDEFontCombo *combo); - virtual ~TDEFontListItem(); - - virtual int width(const TQListBox *) const; - virtual int height(const TQListBox *) const; - - void updateFont(); - -protected: - virtual void paint(TQPainter *p); - -private: - void createFont(); - -private: - TDEFontCombo *m_combo; - TQString m_fontName; - TQFont *m_font; - bool m_canPaintName; -}; - -TDEFontListItem::TDEFontListItem(const TQString &fontName, TDEFontCombo *combo) - : TQListBoxItem(combo->listBox()), - m_combo(combo), - m_fontName(fontName), - m_font(0), - m_canPaintName(true) -{ - setText(fontName); -} - -TDEFontListItem::~TDEFontListItem() -{ - delete m_font; -} - -int TDEFontListItem::width(const TQListBox *lb) const -{ - if (m_font) - return TQFontMetrics(*m_font).width(text()) + 6; - return lb->fontMetrics().width(text()) + 6; -} - -int TDEFontListItem::height(const TQListBox *lb) const -{ - if (m_combo->d->displayFonts) - return m_combo->d->lineSpacing + 2; - TQFontMetrics fm(lb->fontMetrics()); - return fm.lineSpacing() + 2; -} - -void TDEFontListItem::paint(TQPainter *p) -{ - if (m_combo->d->displayFonts) - { - if (!m_font) - createFont(); - - TQString t = m_fontName; - if (p->device() != m_combo) - { - if (m_canPaintName) - p->setFont(*m_font); - else - t = TQString::fromLatin1("(%1)").arg(m_fontName); - } - TQFontMetrics fm(p->fontMetrics()); - p->drawText(3, (m_combo->d->lineSpacing + fm.ascent() + fm.leading() / 2) / 2, t); - } - else - { - TQFontMetrics fm(p->fontMetrics()); - p->drawText(3, fm.ascent() + fm.leading() / 2, m_fontName); - } -} - -void TDEFontListItem::updateFont() -{ - if (!m_font) - return; - - m_font->setBold(m_combo->d->bold); - m_font->setItalic(m_combo->d->italic); - m_font->setUnderline(m_combo->d->underline); - m_font->setStrikeOut(m_combo->d->strikeOut); - m_font->setPointSize(m_combo->d->size); -} - -void TDEFontListItem::createFont() -{ - if (m_font) - return; - - m_font = new TQFont(m_fontName); - TQFontMetrics fm(*m_font); - for (unsigned int i = 0; i < m_fontName.length(); ++i) - if (!fm.inFont(m_fontName[i])) - { - m_canPaintName = false; - break; - } - updateFont(); -} - -TDEFontCombo::TDEFontCombo(TQWidget *parent, const char *name) - : KComboBox(true, parent, name) -{ - init(); - TQStringList families; - TDEFontChooser::getFontList(families, 0); - setFonts(families); -} - -TDEFontCombo::TDEFontCombo(const TQStringList &fonts, TQWidget *parent, const char *name) - : KComboBox(true, parent, name) -{ - init(); - setFonts(fonts); -} - -void TDEFontCombo::setFonts(const TQStringList &fonts) -{ - clear(); - for (TQStringList::ConstIterator it = fonts.begin(); it != fonts.end(); ++it) - new TDEFontListItem(*it, this); -} - -/* - * Maintenance note: Keep in sync with TDEFontAction::setFont() - */ -void TDEFontCombo::setCurrentFont(const TQString &family) -{ - TQString lowerName = family.lower(); - int c = count(); - for(int i = 0; i < c; i++) - { - if (text(i).lower() == lowerName) - { - setCurrentItem(i); - d->defaultFamily = text(i); - d->modified = false; - return; - } - } - int x = lowerName.find(" ["); - if (x>-1) - { - lowerName = lowerName.left(x); - for(int i = 0; i < c; i++) - { - if (text(i).lower() == lowerName) - { - setCurrentItem(i); - d->defaultFamily = text(i); - d->modified = false; - return; - } - } - } - - lowerName += " ["; - for(int i = 0; i < c; i++) - { - if (text(i).lower().startsWith(lowerName)) - { - setCurrentItem(i); - d->defaultFamily = text(i); - d->modified = false; - return; - } - } - - // nothing matched yet, try a fontconfig reverse lookup and - // check again to solve an alias - FcPattern *pattern = NULL; - FcConfig *config = NULL; - TQString realFamily; - TQRegExp regExp("[-:]"); - pattern = FcNameParse( (unsigned char*) family.ascii() ); - FcDefaultSubstitute(pattern); - FcConfigSubstitute (config, pattern, FcMatchPattern); - pattern = FcFontMatch(NULL, pattern, NULL); - realFamily = (char*)FcNameUnparse(pattern); - realFamily.remove(realFamily.find(regExp), realFamily.length()); - - if ( !realFamily.isEmpty() && realFamily != family ) - setCurrentFont( realFamily ); -} - -void TDEFontCombo::slotModified( int ) -{ - d->modified = 1; -} - -TQString TDEFontCombo::currentFont() const -{ - if (d->modified) - return currentText(); - return d->defaultFamily; -} - -void TDEFontCombo::setCurrentItem(int i) -{ - d->modified = true; - TQComboBox::setCurrentItem(i); -} - -void TDEFontCombo::init() -{ - d = new TDEFontComboPrivate; - d->displayFonts = displayFonts(); - setInsertionPolicy(NoInsertion); - setAutoCompletion(true); - setSize(12); - connect( this, TQT_SIGNAL(highlighted(int)), TQT_SLOT(slotModified(int))); -} - -TDEFontCombo::~TDEFontCombo() -{ - delete d; -} - -void TDEFontCombo::setBold(bool bold) -{ - if (d->bold == bold) - return; - d->bold = bold; - updateFonts(); -} - -bool TDEFontCombo::bold() const -{ - return d->bold; -} - -void TDEFontCombo::setItalic(bool italic) -{ - if (d->italic == italic) - return; - d->italic = italic; - updateFonts(); -} - -bool TDEFontCombo::italic() const -{ - return d->italic; -} - -void TDEFontCombo::setUnderline(bool underline) -{ - if (d->underline == underline) - return; - d->underline = underline; - updateFonts(); -} - -bool TDEFontCombo::underline() const -{ - return d->underline; -} - -void TDEFontCombo::setStrikeOut(bool strikeOut) -{ - if (d->strikeOut == strikeOut) - return; - d->strikeOut = strikeOut; - updateFonts(); -} - -bool TDEFontCombo::strikeOut() const -{ - return d->strikeOut; -} - -void TDEFontCombo::setSize(int size) -{ - if (d->size == size) - return; - d->size = size; - TQFont f; - f.setPointSize(size); - TQFontMetrics fm(f); - d->lineSpacing = fm.lineSpacing(); - updateFonts(); -} - -int TDEFontCombo::size() const -{ - return d->size; -} - -void TDEFontCombo::updateFonts() -{ - if (!d->displayFonts) - return; - - for (unsigned int i = 0; i < listBox()->count(); ++i) - { - TDEFontListItem *item = static_cast(listBox()->item(i)); - item->updateFont(); - } -} - -bool TDEFontCombo::displayFonts() -{ - TDEConfigGroupSaver saver(TDEGlobal::config(), "KDE"); - return TDEGlobal::config()->readBoolEntry("DisplayFontItems", true); -} - -void TDEFontCombo::virtual_hook( int id, void* data ) -{ KComboBox::virtual_hook( id, data ); } - diff --git a/tdeui/kfontcombo.h b/tdeui/kfontcombo.h deleted file mode 100644 index 13c55215b..000000000 --- a/tdeui/kfontcombo.h +++ /dev/null @@ -1,179 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (c) 2001 Malte Starostik - - 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. -*/ - -// $Id$ - -#ifndef _KFONTCOMBO_H_ -#define _KFONTCOMBO_H_ - -#include - -/** - * @short A combobox that lists the available fonts. - * - * The items are painted using the respective font itself, so the user - * can easily choose a font based on its look. This can be turned off - * globally if the user wishes so. - * - * @author Malte Starostik - */ -class TDEUI_EXPORT TDEFontCombo : public KComboBox -{ - Q_OBJECT - TQ_PROPERTY(TQString family READ currentFont WRITE setCurrentFont) - TQ_PROPERTY(bool bold READ bold WRITE setBold DESIGNABLE true) - TQ_PROPERTY(bool italic READ italic WRITE setItalic DESIGNABLE true) - TQ_PROPERTY(bool underline READ underline WRITE setUnderline DESIGNABLE true) - TQ_PROPERTY(bool strikeOut READ strikeOut WRITE setStrikeOut DESIGNABLE true) - TQ_PROPERTY(int fontSize READ size WRITE setSize DESIGNABLE true) -public: - /** - * Constructor - * - * @param parent The parent widget - * @param name The object name for the widget - */ - TDEFontCombo(TQWidget *parent, const char *name = 0); - /** - * Constructor that takes an already initialzed font list - * - * @param fonts A list of fonts to show - * @param parent The parent widget - * @param name The object name for the widget - */ - TDEFontCombo(const TQStringList &fonts, TQWidget *parent, const char *name = 0); - /** - * Destructor - */ - virtual ~TDEFontCombo(); - - /** - * Sets the font list. - * - * @param fonts Font list to show - */ - void setFonts(const TQStringList &fonts); - /** - * Sets the currently selected font. - * - * @param family Font to select. - */ - void setCurrentFont(const TQString &family); - /** - * @return the currently selected font. - */ - TQString currentFont() const; - - /** - * Sets the listed fonts to bold or normal. - * - * @param bold Set to true to display fonts in bold - */ - void setBold(bool bold); - /** - * Returns the current bold status. - * - * @return true if fonts are bold - */ - bool bold() const; - /** - * Sets the listed fonts to italic or regular. - * - * @param italic Set to true to display fonts italic - */ - void setItalic(bool italic); - /** - * Returns the current italic status - * - * @return True if fonts are italic - */ - bool italic() const; - /** - * Sets the listed fonts to underlined or not underlined - * - * @param underline Set to true to display fonts underlined - */ - void setUnderline(bool underline); - /** - * Returns the current underline status - * - * @return True if fonts are underlined - */ - bool underline() const; - /** - * Sets the listed fonts to striked out or not - * - * @param strikeOut Set to true to display fonts striked out - */ - void setStrikeOut(bool strikeOut); - /** - * Returns the current strike out status - * - * @return True if fonts are striked out - */ - bool strikeOut() const; - /** - * Sets the listed fonts' size - * - * @param size Set to the point size to display the fonts in - */ - void setSize(int size); - /** - * Returns the current font size - * - * @return The point size of the fonts - */ - int size() const; - - /** - * Returns the user's setting of whether the items should be painted - * in the respective fonts or not - * - * @return True if the respective fonts are used for painting - */ - static bool displayFonts(); - - virtual void setCurrentItem(int i); - -protected slots: - /** - * @internal - * Listens to highlighted(int) - */ - void slotModified( int i ); - -protected: - /** - * Updated the combo's listBox() to reflect changes made to the - * fonts' attributed - */ - void updateFonts(); - -private: - void init(); - -private: - friend class TDEFontListItem; -protected: - virtual void virtual_hook( int id, void* data ); -private: - struct TDEFontComboPrivate *d; -}; - -#endif - diff --git a/tdeui/kfontdialog.cpp b/tdeui/kfontdialog.cpp deleted file mode 100644 index 107755e7f..000000000 --- a/tdeui/kfontdialog.cpp +++ /dev/null @@ -1,799 +0,0 @@ -/* - - Requires the Qt widget libraries, available at no cost at - http://www.troll.no - - Copyright (C) 1996 Bernd Johannes Wuebben - Copyright (c) 1999 Preston Brown - Copyright (c) 1999 Mario Weilguni - - This library 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. - - 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. -*/ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kfontdialog.moc" - -static int minimumListWidth( const TQListBox *list ) -{ - int w=0; - for( uint i=0; icount(); i++ ) - { - int itemWidth = list->item(i)->width(list); - w = QMAX(w,itemWidth); - } - if( w == 0 ) { w = 40; } - w += list->frameWidth() * 2; - w += list->verticalScrollBar()->sizeHint().width(); - return w; -} - -static int minimumListHeight( const TQListBox *list, int numVisibleEntry ) -{ - int w = list->count() > 0 ? list->item(0)->height(list) : - list->fontMetrics().lineSpacing(); - - if( w < 0 ) { w = 10; } - if( numVisibleEntry <= 0 ) { numVisibleEntry = 4; } - return ( w * numVisibleEntry + 2 * list->frameWidth() ); -} - -class TDEFontChooser::TDEFontChooserPrivate -{ -public: - TDEFontChooserPrivate() - { m_palette.setColor(TQPalette::Active, TQColorGroup::Text, Qt::black); - m_palette.setColor(TQPalette::Active, TQColorGroup::Base, Qt::white); } - TQPalette m_palette; -}; - -TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, - bool onlyFixed, const TQStringList &fontList, - bool makeFrame, int visibleListSize, bool diff, - TQButton::ToggleState *sizeIsRelativeState ) - : TQWidget(parent, name), usingFixed(onlyFixed) -{ - charsetsCombo = 0; - - TQString mainWhatsThisText = - i18n( "Here you can choose the font to be used." ); - TQWhatsThis::add( this, mainWhatsThisText ); - - d = new TDEFontChooserPrivate; - TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint() ); - int checkBoxGap = KDialog::spacingHint() / 2; - - TQWidget *page; - TQGridLayout *gridLayout; - int row = 0; - if( makeFrame ) - { - page = new TQGroupBox( i18n("Requested Font"), this ); - topLayout->addWidget(page); - gridLayout = new TQGridLayout( page, 5, 3, KDialog::marginHint(), KDialog::spacingHint() ); - gridLayout->addRowSpacing( 0, fontMetrics().lineSpacing() ); - row = 1; - } - else - { - page = new TQWidget( this ); - topLayout->addWidget(page); - gridLayout = new TQGridLayout( page, 4, 3, 0, KDialog::spacingHint() ); - } - - // - // first, create the labels across the top - // - TQHBoxLayout *familyLayout = new TQHBoxLayout(); - familyLayout->addSpacing( checkBoxGap ); - if (diff) { - familyCheckbox = new TQCheckBox(i18n("Font"), page); - connect(familyCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox())); - familyLayout->addWidget(familyCheckbox, 0, Qt::AlignLeft); - TQString familyCBToolTipText = - i18n("Change font family?"); - TQString familyCBWhatsThisText = - i18n("Enable this checkbox to change the font family settings."); - TQWhatsThis::add( familyCheckbox, familyCBWhatsThisText ); - TQToolTip::add( familyCheckbox, familyCBToolTipText ); - familyLabel = 0; - } else { - familyCheckbox = 0; - familyLabel = new TQLabel( i18n("Font:"), page, "familyLabel" ); - familyLayout->addWidget(familyLabel, 1, Qt::AlignLeft); - } - gridLayout->addLayout(familyLayout, row, 0 ); - - TQHBoxLayout *styleLayout = new TQHBoxLayout(); - if (diff) { - styleCheckbox = new TQCheckBox(i18n("Font style"), page); - connect(styleCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox())); - styleLayout->addWidget(styleCheckbox, 0, Qt::AlignLeft); - TQString styleCBToolTipText = - i18n("Change font style?"); - TQString styleCBWhatsThisText = - i18n("Enable this checkbox to change the font style settings."); - TQWhatsThis::add( styleCheckbox, styleCBWhatsThisText ); - TQToolTip::add( styleCheckbox, styleCBToolTipText ); - styleLabel = 0; - } else { - styleCheckbox = 0; - styleLabel = new TQLabel( i18n("Font style:"), page, "styleLabel"); - styleLayout->addWidget(styleLabel, 1, Qt::AlignLeft); - } - styleLayout->addSpacing( checkBoxGap ); - gridLayout->addLayout(styleLayout, row, 1 ); - - TQHBoxLayout *sizeLayout = new TQHBoxLayout(); - if (diff) { - sizeCheckbox = new TQCheckBox(i18n("Size"),page); - connect(sizeCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox())); - sizeLayout->addWidget(sizeCheckbox, 0, Qt::AlignLeft); - TQString sizeCBToolTipText = - i18n("Change font size?"); - TQString sizeCBWhatsThisText = - i18n("Enable this checkbox to change the font size settings."); - TQWhatsThis::add( sizeCheckbox, sizeCBWhatsThisText ); - TQToolTip::add( sizeCheckbox, sizeCBToolTipText ); - sizeLabel = 0; - } else { - sizeCheckbox = 0; - sizeLabel = new TQLabel( i18n("Size:"), page, "sizeLabel"); - sizeLayout->addWidget(sizeLabel, 1, Qt::AlignLeft); - } - sizeLayout->addSpacing( checkBoxGap ); - sizeLayout->addSpacing( checkBoxGap ); // prevent label from eating border - gridLayout->addLayout(sizeLayout, row, 2 ); - - row ++; - - // - // now create the actual boxes that hold the info - // - familyListBox = new TDEListBox( page, "familyListBox"); - familyListBox->setEnabled( !diff ); - gridLayout->addWidget( familyListBox, row, 0 ); - TQString fontFamilyWhatsThisText = - i18n("Here you can choose the font family to be used." ); - TQWhatsThis::add( familyListBox, fontFamilyWhatsThisText ); - TQWhatsThis::add(diff?(TQWidget *) familyCheckbox:(TQWidget *) familyLabel, fontFamilyWhatsThisText ); - connect(familyListBox, TQT_SIGNAL(highlighted(const TQString &)), - TQT_SLOT(family_chosen_slot(const TQString &))); - if(!fontList.isEmpty()) - { - familyListBox->insertStringList(fontList); - } - else - { - fillFamilyListBox(onlyFixed); - } - - familyListBox->setMinimumWidth( minimumListWidth( familyListBox ) ); - familyListBox->setMinimumHeight( - minimumListHeight( familyListBox, visibleListSize ) ); - - styleListBox = new TDEListBox( page, "styleListBox"); - styleListBox->setEnabled( !diff ); - gridLayout->addWidget(styleListBox, row, 1); - TQString fontStyleWhatsThisText = - i18n("Here you can choose the font style to be used." ); - TQWhatsThis::add( styleListBox, fontStyleWhatsThisText ); - TQWhatsThis::add(diff?(TQWidget *)styleCheckbox:(TQWidget *)styleLabel, fontFamilyWhatsThisText ); - styleListBox->insertItem(i18n("Regular")); - styleListBox->insertItem(i18n("Italic")); - styleListBox->insertItem(i18n("Bold")); - styleListBox->insertItem(i18n("Bold Italic")); - styleListBox->setMinimumWidth( minimumListWidth( styleListBox ) ); - styleListBox->setMinimumHeight( - minimumListHeight( styleListBox, visibleListSize ) ); - - connect(styleListBox, TQT_SIGNAL(highlighted(const TQString &)), - TQT_SLOT(style_chosen_slot(const TQString &))); - - - sizeListBox = new TDEListBox( page, "sizeListBox"); - sizeOfFont = new KIntNumInput( page, "sizeOfFont"); - sizeOfFont->setMinValue(4); - - sizeListBox->setEnabled( !diff ); - sizeOfFont->setEnabled( !diff ); - if( sizeIsRelativeState ) { - TQString sizeIsRelativeCBText = - i18n("Relative"); - TQString sizeIsRelativeCBToolTipText = - i18n("Font size
fixed or relative
to environment"); - TQString sizeIsRelativeCBWhatsThisText = - i18n("Here you can switch between fixed font size and font size " - "to be calculated dynamically and adjusted to changing " - "environment (e.g. widget dimensions, paper size)." ); - sizeIsRelativeCheckBox = new TQCheckBox( sizeIsRelativeCBText, - page, - "sizeIsRelativeCheckBox" ); - sizeIsRelativeCheckBox->setTristate( diff ); - TQGridLayout *sizeLayout2 = new TQGridLayout( 3,2, KDialog::spacingHint()/2, "sizeLayout2" ); - gridLayout->addLayout(sizeLayout2, row, 2); - sizeLayout2->setColStretch( 1, 1 ); // to prevent text from eating the right border - sizeLayout2->addMultiCellWidget( sizeOfFont, 0, 0, 0, 1); - sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,1); - sizeLayout2->addWidget(sizeIsRelativeCheckBox, 2, 0, Qt::AlignLeft); - TQWhatsThis::add( sizeIsRelativeCheckBox, sizeIsRelativeCBWhatsThisText ); - TQToolTip::add( sizeIsRelativeCheckBox, sizeIsRelativeCBToolTipText ); - } - else { - sizeIsRelativeCheckBox = 0L; - TQGridLayout *sizeLayout2 = new TQGridLayout( 2,1, KDialog::spacingHint()/2, "sizeLayout2" ); - gridLayout->addLayout(sizeLayout2, row, 2); - sizeLayout2->addWidget( sizeOfFont, 0, 0); - sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,0); - } - TQString fontSizeWhatsThisText = - i18n("Here you can choose the font size to be used." ); - TQWhatsThis::add( sizeListBox, fontSizeWhatsThisText ); - TQWhatsThis::add( diff?(TQWidget *)sizeCheckbox:(TQWidget *)sizeLabel, fontSizeWhatsThisText ); - - fillSizeList(); - sizeListBox->setMinimumWidth( minimumListWidth(sizeListBox) + - sizeListBox->fontMetrics().maxWidth() ); - sizeListBox->setMinimumHeight( - minimumListHeight( sizeListBox, visibleListSize ) ); - - connect( sizeOfFont, TQT_SIGNAL( valueChanged(int) ), - TQT_SLOT(size_value_slot(int))); - - connect( sizeListBox, TQT_SIGNAL(highlighted(const TQString&)), - TQT_SLOT(size_chosen_slot(const TQString&)) ); - sizeListBox->setSelected(sizeListBox->findItem(TQString::number(10)), true); // default to 10pt. - - row ++; - - row ++; - sampleEdit = new TQLineEdit( page, "sampleEdit"); - TQFont tmpFont( TDEGlobalSettings::generalFont().family(), 64, TQFont::Black ); - sampleEdit->setFont(tmpFont); - //i18n: This is a classical test phrase. (It contains all letters from A to Z.) - sampleEdit->setText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog")); - sampleEdit->setMinimumHeight( sampleEdit->fontMetrics().lineSpacing() ); - sampleEdit->setAlignment(Qt::AlignCenter); - gridLayout->addMultiCellWidget(sampleEdit, 4, 4, 0, 2); - TQString sampleEditWhatsThisText = - i18n("This sample text illustrates the current settings. " - "You may edit it to test special characters." ); - TQWhatsThis::add( sampleEdit, sampleEditWhatsThisText ); - connect(this, TQT_SIGNAL(fontSelected(const TQFont &)), - TQT_SLOT(displaySample(const TQFont &))); - - TQVBoxLayout *vbox; - if( makeFrame ) - { - page = new TQGroupBox( i18n("Actual Font"), this ); - topLayout->addWidget(page); - vbox = new TQVBoxLayout( page, KDialog::spacingHint() ); - vbox->addSpacing( fontMetrics().lineSpacing() ); - } - else - { - page = new TQWidget( this ); - topLayout->addWidget(page); - vbox = new TQVBoxLayout( page, 0, KDialog::spacingHint() ); - TQLabel *label = new TQLabel( i18n("Actual Font"), page ); - vbox->addWidget( label ); - } - - xlfdEdit = new TQLineEdit( page, "xlfdEdit" ); - vbox->addWidget( xlfdEdit ); - - // lets initialize the display if possible - setFont( TDEGlobalSettings::generalFont(), usingFixed ); - // check or uncheck or gray out the "relative" checkbox - if( sizeIsRelativeState && sizeIsRelativeCheckBox ) - setSizeIsRelative( *sizeIsRelativeState ); - - TDEConfig *config = TDEGlobal::config(); - TDEConfigGroupSaver saver(config, TQString::fromLatin1("General")); - showXLFDArea(config->readBoolEntry(TQString::fromLatin1("fontSelectorShowXLFD"), false)); -} - -TDEFontChooser::~TDEFontChooser() -{ - delete d; -} - -void TDEFontChooser::fillSizeList() { - if(! sizeListBox) return; //assertion. - - static const int c[] = - { - 4, 5, 6, 7, - 8, 9, 10, 11, - 12, 13, 14, 15, - 16, 17, 18, 19, - 20, 22, 24, 26, - 28, 32, 48, 64, - 0 - }; - for(int i = 0; c[i]; ++i) - { - sizeListBox->insertItem(TQString::number(c[i])); - } -} - -void TDEFontChooser::setColor( const TQColor & col ) -{ - d->m_palette.setColor( TQPalette::Active, TQColorGroup::Text, col ); - TQPalette pal = sampleEdit->palette(); - pal.setColor( TQPalette::Active, TQColorGroup::Text, col ); - sampleEdit->setPalette( pal ); -} - -TQColor TDEFontChooser::color() const -{ - return d->m_palette.color( TQPalette::Active, TQColorGroup::Text ); -} - -void TDEFontChooser::setBackgroundColor( const TQColor & col ) -{ - d->m_palette.setColor( TQPalette::Active, TQColorGroup::Base, col ); - TQPalette pal = sampleEdit->palette(); - pal.setColor( TQPalette::Active, TQColorGroup::Base, col ); - sampleEdit->setPalette( pal ); -} - -TQColor TDEFontChooser::backgroundColor() const -{ - return d->m_palette.color( TQPalette::Active, TQColorGroup::Base ); -} - -void TDEFontChooser::setSizeIsRelative( TQButton::ToggleState relative ) -{ - // check or uncheck or gray out the "relative" checkbox - if( sizeIsRelativeCheckBox ) { - if( TQButton::NoChange == relative ) - sizeIsRelativeCheckBox->setNoChange(); - else - sizeIsRelativeCheckBox->setChecked( TQButton::On == relative ); - } -} - -TQButton::ToggleState TDEFontChooser::sizeIsRelative() const -{ - return sizeIsRelativeCheckBox - ? sizeIsRelativeCheckBox->state() - : TQButton::NoChange; -} - -TQSize TDEFontChooser::sizeHint( void ) const -{ - return minimumSizeHint(); -} - - -void TDEFontChooser::enableColumn( int column, bool state ) -{ - if( column & FamilyList ) - { - familyListBox->setEnabled(state); - } - if( column & StyleList ) - { - styleListBox->setEnabled(state); - } - if( column & SizeList ) - { - sizeListBox->setEnabled(state); - } -} - - -void TDEFontChooser::setFont( const TQFont& aFont, bool onlyFixed ) -{ - selFont = aFont; - selectedSize=aFont.pointSize(); - if (selectedSize == -1) - selectedSize = TQFontInfo(aFont).pointSize(); - - if( onlyFixed != usingFixed) - { - usingFixed = onlyFixed; - fillFamilyListBox(usingFixed); - } - setupDisplay(); - displaySample(selFont); -} - - -int TDEFontChooser::fontDiffFlags() { - int diffFlags = 0; - if (familyCheckbox && styleCheckbox && sizeCheckbox) { - diffFlags = (int)(familyCheckbox->isChecked() ? FontDiffFamily : 0) - | (int)( styleCheckbox->isChecked() ? FontDiffStyle : 0) - | (int)( sizeCheckbox->isChecked() ? FontDiffSize : 0); - } - return diffFlags; -} - -void TDEFontChooser::toggled_checkbox() -{ - familyListBox->setEnabled( familyCheckbox->isChecked() ); - styleListBox->setEnabled( styleCheckbox->isChecked() ); - sizeListBox->setEnabled( sizeCheckbox->isChecked() ); - sizeOfFont->setEnabled( sizeCheckbox->isChecked() ); -} - -void TDEFontChooser::family_chosen_slot(const TQString& family) -{ - TQFontDatabase dbase; - TQStringList styles = TQStringList(dbase.styles(family)); - styleListBox->clear(); - currentStyles.clear(); - for ( TQStringList::Iterator it = styles.begin(); it != styles.end(); ++it ) { - TQString style = *it; - int pos = style.find("Plain"); - if(pos >=0) style = style.replace(pos,5,i18n("Regular")); - pos = style.find("Normal"); - if(pos >=0) style = style.replace(pos,6,i18n("Regular")); - pos = style.find("Oblique"); - if(pos >=0) style = style.replace(pos,7,i18n("Italic")); - if(!styleListBox->findItem(style)) { - styleListBox->insertItem(i18n(style.utf8())); - currentStyles.insert(i18n(style.utf8()), *it); - } - } - if(styleListBox->count()==0) { - styleListBox->insertItem(i18n("Regular")); - currentStyles.insert(i18n("Regular"), "Normal"); - } - - styleListBox->blockSignals(true); - TQListBoxItem *item = styleListBox->findItem(selectedStyle); - if (item) - styleListBox->setSelected(styleListBox->findItem(selectedStyle), true); - else - styleListBox->setSelected(0, true); - styleListBox->blockSignals(false); - - style_chosen_slot(TQString::null); -} - -void TDEFontChooser::size_chosen_slot(const TQString& size){ - - selectedSize=size.toInt(); - sizeOfFont->setValue(selectedSize); - selFont.setPointSize(selectedSize); - emit fontSelected(selFont); -} - -void TDEFontChooser::size_value_slot(int val) { - selFont.setPointSize(val); - emit fontSelected(selFont); -} - -void TDEFontChooser::style_chosen_slot(const TQString& style) -{ - TQString currentStyle; - if (style.isEmpty()) - currentStyle = styleListBox->currentText(); - else - currentStyle = style; - - int diff=0; // the difference between the font size requested and what we can show. - - sizeListBox->clear(); - TQFontDatabase dbase; - if(dbase.isSmoothlyScalable(familyListBox->currentText(), currentStyles[currentStyle])) { // is vector font - //sampleEdit->setPaletteBackgroundPixmap( VectorPixmap ); // TODO - fillSizeList(); - } else { // is bitmap font. - //sampleEdit->setPaletteBackgroundPixmap( BitmapPixmap ); // TODO - TQValueList sizes = dbase.smoothSizes(familyListBox->currentText(), currentStyles[currentStyle]); - if(sizes.count() > 0) { - TQValueList::iterator it; - diff=1000; - for ( it = sizes.begin(); it != sizes.end(); ++it ) { - if(*it <= selectedSize || diff > *it - selectedSize) diff = selectedSize - *it; - sizeListBox->insertItem(TQString::number(*it)); - } - } else // there are times QT does not provide the list.. - fillSizeList(); - } - sizeListBox->blockSignals(true); - sizeListBox->setSelected(sizeListBox->findItem(TQString::number(selectedSize)), true); - sizeListBox->blockSignals(false); - sizeListBox->ensureCurrentVisible(); - - //kdDebug() << "Showing: " << familyListBox->currentText() << ", " << currentStyles[currentStyle] << ", " << selectedSize-diff << endl; - selFont = dbase.font(familyListBox->currentText(), currentStyles[currentStyle], selectedSize-diff); - emit fontSelected(selFont); - if (!style.isEmpty()) - selectedStyle = style; -} - -void TDEFontChooser::displaySample(const TQFont& font) -{ - sampleEdit->setFont(font); - sampleEdit->setCursorPosition(0); - xlfdEdit->setText(font.rawName()); - xlfdEdit->setCursorPosition(0); - - //TQFontInfo a = TQFontInfo(font); - //kdDebug() << "font: " << a.family () << ", " << a.pointSize () << endl; - //kdDebug() << " (" << font.toString() << ")\n"; -} - -void TDEFontChooser::setupDisplay() -{ - // Calling familyListBox->setCurrentItem() causes the value of selFont - // to change, so we save the family, style and size beforehand. - TQString family = TQString(selFont.family()).lower(); - int style = (selFont.bold() ? 2 : 0) + (selFont.italic() ? 1 : 0); - int size = selFont.pointSize(); - if (size == -1) - size = TQFontInfo(selFont).pointSize(); - TQString sizeStr = TQString::number(size); - - int numEntries, i; - - numEntries = familyListBox->count(); - for (i = 0; i < numEntries; i++) { - if (family == familyListBox->text(i).lower()) { - familyListBox->setCurrentItem(i); - break; - } - } - - // 1st Fallback - if ( (i == numEntries) ) - { - if (family.contains('[')) - { - family = family.left(family.find('[')).stripWhiteSpace(); - for (i = 0; i < numEntries; i++) { - if (family == familyListBox->text(i).lower()) { - familyListBox->setCurrentItem(i); - break; - } - } - } - } - - // 2nd Fallback - if ( (i == numEntries) ) - { - TQString fallback = family+" ["; - for (i = 0; i < numEntries; i++) { - if (familyListBox->text(i).lower().startsWith(fallback)) { - familyListBox->setCurrentItem(i); - break; - } - } - } - - // 3rd Fallback - if ( (i == numEntries) ) - { - for (i = 0; i < numEntries; i++) { - if (familyListBox->text(i).lower().startsWith(family)) { - familyListBox->setCurrentItem(i); - break; - } - } - } - - // Fall back in case nothing matched. Otherwise, diff doesn't work - if ( i == numEntries ) - familyListBox->setCurrentItem( 0 ); - - styleListBox->setCurrentItem(style); - - numEntries = sizeListBox->count(); - for (i = 0; i < numEntries; i++){ - if (sizeStr == sizeListBox->text(i)) { - sizeListBox->setCurrentItem(i); - break; - } - } - - sizeOfFont->setValue(size); -} - - -void TDEFontChooser::getFontList( TQStringList &list, uint fontListCriteria) -{ - TQFontDatabase dbase; - TQStringList lstSys(dbase.families()); - - // if we have criteria; then check fonts before adding - if (fontListCriteria) - { - TQStringList lstFonts; - for (TQStringList::Iterator it = lstSys.begin(); it != lstSys.end(); ++it) - { - if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(*it)) continue; - if (((fontListCriteria & (SmoothScalableFonts | ScalableFonts)) == ScalableFonts) && - !dbase.isBitmapScalable(*it)) continue; - if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(*it)) continue; - lstFonts.append(*it); - } - - if((fontListCriteria & FixedWidthFonts) > 0) { - // Fallback.. if there are no fixed fonts found, it's probably a - // bug in the font server or Qt. In this case, just use 'fixed' - if (lstFonts.count() == 0) - lstFonts.append("fixed"); - } - - lstSys = lstFonts; - } - - lstSys.sort(); - - list = lstSys; -} - -void TDEFontChooser::addFont( TQStringList &list, const char *xfont ) -{ - const char *ptr = strchr( xfont, '-' ); - if ( !ptr ) - return; - - ptr = strchr( ptr + 1, '-' ); - if ( !ptr ) - return; - - TQString font = TQString::fromLatin1(ptr + 1); - - int pos; - if ( ( pos = font.find( '-' ) ) > 0 ) { - font.truncate( pos ); - - if ( font.find( TQString::fromLatin1("open look"), 0, false ) >= 0 ) - return; - - TQStringList::Iterator it = list.begin(); - - for ( ; it != list.end(); ++it ) - if ( *it == font ) - return; - list.append( font ); - } -} - -void TDEFontChooser::fillFamilyListBox(bool onlyFixedFonts) -{ - TQStringList fontList; - getFontList(fontList, onlyFixedFonts?FixedWidthFonts:0); - familyListBox->clear(); - familyListBox->insertStringList(fontList); -} - -void TDEFontChooser::showXLFDArea(bool show) -{ - if( show ) - { - xlfdEdit->parentWidget()->show(); - } - else - { - xlfdEdit->parentWidget()->hide(); - } -} - -/////////////////////////////////////////////////////////////////////////////// - -TDEFontDialog::TDEFontDialog( TQWidget *parent, const char* name, - bool onlyFixed, bool modal, - const TQStringList &fontList, bool makeFrame, bool diff, - TQButton::ToggleState *sizeIsRelativeState ) - : KDialogBase( parent, name, modal, i18n("Select Font"), Ok|Cancel, Ok ) -{ - chooser = new TDEFontChooser( this, "fontChooser", - onlyFixed, fontList, makeFrame, 8, - diff, sizeIsRelativeState ); - setMainWidget(chooser); -} - - -int TDEFontDialog::getFontDiff( TQFont &theFont, int &diffFlags, bool onlyFixed, - TQWidget *parent, bool makeFrame, - TQButton::ToggleState *sizeIsRelativeState ) -{ - TDEFontDialog dlg( parent, "Font Selector", onlyFixed, true, TQStringList(), - makeFrame, true, sizeIsRelativeState ); - dlg.setFont( theFont, onlyFixed ); - - int result = dlg.exec(); - if( result == Accepted ) - { - theFont = dlg.chooser->font(); - diffFlags = dlg.chooser->fontDiffFlags(); - if( sizeIsRelativeState ) - *sizeIsRelativeState = dlg.chooser->sizeIsRelative(); - } - return result; -} - -int TDEFontDialog::getFont( TQFont &theFont, bool onlyFixed, - TQWidget *parent, bool makeFrame, - TQButton::ToggleState *sizeIsRelativeState ) -{ - TDEFontDialog dlg( parent, "Font Selector", onlyFixed, true, TQStringList(), - makeFrame, false, sizeIsRelativeState ); - dlg.setFont( theFont, onlyFixed ); - - int result = dlg.exec(); - if( result == Accepted ) - { - theFont = dlg.chooser->font(); - if( sizeIsRelativeState ) - *sizeIsRelativeState = dlg.chooser->sizeIsRelative(); - } - return result; -} - - -int TDEFontDialog::getFontAndText( TQFont &theFont, TQString &theString, - bool onlyFixed, TQWidget *parent, - bool makeFrame, - TQButton::ToggleState *sizeIsRelativeState ) -{ - TDEFontDialog dlg( parent, "Font and Text Selector", onlyFixed, true, - TQStringList(), makeFrame, false, sizeIsRelativeState ); - dlg.setFont( theFont, onlyFixed ); - - int result = dlg.exec(); - if( result == Accepted ) - { - theFont = dlg.chooser->font(); - theString = dlg.chooser->sampleText(); - if( sizeIsRelativeState ) - *sizeIsRelativeState = dlg.chooser->sizeIsRelative(); - } - return result; -} - -void TDEFontChooser::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -void TDEFontDialog::virtual_hook( int id, void* data ) -{ KDialogBase::virtual_hook( id, data ); } diff --git a/tdeui/kfontdialog.h b/tdeui/kfontdialog.h deleted file mode 100644 index cce427eba..000000000 --- a/tdeui/kfontdialog.h +++ /dev/null @@ -1,504 +0,0 @@ -/* - $Id$ - - Requires the Qt widget libraries, available at no cost at - http://www.troll.no - - Copyright (C) 1997 Bernd Johannes Wuebben - Copyright (c) 1999 Preston Brown - Copyright (c) 1999 Mario Weilguni - - This library 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. - - 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 _K_FONT_DIALOG_H_ -#define _K_FONT_DIALOG_H_ - -#include -#include -#include - -class TQComboBox; -class TQCheckBox; -class TQFont; -class TQGroupBox; -class TQLabel; -class TQStringList; -class TDEListBox; -class KIntNumInput; -/** - * @short A font selection widget. - * - * While TDEFontChooser as an ordinary widget can be embedded in - * custom dialogs and therefore is very flexible, in most cases - * it is preferable to use the convenience functions in - * TDEFontDialog. - * - * \image html kfontchooser.png "KDE Font Chooser" - * - * @author Preston Brown , Bernd Wuebben - * @version $Id$ - */ -class TDEUI_EXPORT TDEFontChooser : public TQWidget -{ - Q_OBJECT - TQ_PROPERTY( TQFont font READ font WRITE setFont ) - -public: - /** - * @li @p FamilyList - Identifies the family (leftmost) list. - * @li @p StyleList - Identifies the style (center) list. - * @li @p SizeList - Identifies the size (rightmost) list. - */ - enum FontColumn { FamilyList=0x01, StyleList=0x02, SizeList=0x04}; - - /** - * @li @p FontDiffFamily - Identifies a requested change in the font family. - * @li @p FontDiffStyle - Identifies a requested change in the font style. - * @li @p FontDiffSize - Identifies a requested change in the font size. - */ - enum FontDiff { FontDiffFamily=0x01, FontDiffStyle=0x02, FontDiffSize=0x04 }; - - /** - * Constructs a font picker widget. - * It normally comes up with all font families present on the system; the - * getFont method below does allow some more fine-tuning of the selection of fonts - * that will be displayed in the dialog. - *

Consider the following code snippet; - * \code - * TQStringList list; - * TDEFontChooser::getFontList(list,SmoothScalableFonts); - * TDEFontChooser chooseFont = new TDEFontChooser(0, "FontList", false, list); - * \endcode - *

- * The above creates a font chooser dialog with only SmoothScaleble fonts. - * - * @param parent The parent widget. - * @param name The widget name. - * @param onlyFixed Only display fonts which have fixed-width - * character sizes. - * @param fontList A list of fonts to display, in XLFD format. If - * no list is formatted, the internal KDE font list is used. - * If that has not been created, X is queried, and all fonts - * available on the system are displayed. - * @param diff Display the difference version dialog. - * See TDEFontDialog::getFontDiff(). - * @param makeFrame Draws a frame with titles around the contents. - * @param visibleListSize The minimum number of visible entries in the - * fontlists. - * @param sizeIsRelativeState If not zero the widget will show a - * checkbox where the user may choose whether the font size - * is to be interpreted as relative size. - * Initial state of this checkbox will be set according to - * *sizeIsRelativeState, user choice may be retrieved by - * calling sizeIsRelative(). - */ - TDEFontChooser(TQWidget *parent = 0L, const char *name = 0L, - bool onlyFixed = false, - const TQStringList &fontList = TQStringList(), - bool makeFrame = true, int visibleListSize=8, - bool diff = false, TQButton::ToggleState *sizeIsRelativeState = 0L ); - - /** - * Destructs the font chooser. - */ - virtual ~TDEFontChooser(); - - /** - * Enables or disable a font column in the chooser. - * - * Use this - * function if your application does not need or supports all font - * properties. - * - * @param column Specify the columns. An or'ed combination of - * @p FamilyList, @p StyleList and @p SizeList is possible. - * @param state If @p false the columns are disabled. - */ - void enableColumn( int column, bool state ); - - /** - * Sets the currently selected font in the chooser. - * - * @param font The font to select. - * @param onlyFixed Readjust the font list to display only fixed - * width fonts if @p true, or vice-versa. - */ - void setFont( const TQFont &font, bool onlyFixed = false ); - - /** - * @return The bitmask corresponding to the attributes the user - * wishes to change. - */ - int fontDiffFlags(); - - /** - * @return The currently selected font in the chooser. - */ - TQFont font() const { return selFont; } - - /** - * Sets the color to use in the preview. - */ - void setColor( const TQColor & col ); - - /** - * @return The color currently used in the preview (default: the text - * color of the active color group) - */ - TQColor color() const; - - /** - * Sets the background color to use in the preview. - */ - void setBackgroundColor( const TQColor & col ); - - /** - * @return The background color currently used in the preview (default: - * the base color of the active colorgroup) - */ - TQColor backgroundColor() const; - - /** - * Sets the state of the checkbox indicating whether the font size - * is to be interpreted as relative size. - * NOTE: If parameter sizeIsRelative was not set in the constructor - * of the widget this setting will be ignored. - */ - void setSizeIsRelative( TQButton::ToggleState relative ); - - /** - * @return Whether the font size is to be interpreted as relative size - * (default: TQButton:Off) - */ - TQButton::ToggleState sizeIsRelative() const; - - - /** - * @return The current text in the sample text input area. - */ - TQString sampleText() const { return sampleEdit->text(); } - - /** - * Sets the sample text. - * - * Normally you should not change this - * text, but it can be better to do this if the default text is - * too large for the edit area when using the default font of your - * application. - * - * @param text The new sample text. The current will be removed. - */ - void setSampleText( const TQString &text ) - { - sampleEdit->setText( text ); - } - - /** - * Shows or hides the sample text box. - * - * @param visible Set it to true to show the box, to false to hide it. - * @since 3.5 - */ - void setSampleBoxVisible( bool visible ) - { - sampleEdit->setShown( visible ); - } - - /** - * Converts a TQFont into the corresponding X Logical Font - * Description (XLFD). - * - * @param theFont The font to convert. - * @return A string representing the given font in XLFD format. - */ - static TQString getXLFD( const TQFont &theFont ) - { return theFont.rawName(); } - - /** - * The selection criteria for the font families shown in the dialog. - * @li @p FixedWidthFont when included only fixed-width fonts are returned. - * The fonts where the width of every character is equal. - * @li @p ScalableFont when included only scalable fonts are returned; - * certain configurations allow bitmap fonts to remain unscaled and - * thus these fonts have limited number of sizes. - * @li @p SmoothScalableFont when included only return smooth scalable fonts. - * this will return only non-bitmap fonts which are scalable to any size requested. - * Setting this option to true will mean the "scalable" flag is irrelavant. - */ - enum FontListCriteria { FixedWidthFonts=0x01, ScalableFonts=0x02, SmoothScalableFonts=0x04 }; - - /** - * Creates a list of font strings. - * - * @param list The list is returned here. - * @param fontListCriteria should contain all the restrictions for font selection as OR-ed values - * @see TDEFontChooser::FontListCriteria for the individual values - */ - static void getFontList( TQStringList &list, uint fontListCriteria); - - /** - * Reimplemented for internal reasons. - */ - virtual TQSize sizeHint( void ) const; - -signals: - /** - * Emitted whenever the selected font changes. - */ - void fontSelected( const TQFont &font ); - -private slots: - void toggled_checkbox(); - void family_chosen_slot(const TQString&); - void size_chosen_slot(const TQString&); - void style_chosen_slot(const TQString&); - void displaySample(const TQFont &font); - void showXLFDArea(bool); - void size_value_slot(int); -private: - void fillFamilyListBox(bool onlyFixedFonts = false); - void fillSizeList(); - // This one must be static since getFontList( TQStringList, char*) is so - static void addFont( TQStringList &list, const char *xfont ); - - void setupDisplay(); - - // pointer to an optinally supplied list of fonts to - // inserted into the fontdialog font-family combo-box - TQStringList fontList; - - KIntNumInput *sizeOfFont; - - TQLineEdit *sampleEdit; - TQLineEdit *xlfdEdit; - - TQLabel *familyLabel; - TQLabel *styleLabel; - TQCheckBox *familyCheckbox; - TQCheckBox *styleCheckbox; - TQCheckBox *sizeCheckbox; - TQLabel *sizeLabel; - TDEListBox *familyListBox; - TDEListBox *styleListBox; - TDEListBox *sizeListBox; - TQComboBox *charsetsCombo; // BIC: remove in KDE4 - TQCheckBox *sizeIsRelativeCheckBox; - - TQFont selFont; - - TQString selectedStyle; - int selectedSize; - TQMap currentStyles; - - bool usingFixed; - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEFontChooserPrivate; - TDEFontChooserPrivate *d; -}; - -/** - * @short A font selection dialog. - * - * The TDEFontDialog provides a dialog for interactive font selection. - * It is basically a thin wrapper around the TDEFontChooser widget, - * which can also be used standalone. In most cases, the simplest - * use of this class is the static method TDEFontDialog::getFont(), - * which pops up the dialog, allows the user to select a font, and - * returns when the dialog is closed. - * - * Example: - * - * \code - * TQFont myFont; - * int result = TDEFontDialog::getFont( myFont ); - * if ( result == TDEFontDialog::Accepted ) - * ... - * \endcode - * - * \image html kfontdialog.png "KDE Font Dialog" - * - * @author Preston Brown , Bernd Wuebben - * @version $Id$ - */ -class TDEUI_EXPORT TDEFontDialog : public KDialogBase { - Q_OBJECT - -public: - /** - * Constructs a font selection dialog. - * - * @param parent The parent widget of the dialog, if any. - * @param name The name of the dialog. - * @param modal Specifies whether the dialog is modal or not. - * @param onlyFixed only display fonts which have fixed-width - * character sizes. - * @param fontlist a list of fonts to display, in XLFD format. If - * no list is formatted, the internal KDE font list is used. - * If that has not been created, X is queried, and all fonts - * available on the system are displayed. - * @param makeFrame Draws a frame with titles around the contents. - * @param diff Display the difference version dialog. See getFontDiff(). - * @param sizeIsRelativeState If not zero the widget will show a - * checkbox where the user may choose whether the font size - * is to be interpreted as relative size. - * Initial state of this checkbox will be set according to - * *sizeIsRelativeState, user choice may be retrieved by - * calling sizeIsRelative(). - * - */ - TDEFontDialog( TQWidget *parent = 0L, const char *name = 0, - bool onlyFixed = false, bool modal = false, - const TQStringList &fontlist = TQStringList(), - bool makeFrame = true, bool diff = false, - TQButton::ToggleState *sizeIsRelativeState = 0L ); - - /** - * Sets the currently selected font in the dialog. - * - * @param font The font to select. - * @param onlyFixed readjust the font list to display only fixed - * width fonts if true, or vice-versa - */ - void setFont( const TQFont &font, bool onlyFixed = false ) - { chooser->setFont(font, onlyFixed); } - - /** - * @return The currently selected font in the dialog. - */ - TQFont font() const { return chooser->font(); } - - /** - * Sets the state of the checkbox indicating whether the font size - * is to be interpreted as relative size. - * NOTE: If parameter sizeIsRelative was not set in the constructor - * of the dialog this setting will be ignored. - */ - void setSizeIsRelative( TQButton::ToggleState relative ) - { chooser->setSizeIsRelative( relative ); } - - /** - * @return Whether the font size is to be interpreted as relative size - * (default: false) - */ - TQButton::ToggleState sizeIsRelative() const - { return chooser->sizeIsRelative(); } - - /** - * Creates a modal font dialog, lets the user choose a font, - * and returns when the dialog is closed. - * - * @param theFont a reference to the font to write the chosen font - * into. - * @param onlyFixed if true, only select from fixed-width fonts. - * @param parent Parent widget of the dialog. Specifying a widget different - * from 0 (Null) improves centering (looks better). - * @param makeFrame Draws a frame with titles around the contents. - * @param sizeIsRelativeState If not zero the widget will show a - * checkbox where the user may choose whether the font size - * is to be interpreted as relative size. - * Initial state of this checkbox will be set according to - * *sizeIsRelativeState and user choice will be returned - * therein. - * - * @return TQDialog::result(). - */ - static int getFont( TQFont &theFont, bool onlyFixed = false, - TQWidget *parent = 0L, bool makeFrame = true, - TQButton::ToggleState *sizeIsRelativeState = 0L ); - - /** - * Creates a modal font difference dialog, lets the user choose a selection - * of changes that should be made to a set of fonts, and returns when the - * dialog is closed. Useful for choosing slight adjustments to the font set - * when the user would otherwise have to manually edit a number of fonts. - * - * @param theFont a reference to the font to write the chosen font - * into. - * @param diffFlags a reference to the int into which the chosen - * difference selection bitmask should be written. - * Check the returned bitmask like: - * \code - * if ( diffFlags & TDEFontChooser::FontDiffFamily ) - * [...] - * if ( diffFlags & TDEFontChooser::FontDiffStyle ) - * [...] - * if ( diffFlags & TDEFontChooser::FontDiffSize ) - * [...] - * \endcode - * @param onlyFixed if true, only select from fixed-width fonts. - * @param parent Parent widget of the dialog. Specifying a widget different - * from 0 (Null) improves centering (looks better). - * @param makeFrame Draws a frame with titles around the contents. - * @param sizeIsRelativeState If not zero the widget will show a - * checkbox where the user may choose whether the font size - * is to be interpreted as relative size. - * Initial state of this checkbox will be set according to - * *sizeIsRelativeState and user choice will be returned - * therein. - * - * @returns TQDialog::result(). - */ - static int getFontDiff( TQFont &theFont, int &diffFlags, bool onlyFixed = false, - TQWidget *parent = 0L, bool makeFrame = true, - TQButton::ToggleState *sizeIsRelativeState = 0L ); - - /** - * When you are not only interested in the font selected, but also - * in the example string typed in, you can call this method. - * - * @param theFont a reference to the font to write the chosen font - * into. - * @param theString a reference to the example text that was typed. - * @param onlyFixed if true, only select from fixed-width fonts. - * @param parent Parent widget of the dialog. Specifying a widget different - * from 0 (Null) improves centering (looks better). - * @param makeFrame Draws a frame with titles around the contents. - * @param sizeIsRelativeState If not zero the widget will show a - * checkbox where the user may choose whether the font size - * is to be interpreted as relative size. - * Initial state of this checkbox will be set according to - * *sizeIsRelativeState and user choice will be returned - * therein. - * @return The result of the dialog. - */ - static int getFontAndText( TQFont &theFont, TQString &theString, - bool onlyFixed = false, TQWidget *parent = 0L, - bool makeFrame = true, - TQButton::ToggleState *sizeIsRelativeState = 0L ); - -signals: - /** - * Emitted whenever the currently selected font changes. - * Connect to this to monitor the font as it is selected if you are - * not running modal. - */ - void fontSelected( const TQFont &font ); - -protected: - TDEFontChooser *chooser; - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEFontDialogPrivate; - TDEFontDialogPrivate *d; - -}; - -#endif diff --git a/tdeui/kfontrequester.cpp b/tdeui/kfontrequester.cpp deleted file mode 100644 index 8ae0d705d..000000000 --- a/tdeui/kfontrequester.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - Copyright (C) 2003 Nadeem Hasan - - This library 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. - - 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. -*/ - -#include "kfontrequester.h" - -#include -#include -#include -#include -#include - -#include -#include - -TDEFontRequester::TDEFontRequester( TQWidget *parent, const char *name, - bool onlyFixed ) : TQWidget( parent, name ), - m_onlyFixed( onlyFixed ) -{ - TQHBoxLayout *layout = new TQHBoxLayout( this, 0, KDialog::spacingHint() ); - - m_sampleLabel = new TQLabel( this, "m_sampleLabel" ); - m_button = new TQPushButton( i18n( "Choose..." ), this, "m_button" ); - - m_sampleLabel->setFrameStyle( TQFrame::StyledPanel | TQFrame::Sunken ); - setFocusProxy( m_button ); - - layout->addWidget( m_sampleLabel, 1 ); - layout->addWidget( m_button ); - - connect( m_button, TQT_SIGNAL( clicked() ), TQT_SLOT( buttonClicked() ) ); - - displaySampleText(); - setToolTip(); -} - -void TDEFontRequester::setFont( const TQFont &font, bool onlyFixed ) -{ - m_selFont = font; - m_onlyFixed = onlyFixed; - - displaySampleText(); - emit fontSelected( m_selFont ); -} - -void TDEFontRequester::setSampleText( const TQString &text ) -{ - m_sampleText = text; - displaySampleText(); -} - -void TDEFontRequester::setTitle( const TQString &title ) -{ - m_title = title; - setToolTip(); -} - -void TDEFontRequester::buttonClicked() -{ - int result = TDEFontDialog::getFont( m_selFont, m_onlyFixed, parentWidget() ); - - if ( result == KDialog::Accepted ) - { - displaySampleText(); - emit fontSelected( m_selFont ); - } -} - -void TDEFontRequester::displaySampleText() -{ - m_sampleLabel->setFont( m_selFont ); - - int size = m_selFont.pointSize(); - if(size == -1) - size = m_selFont.pixelSize(); - - if ( m_sampleText.isEmpty() ) - m_sampleLabel->setText( TQString( "%1 %2" ).arg( m_selFont.family() ) - .arg( size ) ); - else - m_sampleLabel->setText( m_sampleText ); -} - -void TDEFontRequester::setToolTip() -{ - TQToolTip::remove( m_button ); - TQToolTip::add( m_button, i18n( "Click to select a font" ) ); - - TQToolTip::remove( m_sampleLabel ); - TQWhatsThis::remove( m_sampleLabel ); - - if ( m_title.isNull() ) - { - TQToolTip::add( m_sampleLabel, i18n( "Preview of the selected font" ) ); - TQWhatsThis::add( m_sampleLabel, - i18n( "This is a preview of the selected font. You can change it" - " by clicking the \"Choose...\" button." ) ); - } - else - { - TQToolTip::add( m_sampleLabel, - i18n( "Preview of the \"%1\" font" ).arg( m_title ) ); - TQWhatsThis::add( m_sampleLabel, - i18n( "This is a preview of the \"%1\" font. You can change it" - " by clicking the \"Choose...\" button." ).arg( m_title ) ); - } -} - -#include "kfontrequester.moc" - -/* vim: et sw=2 ts=2 -*/ diff --git a/tdeui/kfontrequester.h b/tdeui/kfontrequester.h deleted file mode 100644 index b686cf178..000000000 --- a/tdeui/kfontrequester.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - Copyright (C) 2003 Nadeem Hasan - - This library 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. - - 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 KFONTREQUESTER_H -#define KFONTREQUESTER_H - -#include -#include -#include - -#include - -class TQLabel; -class TQPushButton; - -/** - * This class provides a widget with a lineedit and a button, which invokes - * a font dialog (TDEFontDialog). - * - * The lineedit provides a preview of the selected font. The preview text can - * be customized. You can also have the font dialog show only the fixed fonts. - * - * \image html kfontrequester.png "KDE Font Requester" - * - * @author Nadeem Hasan - * - */ -class TDEUI_EXPORT TDEFontRequester : public TQWidget -{ - Q_OBJECT - - TQ_PROPERTY( TQString title READ title WRITE setTitle ) - TQ_PROPERTY( TQString sampleText READ sampleText WRITE setSampleText ) - TQ_PROPERTY( TQFont font READ font WRITE setFont ) - - public: - - /** - * Constructs a font requester widget. - * - * @param parent The parent widget. - * @param name The widget name. - * @param onlyFixed Only display fonts which have fixed-width character - * sizes. - */ - TDEFontRequester( TQWidget *parent=0L, const char *name=0L, - bool onlyFixed=false ); - - /** - * @return The currently selected font in the requester. - */ - TQFont font() const { return m_selFont; } - - /** - * @return Returns true if only fixed fonts are displayed. - */ - bool isFixedOnly() const { return m_onlyFixed; } - - /** - * @return The current text in the sample text input area. - */ - TQString sampleText() const { return m_sampleText; } - - /** - * @return The current title of the widget. - */ - TQString title() const { return m_title; } - - /** - * @return Pointer to the label used for preview. - */ - TQLabel *label() const { return m_sampleLabel; } - - /** - * @return Pointer to the pushbutton in the widget. - */ - TQPushButton *button() const { return m_button; } - - /** - * Sets the currently selected font in the requester. - * - * @param font The font to select. - * @param onlyFixed Display only fixed-width fonts in the font dialog - * if @p true, or vice-versa. - */ - virtual void setFont( const TQFont &font, bool onlyFixed=false ); - - /** - * Sets the sample text. - * - * Normally you should not change this - * text, but it can be better to do this if the default text is - * too large for the edit area when using the default font of your - * application. Default text is current font name and size. Setting - * the text to TQString::null will restore the default. - * - * @param text The new sample text. The current will be removed. - */ - virtual void setSampleText( const TQString &text ); - - /** - * Set the title for the widget that will be used in the tooltip and - * what's this text. - * - * @param title The title to be set. - */ - virtual void setTitle( const TQString & title ); - - signals: - /** - * Emitted when a new @p font has been selected in the underlying dialog - */ - void fontSelected( const TQFont &font ); - - protected: - - void displaySampleText(); - void setToolTip(); - - protected slots: - - virtual void buttonClicked(); - - protected: - - bool m_onlyFixed; - TQString m_sampleText, m_title; - TQLabel *m_sampleLabel; - TQPushButton *m_button; - TQFont m_selFont; - - private: - - class TDEFontRequesterPrivate; - TDEFontRequesterPrivate *d; -}; - -#endif // KFONTREQUESTER_H - -/* vim: et sw=2 ts=2 -*/ diff --git a/tdeui/klistbox.cpp b/tdeui/klistbox.cpp deleted file mode 100644 index bc31f020d..000000000 --- a/tdeui/klistbox.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2000 Reginald Stadlbauer - - 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. -*/ -#include "config.h" - -#include - -#include -#include -#include -#include -#include - -#include "klistbox.h" - -TDEListBox::TDEListBox( TQWidget *parent, const char *name, WFlags f ) - : TQListBox( parent, name, f ), d(0) -{ - connect( this, TQT_SIGNAL( onViewport() ), - this, TQT_SLOT( slotOnViewport() ) ); - connect( this, TQT_SIGNAL( onItem( TQListBoxItem * ) ), - this, TQT_SLOT( slotOnItem( TQListBoxItem * ) ) ); - slotSettingsChanged(TDEApplication::SETTINGS_MOUSE); - if (kapp) - { - connect( kapp, TQT_SIGNAL( settingsChanged(int) ), TQT_SLOT( slotSettingsChanged(int) ) ); - kapp->addKipcEventMask( KIPC::SettingsChanged ); - } - - m_pCurrentItem = 0L; - - m_pAutoSelect = new TQTimer( this ); - connect( m_pAutoSelect, TQT_SIGNAL( timeout() ), - this, TQT_SLOT( slotAutoSelect() ) ); -} - -void TDEListBox::slotOnItem( TQListBoxItem *item ) -{ - if ( item && m_bChangeCursorOverItem && m_bUseSingle ) - viewport()->setCursor( KCursor().handCursor() ); - - if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) { - m_pAutoSelect->start( m_autoSelectDelay, true ); - m_pCurrentItem = item; - } -} - -void TDEListBox::slotOnViewport() -{ - if ( m_bChangeCursorOverItem ) - viewport()->unsetCursor(); - - m_pAutoSelect->stop(); - m_pCurrentItem = 0L; -} - - -void TDEListBox::slotSettingsChanged(int category) -{ - if (category != TDEApplication::SETTINGS_MOUSE) - return; - m_bUseSingle = TDEGlobalSettings::singleClick(); - - disconnect( this, TQT_SIGNAL( mouseButtonClicked( int, TQListBoxItem *, - const TQPoint & ) ), - this, TQT_SLOT( slotMouseButtonClicked( int, TQListBoxItem *, - const TQPoint & ) ) ); -// disconnect( this, TQT_SIGNAL( doubleClicked( TQListBoxItem *, -// const TQPoint & ) ), -// this, TQT_SLOT( slotExecute( TQListBoxItem *, -// const TQPoint & ) ) ); - - if( m_bUseSingle ) - { - connect( this, TQT_SIGNAL( mouseButtonClicked( int, TQListBoxItem *, - const TQPoint & ) ), - this, TQT_SLOT( slotMouseButtonClicked( int, TQListBoxItem *, - const TQPoint & ) ) ); - } - else - { -// connect( this, TQT_SIGNAL( doubleClicked( TQListBoxItem *, -// const TQPoint & ) ), -// this, TQT_SLOT( slotExecute( TQListBoxItem *, -// const TQPoint & ) ) ); - } - - m_bChangeCursorOverItem = TDEGlobalSettings::changeCursorOverIcon(); - m_autoSelectDelay = TDEGlobalSettings::autoSelectDelay(); - - if( !m_bUseSingle || !m_bChangeCursorOverItem ) - viewport()->unsetCursor(); -} - -void TDEListBox::slotAutoSelect() -{ - // check that the item still exists - if( index( m_pCurrentItem ) == -1 ) - return; - - //Give this widget the keyboard focus. - if( !hasFocus() ) - setFocus(); - - ButtonState keybstate = TDEApplication::keyboardMouseState(); - - TQListBoxItem* previousItem = item( currentItem() ); - setCurrentItem( m_pCurrentItem ); - - if( m_pCurrentItem ) { - //Shift pressed? - if( (keybstate & ShiftButton) ) { - bool block = signalsBlocked(); - blockSignals( true ); - - //No Ctrl? Then clear before! - if( !(keybstate & ControlButton) ) - clearSelection(); - - bool select = !m_pCurrentItem->isSelected(); - bool update = viewport()->isUpdatesEnabled(); - viewport()->setUpdatesEnabled( false ); - - bool down = index( previousItem ) < index( m_pCurrentItem ); - TQListBoxItem* it = down ? previousItem : m_pCurrentItem; - for (;it ; it = it->next() ) { - if ( down && it == m_pCurrentItem ) { - setSelected( m_pCurrentItem, select ); - break; - } - if ( !down && it == previousItem ) { - setSelected( previousItem, select ); - break; - } - setSelected( it, select ); - } - - blockSignals( block ); - viewport()->setUpdatesEnabled( update ); - triggerUpdate( false ); - - emit selectionChanged(); - - if( selectionMode() == TQListBox::Single ) - emit selectionChanged( m_pCurrentItem ); - } - else if( (keybstate & ControlButton) ) - setSelected( m_pCurrentItem, !m_pCurrentItem->isSelected() ); - else { - bool block = signalsBlocked(); - blockSignals( true ); - - if( !m_pCurrentItem->isSelected() ) - clearSelection(); - - blockSignals( block ); - - setSelected( m_pCurrentItem, true ); - } - } - else - kdDebug() << "That´s not supposed to happen!!!!" << endl; -} - -void TDEListBox::emitExecute( TQListBoxItem *item, const TQPoint &pos ) -{ - ButtonState keybstate = TDEApplication::keyboardMouseState(); - - m_pAutoSelect->stop(); - - //Don´t emit executed if in SC mode and Shift or Ctrl are pressed - if( !( m_bUseSingle && ((keybstate & ShiftButton) || (keybstate & ControlButton)) ) ) { - emit executed( item ); - emit executed( item, pos ); - } -} - -// -// 2000-16-01 Espen Sand -// This widget is used in dialogs. It should ignore -// F1 (and combinations) and Escape since these are used -// to start help or close the dialog. This functionality -// should be done in TQListView but it is not (at least now) -// -void TDEListBox::keyPressEvent(TQKeyEvent *e) -{ - if( e->key() == Key_Escape ) - { - e->ignore(); - } - else if( e->key() == Key_F1 ) - { - e->ignore(); - } - else - { - TQListBox::keyPressEvent(e); - } -} - -void TDEListBox::focusOutEvent( TQFocusEvent *fe ) -{ - m_pAutoSelect->stop(); - - TQListBox::focusOutEvent( fe ); -} - -void TDEListBox::leaveEvent( TQEvent *e ) -{ - m_pAutoSelect->stop(); - - TQListBox::leaveEvent( e ); -} - -void TDEListBox::contentsMousePressEvent( TQMouseEvent *e ) -{ - if( (selectionMode() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) { - bool block = signalsBlocked(); - blockSignals( true ); - - clearSelection(); - - blockSignals( block ); - } - - TQListBox::contentsMousePressEvent( e ); -} - -void TDEListBox::contentsMouseDoubleClickEvent ( TQMouseEvent * e ) -{ - TQListBox::contentsMouseDoubleClickEvent( e ); - - TQListBoxItem* item = itemAt( contentsToViewport( e->pos() ) ); - - if( item ) { - emit doubleClicked( item, e->globalPos() ); - - if( (e->button() == Qt::LeftButton) && !m_bUseSingle ) - emitExecute( item, e->globalPos() ); - } -} - -void TDEListBox::slotMouseButtonClicked( int btn, TQListBoxItem *item, const TQPoint &pos ) -{ - if( (btn == Qt::LeftButton) && item ) - emitExecute( item, pos ); -} - -void TDEListBox::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -#include "klistbox.moc" diff --git a/tdeui/klistbox.h b/tdeui/klistbox.h deleted file mode 100644 index 8ef949527..000000000 --- a/tdeui/klistbox.h +++ /dev/null @@ -1,128 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2000 Reginald Stadlbauer - - 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 KLISTBOX_H -#define KLISTBOX_H - -#include - -#include - -/** - * @short A variant of TQListBox that honors KDE's system-wide settings. - * - * Extends the functionality of TQListBox to honor the system - * wide settings for Single Click/Double Click mode, Auto Selection and - * Change Cursor over Link. - * - * There is a new signal executed(). It gets connected to either - * TQListBox::clicked() or TQListBox::doubleClicked() - * depending on the KDE wide Single Click/Double Click settings. It is - * strongly recommended that you use this signal instead of the above - * mentioned. This way you don't need to care about the current - * settings. If you want to get informed when the user selects - * something connect to the TQListBox::selectionChanged() signal. - **/ -class TDEUI_EXPORT TDEListBox : public TQListBox -{ - Q_OBJECT - -public: - TDEListBox( TQWidget *parent = 0, const char *name = 0, WFlags f = 0 ); - -signals: - - /** - * Emitted whenever the user executes an listbox item. - * - * That means depending on the KDE wide Single Click/Double Click - * setting the user clicked or double clicked on that item. - * @param item is the pointer to the executed listbox item. - * - * Note that you may not delete any TQListBoxItem objects in slots - * connected to this signal. - */ - void executed( TQListBoxItem *item ); - - /** - * Emitted whenever the user executes an listbox item. - * - * That means depending on the KDE wide Single Click/Double Click - * setting the user clicked or double clicked on that item. - * @param item is the pointer to the executed listbox item. - * @param pos is the position where the user has clicked - * - * Note that you may not delete any TQListBoxItem objects in slots - * connected to this signal. - */ - void executed( TQListBoxItem *item, const TQPoint &pos ); - - /** - * This signal gets emitted whenever the user double clicks into the - * listbox. - * - * @param item The pointer to the clicked listbox item. - * @param pos The position where the user has clicked. - * - * Note that you may not delete any TQListBoxItem objects in slots - * connected to this signal. - * - * This signal is more or less here for the sake of completeness. - * You should normally not need to use this. In most cases it's better - * to use executed() instead. - */ - void doubleClicked( TQListBoxItem *item, const TQPoint &pos ); - -protected slots: - void slotOnItem( TQListBoxItem *item ); - void slotOnViewport(); - - void slotSettingsChanged(int); - - /** - * Auto selection happend. - */ - void slotAutoSelect(); - -protected: - void emitExecute( TQListBoxItem *item, const TQPoint &pos ); - - virtual void keyPressEvent(TQKeyEvent *e); - virtual void focusOutEvent( TQFocusEvent *fe ); - virtual void leaveEvent( TQEvent *e ); - virtual void contentsMousePressEvent( TQMouseEvent *e ); - virtual void contentsMouseDoubleClickEvent ( TQMouseEvent *e ); - - bool m_bUseSingle; - bool m_bChangeCursorOverItem; - - TQListBoxItem* m_pCurrentItem; - - TQTimer* m_pAutoSelect; - int m_autoSelectDelay; - -private slots: - void slotMouseButtonClicked( int btn, TQListBoxItem *item, const TQPoint &pos ); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEListBoxPrivate; - TDEListBoxPrivate* const d; -}; - -#endif diff --git a/tdeui/klistview.cpp b/tdeui/klistview.cpp deleted file mode 100644 index b3eb2222c..000000000 --- a/tdeui/klistview.cpp +++ /dev/null @@ -1,2411 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2000 Reginald Stadlbauer - Copyright (C) 2000,2003 Charles Samuels - Copyright (C) 2000 Peter Putzer - - 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. -*/ -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "klistview.h" -#include "klistviewlineedit.h" - -class TDEListView::Tooltip : public TQToolTip -{ -public: - Tooltip (TDEListView* parent, TQToolTipGroup* group = 0L); - virtual ~Tooltip () {} - -protected: - /** - * Reimplemented from TQToolTip for internal reasons. - */ - virtual void maybeTip (const TQPoint&); - -private: - TDEListView* mParent; -}; - -TDEListView::Tooltip::Tooltip (TDEListView* parent, TQToolTipGroup* group) - : TQToolTip (parent, group), - mParent (parent) -{ -} - -void TDEListView::Tooltip::maybeTip (const TQPoint&) -{ - // FIXME -} - -class TDEListView::TDEListViewPrivate -{ -public: - TDEListViewPrivate (TDEListView* listview) - : pCurrentItem (0), - autoSelectDelay(0), - dragOverItem(0), - dragDelay (TDEGlobalSettings::dndEventDelay()), - editor (new TDEListViewLineEdit (listview)), - cursorInExecuteArea(false), - itemsMovable (true), - selectedBySimpleMove(false), - selectedUsingMouse(false), - itemsRenameable (false), - validDrag (false), - dragEnabled (false), - autoOpen (true), - disableAutoSelection (false), - dropVisualizer (true), - dropHighlighter (false), - createChildren (true), - pressedOnSelected (false), - wasShiftEvent (false), - fullWidth (false), - sortAscending(true), - tabRename(true), - sortColumn(0), - selectionDirection(0), - tooltipColumn (0), - selectionMode (Single), - contextMenuKey (TDEGlobalSettings::contextMenuKey()), - showContextMenusOnPress (TDEGlobalSettings::showContextMenusOnPress()), - mDropVisualizerWidth (4), - paintAbove (0), - paintCurrent (0), - paintBelow (0), - painting (false), - shadeSortColumn(TDEGlobalSettings::shadeSortColumn()) - { - renameable.append(0); - connect(editor, TQT_SIGNAL(done(TQListViewItem*,int)), listview, TQT_SLOT(doneEditing(TQListViewItem*,int))); - } - - ~TDEListViewPrivate () - { - delete editor; - } - - TQListViewItem* pCurrentItem; - - TQTimer autoSelect; - int autoSelectDelay; - - TQTimer dragExpand; - TQListViewItem* dragOverItem; - TQPoint dragOverPoint; - - TQPoint startDragPos; - int dragDelay; - - TDEListViewLineEdit *editor; - TQValueList renameable; - - bool cursorInExecuteArea:1; - bool bUseSingle:1; - bool bChangeCursorOverItem:1; - bool itemsMovable:1; - bool selectedBySimpleMove : 1; - bool selectedUsingMouse:1; - bool itemsRenameable:1; - bool validDrag:1; - bool dragEnabled:1; - bool autoOpen:1; - bool disableAutoSelection:1; - bool dropVisualizer:1; - bool dropHighlighter:1; - bool createChildren:1; - bool pressedOnSelected:1; - bool wasShiftEvent:1; - bool fullWidth:1; - bool sortAscending:1; - bool tabRename:1; - - int sortColumn; - - //+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX - int selectionDirection; - int tooltipColumn; - - SelectionModeExt selectionMode; - int contextMenuKey; - bool showContextMenusOnPress; - - TQRect mOldDropVisualizer; - int mDropVisualizerWidth; - TQRect mOldDropHighlighter; - TQListViewItem *afterItemDrop; - TQListViewItem *parentItemDrop; - - TQListViewItem *paintAbove; - TQListViewItem *paintCurrent; - TQListViewItem *paintBelow; - bool painting:1; - bool shadeSortColumn:1; - - TQColor alternateBackground; -}; - - -TDEListViewLineEdit::TDEListViewLineEdit(TDEListView *parent) - : KLineEdit(parent->viewport()), item(0), col(0), p(parent) -{ - setFrame( false ); - hide(); - connect( parent, TQT_SIGNAL( selectionChanged() ), TQT_SLOT( slotSelectionChanged() )); - connect( parent, TQT_SIGNAL( itemRemoved( TQListViewItem * ) ), - TQT_SLOT( slotItemRemoved( TQListViewItem * ) )); -} - -TDEListViewLineEdit::~TDEListViewLineEdit() -{ -} - -TQListViewItem *TDEListViewLineEdit::currentItem() const -{ - return item; -} - -void TDEListViewLineEdit::load(TQListViewItem *i, int c) -{ - item=i; - col=c; - - TQRect rect(p->itemRect(i)); - setText(item->text(c)); - home( true ); - - int fieldX = rect.x() - 1; - int fieldW = p->columnWidth(col) + 2; - - TQHeader* const pHeader = p->header(); - - const int pos = pHeader->mapToIndex(col); - for ( int index = 0; index < pos; ++index ) - fieldX += p->columnWidth( pHeader->mapToSection( index )); - - if ( col == 0 ) { - int d = i->depth() + (p->rootIsDecorated() ? 1 : 0); - d *= p->treeStepSize(); - fieldX += d; - fieldW -= d; - } - - if ( i->pixmap( col ) ) {// add width of pixmap - int d = i->pixmap( col )->width(); - fieldX += d; - fieldW -= d; - } - - setGeometry(fieldX, rect.y() - 1, fieldW, rect.height() + 2); - show(); - setFocus(); -} - -/* Helper functions to for - * tabOrderedRename functionality. - */ - -static int nextCol (TDEListView *pl, TQListViewItem *pi, int start, int dir) -{ - if (pi) - { - // Find the next renameable column in the current row - for (; ((dir == +1) ? (start < pl->columns()) : (start >= 0)); start += dir) - if (pl->isRenameable(start)) - return start; - } - - return -1; -} - -static TQListViewItem *prevItem (TQListViewItem *pi) -{ - TQListViewItem *pa = pi->itemAbove(); - - /* Does what the TQListViewItem::previousSibling() - * of my dreams would do. - */ - if (pa && pa->parent() == pi->parent()) - return pa; - - return 0; -} - -static TQListViewItem *lastQChild (TQListViewItem *pi) -{ - if (pi) - { - /* Since there's no TQListViewItem::lastChild(). - * This finds the last sibling for the given - * item. - */ - for (TQListViewItem *pt = pi->nextSibling(); pt; pt = pt->nextSibling()) - pi = pt; - } - - return pi; -} - -void TDEListViewLineEdit::selectNextCell (TQListViewItem *pitem, int column, bool forward) -{ - const int ncols = p->columns(); - const int dir = forward ? +1 : -1; - const int restart = forward ? 0 : (ncols - 1); - TQListViewItem *top = (pitem && pitem->parent()) - ? pitem->parent()->firstChild() - : p->firstChild(); - TQListViewItem *pi = pitem; - - terminate(); // Save current changes - - do - { - /* Check the rest of the current row for an editable column, - * if that fails, check the entire next/previous row. The - * last case goes back to the first item in the current branch - * or the last item in the current branch depending on the - * direction. - */ - if ((column = nextCol(p, pi, column + dir, dir)) != -1 || - (column = nextCol(p, (pi = (forward ? pi->nextSibling() : prevItem(pi))), restart, dir)) != -1 || - (column = nextCol(p, (pi = (forward ? top : lastQChild(pitem))), restart, dir)) != -1) - { - if (pi) - { - p->setCurrentItem(pi); // Calls terminate - p->rename(pi, column); - - /* Some listviews may override rename() to - * prevent certain items from being renamed, - * if this is done, [m_]item will be NULL - * after the rename() call... try again. - */ - if (!item) - continue; - - break; - } - } - } - while (pi && !item); -} - -#ifdef KeyPress -#undef KeyPress -#endif - -bool TDEListViewLineEdit::event (TQEvent *pe) -{ - if (pe->type() == TQEvent::KeyPress) - { - TQKeyEvent *k = (TQKeyEvent *) pe; - - if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) && - p->tabOrderedRenaming() && p->itemsRenameable() && - !(k->state() & ControlButton || k->state() & AltButton)) - { - selectNextCell(item, col, - (k->key() == Key_Tab && !(k->state() & ShiftButton))); - return true; - } - } - - return KLineEdit::event(pe); -} - -void TDEListViewLineEdit::keyPressEvent(TQKeyEvent *e) -{ - if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) - terminate(true); - else if(e->key() == Qt::Key_Escape) - terminate(false); - else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up) - { - terminate(true); - KLineEdit::keyPressEvent(e); - } - else - KLineEdit::keyPressEvent(e); -} - -void TDEListViewLineEdit::terminate() -{ - terminate(true); -} - -void TDEListViewLineEdit::terminate(bool commit) -{ - if ( item ) - { - //kdDebug() << "TDEListViewLineEdit::terminate " << commit << endl; - if (commit) - item->setText(col, text()); - int c=col; - TQListViewItem *i=item; - col=0; - item=0; - p->setFocus();// will call focusOutEvent, that's why we set item=0 before - hide(); - if (commit) - emit done(i,c); - } -} - -void TDEListViewLineEdit::focusOutEvent(TQFocusEvent *ev) -{ - TQFocusEvent * focusEv = static_cast(ev); - // Don't let a RMB close the editor - if (focusEv->reason() != TQFocusEvent::Popup && focusEv->reason() != TQFocusEvent::ActiveWindow) - terminate(true); - else - KLineEdit::focusOutEvent(ev); -} - -void TDEListViewLineEdit::paintEvent( TQPaintEvent *e ) -{ - KLineEdit::paintEvent( e ); - - if ( !frame() ) { - TQPainter p( this ); - p.setClipRegion( e->region() ); - p.drawRect( rect() ); - } -} - -// selection changed -> terminate. As our "item" can be already deleted, -// we can't call terminate(false), because that would emit done() with -// a dangling pointer to "item". -void TDEListViewLineEdit::slotSelectionChanged() -{ - item = 0; - col = 0; - hide(); -} - -// if the current item was removed -> terminate. Can't call terminate(false) -// due to same reason as slotSelectionChanged(). -void TDEListViewLineEdit::slotItemRemoved(TQListViewItem *i) -{ - if (currentItem() != i) - return; - - item = 0; - col = 0; - hide(); -} - - -TDEListView::TDEListView( TQWidget *parent, const char *name ) - : TQListView( parent, name ), - d (new TDEListViewPrivate (this)) -{ - setDragAutoScroll(true); - - connect( this, TQT_SIGNAL( onViewport() ), - this, TQT_SLOT( slotOnViewport() ) ); - connect( this, TQT_SIGNAL( onItem( TQListViewItem * ) ), - this, TQT_SLOT( slotOnItem( TQListViewItem * ) ) ); - - connect (this, TQT_SIGNAL(contentsMoving(int,int)), - this, TQT_SLOT(cleanDropVisualizer())); - connect (this, TQT_SIGNAL(contentsMoving(int,int)), - this, TQT_SLOT(cleanItemHighlighter())); - - slotSettingsChanged(TDEApplication::SETTINGS_MOUSE); - if (kapp) - { - connect( kapp, TQT_SIGNAL( settingsChanged(int) ), TQT_SLOT( slotSettingsChanged(int) ) ); - kapp->addKipcEventMask( KIPC::SettingsChanged ); - } - - connect(&d->autoSelect, TQT_SIGNAL( timeout() ), - this, TQT_SLOT( slotAutoSelect() ) ); - connect(&d->dragExpand, TQT_SIGNAL( timeout() ), - this, TQT_SLOT( slotDragExpand() ) ); - - // context menu handling - if (d->showContextMenusOnPress) - { - connect (this, TQT_SIGNAL (rightButtonPressed (TQListViewItem*, const TQPoint&, int)), - this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); - } - else - { - connect (this, TQT_SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint&, int)), - this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); - } - - connect (this, TQT_SIGNAL (menuShortCutPressed (TDEListView*, TQListViewItem*)), - this, TQT_SLOT (emitContextMenu (TDEListView*, TQListViewItem*))); - d->alternateBackground = TDEGlobalSettings::alternateBackgroundColor(); -} - -TDEListView::~TDEListView() -{ - delete d; -} - -bool TDEListView::isExecuteArea( const TQPoint& point ) -{ - TQListViewItem* item = itemAt( point ); - if ( item ) { - return isExecuteArea( point.x(), item ); - } - - return false; -} - -bool TDEListView::isExecuteArea( int x ) -{ - return isExecuteArea( x, 0 ); -} - -bool TDEListView::isExecuteArea( int x, TQListViewItem* item ) -{ - if( allColumnsShowFocus() ) - return true; - else { - int offset = 0; - - - int width = columnWidth( 0 ); - - TQHeader* const thisHeader = header(); - const int pos = thisHeader->mapToIndex( 0 ); - - for ( int index = 0; index < pos; ++index ) - offset += columnWidth( thisHeader->mapToSection( index ) ); - - x += contentsX(); // in case of a horizontal scrollbar - - if ( item ) - { - width = treeStepSize()*( item->depth() + ( rootIsDecorated() ? 1 : 0 ) ); - width += itemMargin(); - int ca = AlignHorizontal_Mask & columnAlignment( 0 ); - if ( ca == AlignLeft || ca == AlignAuto ) { - width += item->width( fontMetrics(), this, 0 ); - if ( width > columnWidth( 0 ) ) - width = columnWidth( 0 ); - } - } - - return ( x > offset && x < ( offset + width ) ); - } -} - -void TDEListView::slotOnItem( TQListViewItem *item ) -{ - TQPoint vp = viewport()->mapFromGlobal( TQCursor::pos() ); - if ( item && isExecuteArea( vp.x() ) && (d->autoSelectDelay > -1) && d->bUseSingle ) { - d->autoSelect.start( d->autoSelectDelay, true ); - d->pCurrentItem = item; - } -} - -void TDEListView::slotOnViewport() -{ - if ( d->bChangeCursorOverItem ) - viewport()->unsetCursor(); - - d->autoSelect.stop(); - d->pCurrentItem = 0L; -} - -void TDEListView::slotSettingsChanged(int category) -{ - switch (category) - { - case TDEApplication::SETTINGS_MOUSE: - d->dragDelay = TDEGlobalSettings::dndEventDelay(); - d->bUseSingle = TDEGlobalSettings::singleClick(); - - disconnect(this, TQT_SIGNAL (mouseButtonClicked (int, TQListViewItem*, const TQPoint &, int)), - this, TQT_SLOT (slotMouseButtonClicked (int, TQListViewItem*, const TQPoint &, int))); - - if( d->bUseSingle ) - connect (this, TQT_SIGNAL (mouseButtonClicked (int, TQListViewItem*, const TQPoint &, int)), - this, TQT_SLOT (slotMouseButtonClicked( int, TQListViewItem*, const TQPoint &, int))); - - d->bChangeCursorOverItem = TDEGlobalSettings::changeCursorOverIcon(); - if ( !d->disableAutoSelection ) - d->autoSelectDelay = TDEGlobalSettings::autoSelectDelay(); - - if( !d->bUseSingle || !d->bChangeCursorOverItem ) - viewport()->unsetCursor(); - - break; - - case TDEApplication::SETTINGS_POPUPMENU: - d->contextMenuKey = TDEGlobalSettings::contextMenuKey (); - d->showContextMenusOnPress = TDEGlobalSettings::showContextMenusOnPress (); - - if (d->showContextMenusOnPress) - { - disconnect (0L, 0L, this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); - - connect(this, TQT_SIGNAL (rightButtonPressed (TQListViewItem*, const TQPoint&, int)), - this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); - } - else - { - disconnect (0L, 0L, this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); - - connect(this, TQT_SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint&, int)), - this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); - } - break; - - default: - break; - } -} - -void TDEListView::slotAutoSelect() -{ - // check that the item still exists - if( itemIndex( d->pCurrentItem ) == -1 ) - return; - - if (!isActiveWindow()) - { - d->autoSelect.stop(); - return; - } - - //Give this widget the keyboard focus. - if( !hasFocus() ) - setFocus(); - - ButtonState keybstate = TDEApplication::keyboardMouseState(); - - TQListViewItem* previousItem = currentItem(); - setCurrentItem( d->pCurrentItem ); - - if( d->pCurrentItem ) { - //Shift pressed? - if( (keybstate & TQt::ShiftButton) ) { - bool block = signalsBlocked(); - blockSignals( true ); - - //No Ctrl? Then clear before! - if( !(keybstate & TQt::ControlButton) ) - clearSelection(); - - bool select = !d->pCurrentItem->isSelected(); - bool update = viewport()->isUpdatesEnabled(); - viewport()->setUpdatesEnabled( false ); - - bool down = previousItem->itemPos() < d->pCurrentItem->itemPos(); - TQListViewItemIterator lit( down ? previousItem : d->pCurrentItem ); - for ( ; lit.current(); ++lit ) { - if ( down && lit.current() == d->pCurrentItem ) { - d->pCurrentItem->setSelected( select ); - break; - } - if ( !down && lit.current() == previousItem ) { - previousItem->setSelected( select ); - break; - } - lit.current()->setSelected( select ); - } - - blockSignals( block ); - viewport()->setUpdatesEnabled( update ); - triggerUpdate(); - - emit selectionChanged(); - - if( selectionMode() == TQListView::Single ) - emit selectionChanged( d->pCurrentItem ); - } - else if( (keybstate & TDEApplication::ControlModifier) ) - setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() ); - else { - bool block = signalsBlocked(); - blockSignals( true ); - - if( !d->pCurrentItem->isSelected() ) - clearSelection(); - - blockSignals( block ); - - setSelected( d->pCurrentItem, true ); - } - } - else - kdDebug() << "TDEListView::slotAutoSelect: That�s not supposed to happen!!!!" << endl; -} - -void TDEListView::slotHeaderChanged() -{ - - const int colCount = columns(); - if (d->fullWidth && colCount) - { - int w = 0; - const int lastColumn = colCount - 1; - for (int i = 0; i < lastColumn; ++i) w += columnWidth(i); - setColumnWidth( lastColumn, viewport()->width() - w - 1 ); - } -} - -void TDEListView::emitExecute( TQListViewItem *item, const TQPoint &pos, int c ) -{ - if( isExecuteArea( viewport()->mapFromGlobal(pos) ) ) { - d->validDrag=false; - - // Double click mode ? - if ( !d->bUseSingle ) - { - viewport()->unsetCursor(); - emit executed( item ); - emit executed( item, pos, c ); - } - else - { - ButtonState keybstate = TDEApplication::keyboardMouseState(); - - d->autoSelect.stop(); - - //Don't emit executed if in SC mode and Shift or Ctrl are pressed - if( !( ((keybstate & TQt::ShiftButton) || (keybstate & TQt::ControlButton)) ) ) { - viewport()->unsetCursor(); - emit executed( item ); - emit executed( item, pos, c ); - } - } - } -} - -void TDEListView::focusInEvent( TQFocusEvent *fe ) -{ - // kdDebug()<<"TDEListView::focusInEvent()"<selectedBySimpleMove) - && (d->selectionMode == FileManager) - && (fe->reason()!=TQFocusEvent::Popup) - && (fe->reason()!=TQFocusEvent::ActiveWindow) - && (currentItem())) - { - currentItem()->setSelected(true); - currentItem()->repaint(); - emit selectionChanged(); - }; -} - -void TDEListView::focusOutEvent( TQFocusEvent *fe ) -{ - cleanDropVisualizer(); - cleanItemHighlighter(); - - d->autoSelect.stop(); - - if ((d->selectedBySimpleMove) - && (d->selectionMode == FileManager) - && (fe->reason()!=TQFocusEvent::Popup) - && (fe->reason()!=TQFocusEvent::ActiveWindow) - && (currentItem()) - && (!d->editor->isVisible())) - { - currentItem()->setSelected(false); - currentItem()->repaint(); - emit selectionChanged(); - }; - - TQListView::focusOutEvent( fe ); -} - -void TDEListView::leaveEvent( TQEvent *e ) -{ - d->autoSelect.stop(); - - TQListView::leaveEvent( e ); -} - -bool TDEListView::event( TQEvent *e ) -{ - if (e->type() == TQEvent::ApplicationPaletteChange) - d->alternateBackground=TDEGlobalSettings::alternateBackgroundColor(); - - return TQListView::event(e); -} - -void TDEListView::contentsMousePressEvent( TQMouseEvent *e ) -{ - if( (selectionModeExt() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) - { - bool block = signalsBlocked(); - blockSignals( true ); - - clearSelection(); - - blockSignals( block ); - } - else if ((selectionModeExt()==FileManager) && (d->selectedBySimpleMove)) - { - d->selectedBySimpleMove=false; - d->selectedUsingMouse=true; - if (currentItem()) - { - currentItem()->setSelected(false); - currentItem()->repaint(); -// emit selectionChanged(); - } - } - - TQPoint p( contentsToViewport( e->pos() ) ); - TQListViewItem *at = itemAt (p); - - // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) - bool rootDecoClicked = at - && ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + - treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) - && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); - - if (e->button() == Qt::LeftButton && !rootDecoClicked) - { - //Start a drag - d->startDragPos = e->pos(); - - if (at) - { - d->validDrag = true; - d->pressedOnSelected = at->isSelected(); - } - } - - TQListView::contentsMousePressEvent( e ); -} - -void TDEListView::contentsMouseMoveEvent( TQMouseEvent *e ) -{ - if (!dragEnabled() || d->startDragPos.isNull() || !d->validDrag) - TQListView::contentsMouseMoveEvent (e); - - TQPoint vp = contentsToViewport(e->pos()); - TQListViewItem *item = itemAt( vp ); - - //do we process cursor changes at all? - if ( item && d->bChangeCursorOverItem && d->bUseSingle ) - { - //Cursor moved on a new item or in/out the execute area - if( (item != d->pCurrentItem) || - (isExecuteArea(vp) != d->cursorInExecuteArea) ) - { - d->cursorInExecuteArea = isExecuteArea(vp); - - if( d->cursorInExecuteArea ) //cursor moved in execute area - viewport()->setCursor( KCursor::handCursor() ); - else //cursor moved out of execute area - viewport()->unsetCursor(); - } - } - - bool dragOn = dragEnabled(); - TQPoint newPos = e->pos(); - if (dragOn && d->validDrag && - (newPos.x() > d->startDragPos.x()+d->dragDelay || - newPos.x() < d->startDragPos.x()-d->dragDelay || - newPos.y() > d->startDragPos.y()+d->dragDelay || - newPos.y() < d->startDragPos.y()-d->dragDelay)) - //(d->startDragPos - e->pos()).manhattanLength() > TQApplication::startDragDistance()) - { - TQListView::contentsMouseReleaseEvent( 0 ); - startDrag(); - d->startDragPos = TQPoint(); - d->validDrag = false; - } -} - -void TDEListView::contentsMouseReleaseEvent( TQMouseEvent *e ) -{ - if (e->button() == Qt::LeftButton) - { - // If the row was already selected, maybe we want to start an in-place editing - if ( d->pressedOnSelected && itemsRenameable() ) - { - TQPoint p( contentsToViewport( e->pos() ) ); - TQListViewItem *at = itemAt (p); - if ( at ) - { - // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) - bool rootDecoClicked = - ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + - treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) - && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); - - if (!rootDecoClicked) - { - int col = header()->mapToLogical( header()->cellAt( p.x() ) ); - if ( d->renameable.contains(col) ) - rename(at, col); - } - } - } - - d->pressedOnSelected = false; - d->validDrag = false; - d->startDragPos = TQPoint(); - } - TQListView::contentsMouseReleaseEvent( e ); -} - -void TDEListView::contentsMouseDoubleClickEvent ( TQMouseEvent *e ) -{ - // We don't want to call the parent method because it does setOpen, - // whereas we don't do it in single click mode... (David) - //TQListView::contentsMouseDoubleClickEvent( e ); - if ( !e || e->button() != Qt::LeftButton ) - return; - - TQPoint vp = contentsToViewport(e->pos()); - TQListViewItem *item = itemAt( vp ); - emit TQListView::doubleClicked( item ); // we do it now - - int col = item ? header()->mapToLogical( header()->cellAt( vp.x() ) ) : -1; - - if( item ) { - emit doubleClicked( item, e->globalPos(), col ); - - if( (e->button() == Qt::LeftButton) && !d->bUseSingle ) - emitExecute( item, e->globalPos(), col ); - } -} - -void TDEListView::slotMouseButtonClicked( int btn, TQListViewItem *item, const TQPoint &pos, int c ) -{ - if( (btn == Qt::LeftButton) && item ) - emitExecute(item, pos, c); -} - -void TDEListView::contentsDropEvent(TQDropEvent* e) -{ - cleanDropVisualizer(); - cleanItemHighlighter(); - d->dragExpand.stop(); - - if (acceptDrag (e)) - { - e->acceptAction(); - TQListViewItem *afterme; - TQListViewItem *parent; - - findDrop(e->pos(), parent, afterme); - - if (e->source() == viewport() && itemsMovable()) - movableDropEvent(parent, afterme); - else - { - emit dropped(e, afterme); - emit dropped(this, e, afterme); - emit dropped(e, parent, afterme); - emit dropped(this, e, parent, afterme); - } - } -} - -void TDEListView::movableDropEvent (TQListViewItem* parent, TQListViewItem* afterme) -{ - TQPtrList items, afterFirsts, afterNows; - TQListViewItem *current=currentItem(); - bool hasMoved=false; - for (TQListViewItem *i = firstChild(), *iNext=0; i; i = iNext) - { - iNext=i->itemBelow(); - if (!i->isSelected()) - continue; - - // don't drop an item after itself, or else - // it moves to the top of the list - if (i==afterme) - continue; - - i->setSelected(false); - - TQListViewItem *afterFirst = i->itemAbove(); - - if (!hasMoved) - { - emit aboutToMove(); - hasMoved=true; - } - - moveItem(i, parent, afterme); - - // ###### This should include the new parent !!! -> KDE 3.0 - // If you need this right now, have a look at keditbookmarks. - emit moved(i, afterFirst, afterme); - - items.append (i); - afterFirsts.append (afterFirst); - afterNows.append (afterme); - - afterme = i; - } - clearSelection(); - for (TQListViewItem *i=items.first(); i; i=items.next() ) - i->setSelected(true); - if (current) - setCurrentItem(current); - - emit moved(items,afterFirsts,afterNows); - - if (firstChild()) - emit moved(); -} - -void TDEListView::contentsDragMoveEvent(TQDragMoveEvent *event) -{ - if (acceptDrag(event)) - { - event->acceptAction(); - //Clean up the view - - findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop); - TQPoint vp = contentsToViewport( event->pos() ); - TQListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L; - - if ( item != d->dragOverItem ) - { - d->dragExpand.stop(); - d->dragOverItem = item; - d->dragOverPoint = vp; - if ( d->dragOverItem && d->dragOverItem->isExpandable() && !d->dragOverItem->isOpen() ) - d->dragExpand.start( TQApplication::startDragTime(), true ); - } - if (dropVisualizer()) - { - TQRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, d->afterItemDrop); - if (tmpRect != d->mOldDropVisualizer) - { - cleanDropVisualizer(); - d->mOldDropVisualizer=tmpRect; - viewport()->repaint(tmpRect); - } - } - if (dropHighlighter()) - { - TQRect tmpRect = drawItemHighlighter(0, itemAt( vp )); - if (tmpRect != d->mOldDropHighlighter) - { - cleanItemHighlighter(); - d->mOldDropHighlighter=tmpRect; - viewport()->repaint(tmpRect); - } - } - } - else - event->ignore(); -} - -void TDEListView::slotDragExpand() -{ - if ( itemAt( d->dragOverPoint ) == d->dragOverItem ) - d->dragOverItem->setOpen( true ); -} - -void TDEListView::contentsDragLeaveEvent (TQDragLeaveEvent*) -{ - d->dragExpand.stop(); - cleanDropVisualizer(); - cleanItemHighlighter(); -} - -void TDEListView::cleanDropVisualizer() -{ - if (d->mOldDropVisualizer.isValid()) - { - TQRect rect=d->mOldDropVisualizer; - d->mOldDropVisualizer = TQRect(); - viewport()->repaint(rect, true); - } -} - -int TDEListView::depthToPixels( int depth ) -{ - return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin(); -} - -void TDEListView::findDrop(const TQPoint &pos, TQListViewItem *&parent, TQListViewItem *&after) -{ - TQPoint p (contentsToViewport(pos)); - - // Get the position to put it in - TQListViewItem *atpos = itemAt(p); - - TQListViewItem *above; - if (!atpos) // put it at the end - above = lastItem(); - else - { - // Get the closest item before us ('atpos' or the one above, if any) - if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2)) - above = atpos->itemAbove(); - else - above = atpos; - } - - if (above) - { - // if above has children, I might need to drop it as the first item there - - if (above->firstChild() && above->isOpen()) - { - parent = above; - after = 0; - return; - } - - // Now, we know we want to go after "above". But as a child or as a sibling ? - // We have to ask the "above" item if it accepts children. - if (above->isExpandable()) - { - // The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children - if (p.x() >= depthToPixels( above->depth() + 1 ) || - (above->isOpen() && above->childCount() > 0) ) - { - parent = above; - after = 0L; - return; - } - } - - // Ok, there's one more level of complexity. We may want to become a new - // sibling, but of an upper-level group, rather than the "above" item - TQListViewItem * betterAbove = above->parent(); - TQListViewItem * last = above; - while ( betterAbove ) - { - // We are allowed to become a sibling of "betterAbove" only if we are - // after its last child - if ( !last->nextSibling() ) - { - if (p.x() < depthToPixels ( betterAbove->depth() + 1 )) - above = betterAbove; // store this one, but don't stop yet, there may be a better one - else - break; // not enough on the left, so stop - last = betterAbove; - betterAbove = betterAbove->parent(); // up one level - } else - break; // we're among the child of betterAbove, not after the last one - } - } - // set as sibling - after = above; - parent = after ? after->parent() : 0L ; -} - -TQListViewItem* TDEListView::lastChild () const -{ - TQListViewItem* lastchild = firstChild(); - - if (lastchild) - for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling()); - - return lastchild; -} - -TQListViewItem *TDEListView::lastItem() const -{ - TQListViewItem* last = lastChild(); - - for (TQListViewItemIterator it (last); it.current(); ++it) - last = it.current(); - - return last; -} - -KLineEdit *TDEListView::renameLineEdit() const -{ - return d->editor; -} - -void TDEListView::startDrag() -{ - TQDragObject *drag = dragObject(); - - if (!drag) - return; - - if (drag->drag() && drag->target() != viewport()) - emit moved(); -} - -TQDragObject *TDEListView::dragObject() -{ - if (!currentItem()) - return 0; - - - return new TQStoredDrag("application/x-qlistviewitem", viewport()); -} - -void TDEListView::setItemsMovable(bool b) -{ - d->itemsMovable=b; -} - -bool TDEListView::itemsMovable() const -{ - return d->itemsMovable; -} - -void TDEListView::setItemsRenameable(bool b) -{ - d->itemsRenameable=b; -} - -bool TDEListView::itemsRenameable() const -{ - return d->itemsRenameable; -} - - -void TDEListView::setDragEnabled(bool b) -{ - d->dragEnabled=b; -} - -bool TDEListView::dragEnabled() const -{ - return d->dragEnabled; -} - -void TDEListView::setAutoOpen(bool b) -{ - d->autoOpen=b; -} - -bool TDEListView::autoOpen() const -{ - return d->autoOpen; -} - -bool TDEListView::dropVisualizer() const -{ - return d->dropVisualizer; -} - -void TDEListView::setDropVisualizer(bool b) -{ - d->dropVisualizer=b; -} - -TQPtrList TDEListView::selectedItems() const -{ - return selectedItems(true); -} - -TQPtrList TDEListView::selectedItems(bool includeHiddenItems) const -{ - TQPtrList list; - - // Using selectionMode() instead of selectionModeExt() since for the cases that - // we're interested in selectionMode() should work for either variety of the - // setSelectionMode(). - - switch(selectionMode()) - { - case NoSelection: - break; - case Single: - if(selectedItem() && (includeHiddenItems || selectedItem()->isVisible())) - list.append(selectedItem()); - break; - default: - { - int flags = TQListViewItemIterator::Selected; - if (!includeHiddenItems) - { - flags |= TQListViewItemIterator::Visible; - } - - TQListViewItemIterator it(const_cast(this), flags); - - for(; it.current(); ++it) - list.append(it.current()); - - break; - } - } - - return list; -} - - -void TDEListView::moveItem(TQListViewItem *item, TQListViewItem *parent, TQListViewItem *after) -{ - // sanity check - don't move a item into its own child structure - TQListViewItem *i = parent; - while(i) - { - if(i == item) - return; - i = i->parent(); - } - - if (after) - { - item->moveItem(after); - return; - } - - // Basically reimplementing the TQListViewItem(TQListViewItem*, TQListViewItem*) constructor - // in here, without ever deleting the item. - if (item->parent()) - item->parent()->takeItem(item); - else - takeItem(item); - - if (parent) - parent->insertItem(item); - else - insertItem(item); -} - -void TDEListView::contentsDragEnterEvent(TQDragEnterEvent *event) -{ - if (acceptDrag (event)) - event->accept(); -} - -void TDEListView::setDropVisualizerWidth (int w) -{ - d->mDropVisualizerWidth = w > 0 ? w : 1; -} - -TQRect TDEListView::drawDropVisualizer(TQPainter *p, TQListViewItem *parent, - TQListViewItem *after) -{ - TQRect insertmarker; - - if (!after && !parent) - insertmarker = TQRect (0, 0, viewport()->width(), d->mDropVisualizerWidth/2); - else - { - int level = 0; - if (after) - { - TQListViewItem* it = 0L; - if (after->isOpen()) - { - // Look for the last child (recursively) - it = after->firstChild(); - if (it) - while (it->nextSibling() || it->firstChild()) - if ( it->nextSibling() ) - it = it->nextSibling(); - else - it = it->firstChild(); - } - - insertmarker = itemRect (it ? it : after); - level = after->depth(); - } - else if (parent) - { - insertmarker = itemRect (parent); - level = parent->depth() + 1; - } - insertmarker.setLeft( treeStepSize() * ( level + (rootIsDecorated() ? 1 : 0) ) + itemMargin() ); - insertmarker.setRight (viewport()->width()); - insertmarker.setTop (insertmarker.bottom() - d->mDropVisualizerWidth/2 + 1); - insertmarker.setBottom (insertmarker.bottom() + d->mDropVisualizerWidth/2); - } - - // This is not used anymore, at least by TDEListView itself (see viewportPaintEvent) - // Remove for KDE 4.0. - if (p) - p->fillRect(insertmarker, Dense4Pattern); - - return insertmarker; -} - -TQRect TDEListView::drawItemHighlighter(TQPainter *painter, TQListViewItem *item) -{ - TQRect r; - - if (item) - { - r = itemRect(item); - r.setLeft(r.left()+(item->depth()+(rootIsDecorated() ? 1 : 0))*treeStepSize()); - if (painter) - style().tqdrawPrimitive(TQStyle::PE_FocusRect, painter, r, colorGroup(), - TQStyle::Style_FocusAtBorder, colorGroup().highlight()); - } - - return r; -} - -void TDEListView::cleanItemHighlighter () -{ - if (d->mOldDropHighlighter.isValid()) - { - TQRect rect=d->mOldDropHighlighter; - d->mOldDropHighlighter = TQRect(); - viewport()->repaint(rect, true); - } -} - -void TDEListView::rename(TQListViewItem *item, int c) -{ - if (d->renameable.contains(c)) - { - ensureItemVisible(item); - d->editor->load(item,c); - } -} - -bool TDEListView::isRenameable (int col) const -{ - return d->renameable.contains(col); -} - -void TDEListView::setRenameable (int col, bool renameable) -{ - if (col>=header()->count()) return; - - d->renameable.remove(col); - if (renameable) - d->renameable+=col; -} - -void TDEListView::doneEditing(TQListViewItem *item, int row) -{ - emit itemRenamed(item, item->text(row), row); - emit itemRenamed(item); -} - -bool TDEListView::acceptDrag(TQDropEvent* e) const -{ - return acceptDrops() && itemsMovable() && (e->source()==viewport()); -} - -void TDEListView::setCreateChildren(bool b) -{ - d->createChildren=b; -} - -bool TDEListView::createChildren() const -{ - return d->createChildren; -} - - -int TDEListView::tooltipColumn() const -{ - return d->tooltipColumn; -} - -void TDEListView::setTooltipColumn(int column) -{ - d->tooltipColumn=column; -} - -void TDEListView::setDropHighlighter(bool b) -{ - d->dropHighlighter=b; -} - -bool TDEListView::dropHighlighter() const -{ - return d->dropHighlighter; -} - -bool TDEListView::showTooltip(TQListViewItem *item, const TQPoint &, int column) const -{ - return ((column==tooltipColumn()) && !tooltip(item, column).isEmpty()); -} - -TQString TDEListView::tooltip(TQListViewItem *item, int column) const -{ - return item->text(column); -} - -void TDEListView::setTabOrderedRenaming(bool b) -{ - d->tabRename = b; -} - -bool TDEListView::tabOrderedRenaming() const -{ - return d->tabRename; -} - -void TDEListView::keyPressEvent (TQKeyEvent* e) -{ - //don't we need a contextMenuModifier too ? (aleXXX) - if (e->key() == d->contextMenuKey) - { - emit menuShortCutPressed (this, currentItem()); - return; - } - - if (d->selectionMode != FileManager) - TQListView::keyPressEvent (e); - else - fileManagerKeyPressEvent (e); -} - -void TDEListView::activateAutomaticSelection() -{ - d->selectedBySimpleMove=true; - d->selectedUsingMouse=false; - if (currentItem()) - { - currentItem()->setSelected(true); - currentItem()->repaint(); - emit selectionChanged(); - }; -} - -void TDEListView::deactivateAutomaticSelection() -{ - d->selectedBySimpleMove=false; -} - -bool TDEListView::automaticSelection() const -{ - return d->selectedBySimpleMove; -} - -void TDEListView::fileManagerKeyPressEvent (TQKeyEvent* e) -{ - //don't care whether it's on the keypad or not - int e_state=(e->state() & ~Keypad); - - int oldSelectionDirection(d->selectionDirection); - - if ((e->key()!=Key_Shift) && (e->key()!=Key_Control) - && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)) - { - if ((e_state==ShiftButton) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove)) - selectAll(false); - d->selectionDirection=0; - d->wasShiftEvent = (e_state == ShiftButton); - }; - - //d->wasShiftEvent = (e_state == ShiftButton); - - - TQListViewItem* item = currentItem(); - if (!item) return; - - TQListViewItem* repaintItem1 = item; - TQListViewItem* repaintItem2 = 0L; - TQListViewItem* visItem = 0L; - - TQListViewItem* nextItem = 0L; - int items = 0; - - bool shiftOrCtrl((e_state==ControlButton) || (e_state==ShiftButton)); - int selectedItems(0); - for (TQListViewItem *tmpItem=firstChild(); tmpItem; tmpItem=tmpItem->nextSibling()) - if (tmpItem->isSelected()) selectedItems++; - - if (((!selectedItems) || ((selectedItems==1) && (d->selectedUsingMouse))) - && (e_state==Qt::NoButton) - && ((e->key()==Key_Down) - || (e->key()==Key_Up) - || (e->key()==Key_Next) - || (e->key()==Key_Prior) - || (e->key()==Key_Home) - || (e->key()==Key_End))) - { - d->selectedBySimpleMove=true; - d->selectedUsingMouse=false; - } - else if (selectedItems>1) - d->selectedBySimpleMove=false; - - bool emitSelectionChanged(false); - - switch (e->key()) - { - case Key_Escape: - selectAll(false); - emitSelectionChanged=true; - break; - - case Key_Space: - //toggle selection of current item - if (d->selectedBySimpleMove) - d->selectedBySimpleMove=false; - item->setSelected(!item->isSelected()); - emitSelectionChanged=true; - break; - - case Key_Insert: - //toggle selection of current item and move to the next item - if (d->selectedBySimpleMove) - { - d->selectedBySimpleMove=false; - if (!item->isSelected()) item->setSelected(true); - } - else - { - item->setSelected(!item->isSelected()); - }; - - nextItem=item->itemBelow(); - - if (nextItem) - { - repaintItem2=nextItem; - visItem=nextItem; - setCurrentItem(nextItem); - }; - d->selectionDirection=1; - emitSelectionChanged=true; - break; - - case Key_Down: - nextItem=item->itemBelow(); - //toggle selection of current item and move to the next item - if (shiftOrCtrl) - { - d->selectionDirection=1; - if (d->selectedBySimpleMove) - d->selectedBySimpleMove=false; - else - { - if (oldSelectionDirection!=-1) - { - item->setSelected(!item->isSelected()); - emitSelectionChanged=true; - }; - }; - } - else if ((d->selectedBySimpleMove) && (nextItem)) - { - item->setSelected(false); - emitSelectionChanged=true; - }; - - if (nextItem) - { - if (d->selectedBySimpleMove) - nextItem->setSelected(true); - repaintItem2=nextItem; - visItem=nextItem; - setCurrentItem(nextItem); - }; - break; - - case Key_Up: - nextItem=item->itemAbove(); - d->selectionDirection=-1; - //move to the prev. item and toggle selection of this one - // => No, can't select the last item, with this. For symmetry, let's - // toggle selection and THEN move up, just like we do in down (David) - if (shiftOrCtrl) - { - if (d->selectedBySimpleMove) - d->selectedBySimpleMove=false; - else - { - if (oldSelectionDirection!=1) - { - item->setSelected(!item->isSelected()); - emitSelectionChanged=true; - }; - } - } - else if ((d->selectedBySimpleMove) && (nextItem)) - { - item->setSelected(false); - emitSelectionChanged=true; - }; - - if (nextItem) - { - if (d->selectedBySimpleMove) - nextItem->setSelected(true); - repaintItem2=nextItem; - visItem=nextItem; - setCurrentItem(nextItem); - }; - break; - - case Key_End: - //move to the last item and toggle selection of all items inbetween - nextItem=item; - if (d->selectedBySimpleMove) - item->setSelected(false); - if (shiftOrCtrl) - d->selectedBySimpleMove=false; - - while(nextItem) - { - if (shiftOrCtrl) - nextItem->setSelected(!nextItem->isSelected()); - if (!nextItem->itemBelow()) - { - if (d->selectedBySimpleMove) - nextItem->setSelected(true); - repaintItem2=nextItem; - visItem=nextItem; - setCurrentItem(nextItem); - } - nextItem=nextItem->itemBelow(); - } - emitSelectionChanged=true; - break; - - case Key_Home: - // move to the first item and toggle selection of all items inbetween - nextItem = firstChild(); - visItem = nextItem; - repaintItem2 = visItem; - if (d->selectedBySimpleMove) - item->setSelected(false); - if (shiftOrCtrl) - { - d->selectedBySimpleMove=false; - - while ( nextItem != item ) - { - nextItem->setSelected( !nextItem->isSelected() ); - nextItem = nextItem->itemBelow(); - } - item->setSelected( !item->isSelected() ); - } - setCurrentItem( firstChild() ); - emitSelectionChanged=true; - break; - - case Key_Next: - items=visibleHeight()/item->height(); - nextItem=item; - if (d->selectedBySimpleMove) - item->setSelected(false); - if (shiftOrCtrl) - { - d->selectedBySimpleMove=false; - d->selectionDirection=1; - }; - - for (int i=0; isetSelected(!nextItem->isSelected()); - //the end - if ((i==items-1) || (!nextItem->itemBelow())) - - { - if (shiftOrCtrl) - nextItem->setSelected(!nextItem->isSelected()); - if (d->selectedBySimpleMove) - nextItem->setSelected(true); - ensureItemVisible(nextItem); - setCurrentItem(nextItem); - update(); - if ((shiftOrCtrl) || (d->selectedBySimpleMove)) - { - emit selectionChanged(); - } - return; - } - nextItem=nextItem->itemBelow(); - } - break; - - case Key_Prior: - items=visibleHeight()/item->height(); - nextItem=item; - if (d->selectedBySimpleMove) - item->setSelected(false); - if (shiftOrCtrl) - { - d->selectionDirection=-1; - d->selectedBySimpleMove=false; - }; - - for (int i=0; isetSelected(!nextItem->isSelected()); - //the end - if ((i==items-1) || (!nextItem->itemAbove())) - - { - if (d->selectedBySimpleMove) - nextItem->setSelected(true); - ensureItemVisible(nextItem); - setCurrentItem(nextItem); - update(); - if ((shiftOrCtrl) || (d->selectedBySimpleMove)) - { - emit selectionChanged(); - } - return; - } - nextItem=nextItem->itemAbove(); - } - break; - - case Key_Minus: - if ( item->isOpen() ) - setOpen( item, false ); - break; - case Key_Plus: - if ( !item->isOpen() && (item->isExpandable() || item->childCount()) ) - setOpen( item, true ); - break; - default: - bool realKey = ((e->key()!=Key_Shift) && (e->key()!=Key_Control) - && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)); - - bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected()); - if (realKey && selectCurrentItem) - item->setSelected(false); - //this is mainly for the "goto filename beginning with pressed char" feature (aleXXX) - TQListView::SelectionMode oldSelectionMode = selectionMode(); - setSelectionMode (TQListView::Multi); - TQListView::keyPressEvent (e); - setSelectionMode (oldSelectionMode); - if (realKey && selectCurrentItem) - { - currentItem()->setSelected(true); - emitSelectionChanged=true; - } - repaintItem2=currentItem(); - if (realKey) - visItem=currentItem(); - break; - } - - if (visItem) - ensureItemVisible(visItem); - - TQRect ir; - if (repaintItem1) - ir = ir.unite( itemRect(repaintItem1) ); - if (repaintItem2) - ir = ir.unite( itemRect(repaintItem2) ); - - if ( !ir.isEmpty() ) - { // rectangle to be repainted - if ( ir.x() < 0 ) - ir.moveBy( -ir.x(), 0 ); - viewport()->repaint( ir, false ); - } - /*if (repaintItem1) - repaintItem1->repaint(); - if (repaintItem2) - repaintItem2->repaint();*/ - update(); - if (emitSelectionChanged) - emit selectionChanged(); -} - -void TDEListView::setSelectionModeExt (SelectionModeExt mode) -{ - d->selectionMode = mode; - - switch (mode) - { - case Single: - case Multi: - case Extended: - case NoSelection: - setSelectionMode (static_cast(static_cast(mode))); - break; - - case FileManager: - setSelectionMode (TQListView::Extended); - break; - - default: - kdWarning () << "Warning: illegal selection mode " << int(mode) << " set!" << endl; - break; - } -} - -TDEListView::SelectionModeExt TDEListView::selectionModeExt () const -{ - return d->selectionMode; -} - -int TDEListView::itemIndex( const TQListViewItem *item ) const -{ - if ( !item ) - return -1; - - if ( item == firstChild() ) - return 0; - else { - TQListViewItemIterator it(firstChild()); - uint j = 0; - for (; it.current() && it.current() != item; ++it, ++j ); - - if( !it.current() ) - return -1; - - return j; - } -} - -TQListViewItem* TDEListView::itemAtIndex(int index) -{ - if (index<0) - return 0; - - int j(0); - for (TQListViewItemIterator it=firstChild(); it.current(); ++it) - { - if (j==index) - return it.current(); - ++j; - }; - return 0; -} - - -void TDEListView::emitContextMenu (TDEListView*, TQListViewItem* i) -{ - TQPoint p; - - if (i) - p = viewport()->mapToGlobal(itemRect(i).center()); - else - p = mapToGlobal(rect().center()); - - emit contextMenu (this, i, p); -} - -void TDEListView::emitContextMenu (TQListViewItem* i, const TQPoint& p, int) -{ - emit contextMenu (this, i, p); -} - -void TDEListView::setAcceptDrops (bool val) -{ - TQListView::setAcceptDrops (val); - viewport()->setAcceptDrops (val); -} - -int TDEListView::dropVisualizerWidth () const -{ - return d->mDropVisualizerWidth; -} - - -void TDEListView::viewportPaintEvent(TQPaintEvent *e) -{ - d->paintAbove = 0; - d->paintCurrent = 0; - d->paintBelow = 0; - d->painting = true; - - TQListView::viewportPaintEvent(e); - - if (d->mOldDropVisualizer.isValid() && e->rect().intersects(d->mOldDropVisualizer)) - { - TQPainter painter(viewport()); - - // This is where we actually draw the drop-visualizer - painter.fillRect(d->mOldDropVisualizer, Dense4Pattern); - } - if (d->mOldDropHighlighter.isValid() && e->rect().intersects(d->mOldDropHighlighter)) - { - TQPainter painter(viewport()); - - // This is where we actually draw the drop-highlighter - style().tqdrawPrimitive(TQStyle::PE_FocusRect, &painter, d->mOldDropHighlighter, colorGroup(), - TQStyle::Style_FocusAtBorder); - } - d->painting = false; -} - -void TDEListView::setFullWidth() -{ - setFullWidth(true); -} - -void TDEListView::setFullWidth(bool fullWidth) -{ - d->fullWidth = fullWidth; - header()->setStretchEnabled(fullWidth, columns()-1); -} - -bool TDEListView::fullWidth() const -{ - return d->fullWidth; -} - -int TDEListView::addColumn(const TQString& label, int width) -{ - int result = TQListView::addColumn(label, width); - if (d->fullWidth) { - header()->setStretchEnabled(false, columns()-2); - header()->setStretchEnabled(true, columns()-1); - } - return result; -} - -int TDEListView::addColumn(const TQIconSet& iconset, const TQString& label, int width) -{ - int result = TQListView::addColumn(iconset, label, width); - if (d->fullWidth) { - header()->setStretchEnabled(false, columns()-2); - header()->setStretchEnabled(true, columns()-1); - } - return result; -} - -void TDEListView::removeColumn(int index) -{ - TQListView::removeColumn(index); - if (d->fullWidth && index == columns()) header()->setStretchEnabled(true, columns()-1); -} - -void TDEListView::viewportResizeEvent(TQResizeEvent* e) -{ - TQListView::viewportResizeEvent(e); -} - -const TQColor &TDEListView::alternateBackground() const -{ - return d->alternateBackground; -} - -void TDEListView::setAlternateBackground(const TQColor &c) -{ - d->alternateBackground = c; - repaint(); -} - -void TDEListView::setShadeSortColumn(bool shadeSortColumn) -{ - d->shadeSortColumn = shadeSortColumn; - repaint(); -} - -bool TDEListView::shadeSortColumn() const -{ - return d->shadeSortColumn; -} - -void TDEListView::saveLayout(TDEConfig *config, const TQString &group) const -{ - TDEConfigGroupSaver saver(config, group); - TQStringList widths, order; - - const int colCount = columns(); - TQHeader* const thisHeader = header(); - for (int i = 0; i < colCount; ++i) - { - widths << TQString::number(columnWidth(i)); - order << TQString::number(thisHeader->mapToIndex(i)); - } - config->writeEntry("ColumnWidths", widths); - config->writeEntry("ColumnOrder", order); - config->writeEntry("SortColumn", d->sortColumn); - config->writeEntry("SortAscending", d->sortAscending); -} - -void TDEListView::restoreLayout(TDEConfig *config, const TQString &group) -{ - TDEConfigGroupSaver saver(config, group); - TQStringList cols = config->readListEntry("ColumnWidths"); - int i = 0; - { // scope the iterators - TQStringList::ConstIterator it = cols.constBegin(); - const TQStringList::ConstIterator itEnd = cols.constEnd(); - for (; it != itEnd; ++it) - setColumnWidth(i++, (*it).toInt()); - } - - // move sections in the correct sequence: from lowest to highest index position - // otherwise we move a section from an index, which modifies - // all index numbers to the right of the moved one - cols = config->readListEntry("ColumnOrder"); - const int colCount = columns(); - for (i = 0; i < colCount; ++i) // final index positions from lowest to highest - { - TQStringList::ConstIterator it = cols.constBegin(); - const TQStringList::ConstIterator itEnd = cols.constEnd(); - - int section = 0; - for (; (it != itEnd) && ((*it).toInt() != i); ++it, ++section) ; - - if ( it != itEnd ) { - // found the section to move to position i - header()->moveSection(section, i); - } - } - - if (config->hasKey("SortColumn")) - setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true)); -} - -void TDEListView::setSorting(int column, bool ascending) -{ - TQListViewItem *selected = 0; - - if (selectionMode() == TQListView::Single) { - selected = selectedItem(); - if (selected && !selected->isVisible()) - selected = 0; - } - else if (selectionMode() != TQListView::NoSelection) { - TQListViewItem *item = firstChild(); - while (item && !selected) { - if (item->isSelected() && item->isVisible()) - selected = item; - item = item->itemBelow(); - } - } - - d->sortColumn = column; - d->sortAscending = ascending; - TQListView::setSorting(column, ascending); - - if (selected) - ensureItemVisible(selected); - - TQListViewItem* item = firstChild(); - while ( item ) { - TDEListViewItem *kItem = dynamic_cast(item); - if (kItem) kItem->m_known = false; - item = item->itemBelow(); - } -} - -int TDEListView::columnSorted(void) const -{ - return d->sortColumn; -} - -bool TDEListView::ascendingSort(void) const -{ - return d->sortAscending; -} - -void TDEListView::takeItem(TQListViewItem *item) -{ - if(item && item == d->editor->currentItem()) - d->editor->terminate(); - - TQListView::takeItem(item); -} - -void TDEListView::disableAutoSelection() -{ - if ( d->disableAutoSelection ) - return; - - d->disableAutoSelection = true; - d->autoSelect.stop(); - d->autoSelectDelay = -1; -} - -void TDEListView::resetAutoSelection() -{ - if ( !d->disableAutoSelection ) - return; - - d->disableAutoSelection = false; - d->autoSelectDelay = TDEGlobalSettings::autoSelectDelay(); -} - -void TDEListView::doubleClicked( TQListViewItem *item, const TQPoint &pos, int c ) -{ - emit TQListView::doubleClicked( item, pos, c ); -} - -TDEListViewItem::TDEListViewItem(TQListView *parent) - : TQListViewItem(parent) -{ - init(); -} - -TDEListViewItem::TDEListViewItem(TQListViewItem *parent) - : TQListViewItem(parent) -{ - init(); -} - -TDEListViewItem::TDEListViewItem(TQListView *parent, TQListViewItem *after) - : TQListViewItem(parent, after) -{ - init(); -} - -TDEListViewItem::TDEListViewItem(TQListViewItem *parent, TQListViewItem *after) - : TQListViewItem(parent, after) -{ - init(); -} - -TDEListViewItem::TDEListViewItem(TQListView *parent, - TQString label1, TQString label2, TQString label3, TQString label4, - TQString label5, TQString label6, TQString label7, TQString label8) - : TQListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) -{ - init(); -} - -TDEListViewItem::TDEListViewItem(TQListViewItem *parent, - TQString label1, TQString label2, TQString label3, TQString label4, - TQString label5, TQString label6, TQString label7, TQString label8) - : TQListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) -{ - init(); -} - -TDEListViewItem::TDEListViewItem(TQListView *parent, TQListViewItem *after, - TQString label1, TQString label2, TQString label3, TQString label4, - TQString label5, TQString label6, TQString label7, TQString label8) - : TQListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) -{ - init(); -} - -TDEListViewItem::TDEListViewItem(TQListViewItem *parent, TQListViewItem *after, - TQString label1, TQString label2, TQString label3, TQString label4, - TQString label5, TQString label6, TQString label7, TQString label8) - : TQListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) -{ - init(); -} - -TDEListViewItem::~TDEListViewItem() -{ - if(listView()) - emit static_cast(listView())->itemRemoved(this); -} - -void TDEListViewItem::init() -{ - m_odd = m_known = false; - TDEListView *lv = static_cast(listView()); - setDragEnabled( dragEnabled() || lv->dragEnabled() ); - emit lv->itemAdded(this); -} - -void TDEListViewItem::insertItem(TQListViewItem *item) -{ - TQListViewItem::insertItem(item); - if(listView()) - emit static_cast(listView())->itemAdded(item); -} - -void TDEListViewItem::takeItem(TQListViewItem *item) -{ - TQListViewItem::takeItem(item); - if(listView()) - emit static_cast(listView())->itemRemoved(item); -} - -const TQColor &TDEListViewItem::backgroundColor() -{ - if (isAlternate()) - return static_cast< TDEListView* >(listView())->alternateBackground(); - return listView()->viewport()->colorGroup().base(); -} - -TQColor TDEListViewItem::backgroundColor(int column) -{ - TDEListView* view = static_cast< TDEListView* >(listView()); - TQColor color = isAlternate() ? - view->alternateBackground() : - view->viewport()->colorGroup().base(); - - // calculate a different color if the current column is sorted (only if more than 1 column) - if ( (view->columns() > 1) && view->shadeSortColumn() && (column == view->columnSorted()) ) - { - if ( color == Qt::black ) - color = TQColor(55, 55, 55); // dark gray - else - { - int h,s,v; - color.hsv(&h, &s, &v); - if ( v > 175 ) - color = color.dark(104); - else - color = color.light(120); - } - } - - return color; -} - -bool TDEListViewItem::isAlternate() -{ - TDEListView* const lv = static_cast(listView()); - if (lv && lv->alternateBackground().isValid()) - { - TDEListViewItem *above; - - TDEListView::TDEListViewPrivate* const lvD = lv->d; - - // Ok, there's some weirdness here that requires explanation as this is a - // speed hack. itemAbove() is a O(n) operation (though this isn't - // immediately clear) so we want to call it as infrequently as possible -- - // especially in the case of painting a cell. - // - // So, in the case that we *are* painting a cell: (1) we're assuming that - // said painting is happening top to bottem -- this assumption is present - // elsewhere in the implementation of this class, (2) itemBelow() is fast -- - // roughly constant time. - // - // Given these assumptions we can do a mixture of caching and telling the - // next item that the when that item is the current item that the now - // current item will be the item above it. - // - // Ideally this will make checking to see if the item above the current item - // is the alternate color a constant time operation rather than 0(n). - - if (lvD->painting) { - if (lvD->paintCurrent != this) - { - lvD->paintAbove = lvD->paintBelow == this ? lvD->paintCurrent : itemAbove(); - lvD->paintCurrent = this; - lvD->paintBelow = itemBelow(); - } - - above = dynamic_cast(lvD->paintAbove); - } - else - { - above = dynamic_cast(itemAbove()); - } - - m_known = above ? above->m_known : true; - if (m_known) - { - m_odd = above ? !above->m_odd : false; - } - else - { - TDEListViewItem *item; - bool previous = true; - if (parent()) - { - item = dynamic_cast(parent()); - if (item) - previous = item->m_odd; - item = dynamic_cast(parent()->firstChild()); - } - else - { - item = dynamic_cast(lv->firstChild()); - } - - while(item) - { - previous = !previous; - item->m_odd = previous; - item->m_known = true; - item = dynamic_cast(item->nextSibling()); - } - } - return m_odd; - } - return false; -} - -void TDEListViewItem::paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment) -{ - TQColorGroup _cg = cg; - TQListView* lv = listView(); - const TQPixmap *pm = lv->viewport()->backgroundPixmap(); - - if (pm && !pm->isNull()) - { - _cg.setBrush(TQColorGroup::Base, TQBrush(backgroundColor(column), *pm)); - TQPoint o = p->brushOrigin(); - p->setBrushOrigin( o.x()-lv->contentsX(), o.y()-lv->contentsY() ); - } - else - { - _cg.setColor((lv->viewport()->backgroundMode() == TQt::FixedColor) ? - TQColorGroup::Background : TQColorGroup::Base, - backgroundColor(column)); - } - TQListViewItem::paintCell(p, _cg, column, width, alignment); -} - -/*! - If \a select is TRUE, all the items get selected; otherwise all - the items get unselected. This only works in the selection modes \c - Multi and \c Extended. In \c Single and \c NoSelection mode the - selection of the current item is just set to \a select. -*/ - -void TDEListView::selectAll( bool select ) -{ - if ( selectionMode() == Multi || selectionMode() == Extended ) { - bool b = signalsBlocked(); - blockSignals( TRUE ); - bool anything = FALSE; - TQListViewItemIterator it( this ); - while ( it.current() ) { - TQListViewItem *i = it.current(); - if ( select == TRUE ) { - if ( (bool)i->isVisible() == TRUE ) { - i->setSelected( TRUE ); - anything = TRUE; - } - if ( (bool)i->isVisible() == FALSE ) { - i->setSelected( FALSE ); - anything = TRUE; - } - } - else { - if ( (bool)i->isSelected() != select ) { - i->setSelected( select ); - anything = TRUE; - } - } - ++it; - } - blockSignals( b ); - if ( anything ) { - emit selectionChanged(); -// d->useDoubleBuffer = TRUE; - triggerUpdate(); - } - } else if ( currentItem() ) { - TQListViewItem * i = currentItem(); - setSelected( i, select ); - } -} - -void TDEListView::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -#include "klistview.moc" -#include "klistviewlineedit.moc" - -// vim: noet diff --git a/tdeui/klistview.h b/tdeui/klistview.h deleted file mode 100644 index 750100b8c..000000000 --- a/tdeui/klistview.h +++ /dev/null @@ -1,1094 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2000 Reginald Stadlbauer - Copyright (C) 2000 Charles Samuels - Copyright (C) 2000 Peter Putzer - - 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 KLISTVIEW_H -#define KLISTVIEW_H - -#include - -#include -#include - -class TQDragObject; -class TDEConfig; -class KLineEdit; -/** - * This Widget extends the functionality of TQListView to honor the system - * wide settings for Single Click/Double Click mode, AutoSelection and - * ChangeCursorOverLink (TM). - * - * There is a new signal executed(). It gets connected to either - * TQListView::clicked() or TQListView::doubleClicked() depending on the KDE - * wide Single Click/Double Click settings. It is strongly recommended that - * you use this signal instead of the above mentioned. This way you don´t - * need to care about the current settings. - * If you want to get informed when the user selects something connect to the - * TQListView::selectionChanged() signal. - * - * Drag-and-Drop is supported with the signal dropped(), just setAcceptDrops(true) - * and connect it to a suitable slot. - * To see where you are dropping, setDropVisualizer(true). - * And also you'll need acceptDrag(TQDropEvent*) - * - * TDEListView is drag-enabled, too: to benefit from that you have to derive from it. - * Reimplement dragObject() and (possibly) startDrag(), - * and setDragEnabled(true). - */ -class TDEUI_EXPORT TDEListView : public TQListView -{ - friend class TDEListViewItem; - - Q_OBJECT - - TQ_ENUMS( SelectionModeExt ) - TQ_PROPERTY( bool fullWidth READ fullWidth WRITE setFullWidth ) - TQ_PROPERTY( bool itemsMovable READ itemsMovable WRITE setItemsMovable ) - TQ_PROPERTY( bool itemsRenameable READ itemsRenameable WRITE setItemsRenameable ) - TQ_PROPERTY( bool dragEnabled READ dragEnabled WRITE setDragEnabled ) - TQ_PROPERTY( bool autoOpen READ autoOpen WRITE setAutoOpen ) - TQ_PROPERTY( bool dropVisualizer READ dropVisualizer WRITE setDropVisualizer ) - TQ_PROPERTY( int tooltipColumn READ tooltipColumn WRITE setTooltipColumn ) - TQ_PROPERTY( int dropVisualizerWidth READ dropVisualizerWidth WRITE setDropVisualizerWidth ) - TQ_PROPERTY( TQColor alternateBackground READ alternateBackground WRITE setAlternateBackground ) - TQ_PROPERTY( bool shadeSortColumn READ shadeSortColumn WRITE setShadeSortColumn ) - - TQ_OVERRIDE( SelectionModeExt selectionMode READ selectionModeExt WRITE setSelectionModeExt ) - -public: - /** - * Possible selection modes. - * - * The first four correspond directly to TQListView::SelectionMode, while - * the FileManager selection mode is defined as follows: - * @li home: move to the first - * @li end: move to the last - * @li PgUp/PgDn: move one page up/down - * @li up/down: move one item up/down - * @li insert: toggle selection of current and move to the next - * @li space: toggle selection of the current - * @li CTRL+up: move to the previous item and toggle selection of this one - * @li CTRL+down: toggle selection of the current item and move to the next - * @li CTRL+end: toggle selection from (including) the current - * item to (including) the last item - * @li CTRL+home: toggle selection from (including) the current - * item to the (including) the first item - * @li CTRL+PgDn: toggle selection from (including) the current - * item to (excluding) the item one page down - * @li CTRL+PgUp: toggle selection from (excluding) the current - * item to (including) the item one page up - * - * The combinations work the same with SHIFT instead of CTRL, except - * that if you start selecting something using SHIFT everything selected - * before will be deselected first. - * - * Additionally the current item is always selected automatically when - * navigating using the keyboard, except other items were selected explicitly. - * - * This way e.g. SHIFT+up/PgUp then SHIFT+down/PgDn leaves no item selected - */ - enum SelectionModeExt { - Single = TQListView::Single, - Multi = TQListView::Multi, - Extended = TQListView::Extended, - NoSelection = TQListView::NoSelection, - FileManager - }; - - /** - * Constructor. - * - * The parameters @p parent and @p name are handled by - * TQListView, as usual. - */ - TDEListView (TQWidget *parent = 0, const char *name = 0); - - /** - * Destructor. - */ - virtual ~TDEListView(); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void setAcceptDrops (bool); - - /** - * This function determines whether the given coordinates are within the - * execute area. The execute area is the part of a TQListViewItem where mouse - * clicks or double clicks respectively generate a executed() signal. - * Depending on TQListView::allColumnsShowFocus() this is either the - * whole item or only the first column. - * @return true if point is inside execute area of an item, false in all - * other cases including the case that it is over the viewport. - */ - virtual bool isExecuteArea( const TQPoint& point ); - - /** - * Same thing, but from an x coordinate only. This only checks if x is in - * the first column (if all columns don't show focus), without testing if - * the y coordinate is over an item or not. - */ - bool isExecuteArea( int x ); - - /** - * @return a list containing the currently selected items. - * - * @deprecated - */ - TQPtrList selectedItems() const; - - /** - * @return a list containing the currently selected items. - * - * @param includeHiddenItems Set to true to return all items regardless of - * visibility. Set to false to only return items that are isVisible(). - * - * @return a list of all selected listview items - * - * @since 3.4 - */ - TQPtrList selectedItems(bool includeHiddenItems) const; // ### BIC: KDE 4: use an implicitly shared class! (QValutList?) and merge with above, default to true - - /** - * Arbitrarily move @p item to @p parent, positioned immediately after item @p after. - * If after is 0, @p item is made the first child of @p parent. - * - * (Un-deprecated in kde-3.4) - */ - void moveItem(TQListViewItem *item, TQListViewItem *parent, TQListViewItem *after); - - /** - * @return the last item (not child!) of this listview. - * - * @see lastChild() - */ - TQListViewItem *lastItem() const; - - /** - * @return the last child of this listview. - * - * @see lastItem() - */ - TQListViewItem* lastChild () const; - - /** - * @return the lineedit used for inline renaming. - * Use that to setup a KCompletion or TQValidator for the lineedit - * - * @since 3.2 - */ - KLineEdit* renameLineEdit() const; - - /** - * @returns if it is legal to move items in the list view. True by default. - * - * @see setDragEnabled() - * @see setItemsMovable() - */ - bool itemsMovable() const; - - /** - * @return whether inplace-renaming has been enabled. False by default. - * - * @see setItemsRenameable() - */ - bool itemsRenameable() const; - - /** - * @return whether dragging is enabled. False by default. - * - * @see setDragEnabled() - */ - bool dragEnabled() const; - - /** - * @return true if AutoOpen is enabled (not implemented currently). - * - * @see setAutoOpen() - */ - bool autoOpen() const; - - /** - * @return true if @p column is renamable. - * - * @see setRenameable() - */ - bool isRenameable (int column) const; - - /** - * @return true if drawing of the drop-visualizer has been enabled. True by default. - * - * @see setDropVisualizer() - */ - bool dropVisualizer() const; - - /** - * @return the column for which tooltips are displayed (or -1 if none set). - * - * @see setTooltipColumn() - */ - int tooltipColumn() const; - - /** - * For future expansions. - * - * Do not use. - * @deprecated - */ - bool createChildren() const KDE_DEPRECATED; - - /** - * @return true if drawing of the drop-highlighter has been enabled. False by default. - * - * @see setDropHighlighter() - */ - bool dropHighlighter() const; - - /** - * The dropVisualizerWidth defaults to 4. - * - * @see setDropVisualizerWidth() - * @return the current width of the drop-visualizer. - */ - int dropVisualizerWidth () const; - - /** - * @return the "extended" selection mode of this listview. - * - * @see SelectionModeExt - * @see setSelectionModeExt - */ - SelectionModeExt selectionModeExt () const; - - /** - * Returns the index of @p item within the item tree or -1 if - * @p item doesn't exist in this list view. This function takes - * all items into account not only the visible ones. - */ - int itemIndex( const TQListViewItem *item ) const; - - /** - * Returns the item of @p index within the item tree or 0 if - * @p index doesn't exist in this list view. This function takes - * all items into account not only the visible ones. - */ - TQListViewItem* itemAtIndex(int index); - - /** - * @deprecated - * @see setFullWidth() - */ - void setFullWidth() KDE_DEPRECATED; - - /** - * Let the last column fit exactly all the available width. - * - * @see fullWidth() - */ - void setFullWidth(bool fullWidth); - - /** - * Returns whether the last column is set to fit the available width. - * - * @see setFullWidth() - */ - bool fullWidth() const; - - /** - * Reimplemented for full width support - * - * @see removeColumn() - */ - virtual int addColumn(const TQString& label, int width = -1); - /** - * Reimplemented for full width support - */ - virtual int addColumn(const TQIconSet& iconset, const TQString& label, int width = -1); - /** - * Reimplemented for full width support - * - * @see addColumn() - */ - virtual void removeColumn(int index); - - /** - * sets the alternate background background color. - * This only has an effect if the items are TDEListViewItems - * - * @param c the color to use for every other item. Set to an invalid - * color to disable alternate colors. - * - * @see alternateBackground() - **/ - void setAlternateBackground(const TQColor &c); - /** - * @return the alternate background color - * - * @see setAlternateBackground() - */ - const TQColor &alternateBackground() const; - - /** - * Saves the list view's layout (column widtsh, column order, sort column) - * to a TDEConfig group - * - * @param config the TDEConfig object to write to - * @param group the config group to use - */ - void saveLayout(TDEConfig *config, const TQString &group) const; - /** - * Reads the list view's layout from a TDEConfig group as stored with - * saveLayout - * - * @param config the TDEConfig object to read from - * @param group the config group to use - */ - void restoreLayout(TDEConfig *config, const TQString &group); - /** - * Reimplemented to remember the current sort column and order. - * @param column is the column to be sorted, or -1 to sort in order of - * insertion - * @param ascending whether to sort ascending (or descending) - */ - virtual void setSorting(int column, bool ascending = true); - - /** - * @return the currently sorted column, or -1 if none is sorted - */ - int columnSorted(void) const; - - /** - * @return whether the current sort is ascending (or descending) - */ - bool ascendingSort(void) const; - - /** - * Reimplemented for internal reasons. - */ - virtual void takeItem(TQListViewItem *i); - - /** - * Set to true if the currently sorted column should be drawn shaded. Defaults to true - * @param shadeSortColumn True if sort column should be shaded. - * - * @since 3.4 - */ - void setShadeSortColumn(bool shadeSortColumn); - - /** - * See if the sort column should be drawn shaded - * @return true if the sort column should be shaded - * - * @since 3.4 - */ - bool shadeSortColumn(void) const; -signals: - - /** - * This signal is emitted whenever the user executes an listview item. - * That means depending on the KDE wide Single Click/Double Click - * setting the user clicked or double clicked on that item. - * @param item is the pointer to the executed listview item. - * - * Note that you may not delete any TQListViewItem objects in slots - * connected to this signal. - */ - void executed( TQListViewItem *item ); - - /** - * This signal is emitted whenever the user executes an listview item. - * That means depending on the KDE wide Single Click/Double Click - * setting the user clicked or double clicked on that item. - * @param item is the pointer to the executed listview item. - * @param pos is the position where the user has clicked - * @param c is the column into which the user clicked. - * - * Note that you may not delete any TQListViewItem objects in slots - * connected to this signal. - */ - void executed( TQListViewItem *item, const TQPoint &pos, int c ); - - /** - * This signal gets emitted whenever something acceptable is - * dropped onto the listview. - * - * @param e is the drop event itself (it has already been accepted) - * @param after is the item after which the drop occurred (or 0L, if - * the drop was above all items) - * - * @see acceptDrop() - */ - void dropped (TQDropEvent * e, TQListViewItem *after); - - /** - * This signal gets emitted whenever something acceptable is - * dropped onto the listview. - * - * This is an overloaded version of the above (provided to simplify - * processing drops outside of the class). - * - * @param list is the listview - * @param e is the drop event itself (it has already been accepted) - * @param after is the item after which the drop occurred (or 0L, if - * the drop was above all items - */ - void dropped (TDEListView* list, TQDropEvent* e, TQListViewItem* after); - - /** - * This signal gets emitted whenever something acceptable is - * dropped onto the listview. - * - * This function also provides a parent, in the event that your listview - * is a tree - * @param list is the listview - * @param e is the drop event itself (it has already been accepted) - * @param parent the item that is to be the parent of the new item - * @param after is the item after which the drop occurred (or 0L, if - * the drop was above all items - */ - void dropped (TDEListView* list, TQDropEvent* e, TQListViewItem* parent, TQListViewItem* after); - - /** - * This signal gets emitted whenever something acceptable is - * dropped onto the listview. - * - * This function also provides a parent, in the event that your listview - * is a tree - * @param e is the drop event itself (it has already been accepted) - * @param parent the item that is to be the parent of the new item - * @param after is the item after which the drop occurred (or 0L, if - * the drop was above all items - */ - void dropped (TQDropEvent* e, TQListViewItem* parent, TQListViewItem* after); - - /** - * This signal is emitted when ever the user moves an item in the list via - * DnD. - * If more than one item is moved at the same time, this signal is only emitted - * once. - */ - void moved(); - - /** - * Connect to this signal if you want to do some preprocessing before - * a move is made, for example, to disable sorting - * - * This is sent only once per each groups of moves. That is, for each - * drop that is a move this will be emitted once, before TDEListView calls - * @see moveItem() - */ - void aboutToMove(); - - /** - * This signal is emitted when ever the user moves an item in the list via - * DnD. - * If more than one item is moved at the same time, @p afterFirst and - * @p afterNow will reflect what was true before the move. - * This differs from moved(), so be careful. All the items will have been - * moved before moved() is emitted, which is not true in this method. // FIXME - * @param item the item that was moved - * @param afterFirst the item that parameter item was in before the move, in the list - * @param afterNow the item it's currently after. - */ - void moved (TQListViewItem *item, TQListViewItem *afterFirst, TQListViewItem *afterNow); - - - /** - * This signal is emitted after all the items have been moved. It reports info for - * each and every item moved, in order. The first element in @p items associates - * with the first of afterFirst and afterNow. - */ - void moved(TQPtrList &items, TQPtrList &afterFirst, TQPtrList &afterNow); - - /** - * This signal gets emitted when an item is renamed via in-place renaming. - * - * @param item is the renamed item. - * @param str is the new value of column @p col. - * @param col is the renamed column. - */ - void itemRenamed(TQListViewItem* item, const TQString &str, int col); - - /** - * Same as above, but without the extra information. - */ - void itemRenamed(TQListViewItem* item); - - /** - * This signal is emitted when the shortcut key for popup-menus is pressed. - * - * Normally you should not use this, just connect a slot to signal - * contextMenu (TDEListView*, TQListViewItem*, const TQPoint&) to correctly - * handle showing context menus regardless of settings. - * - * @param list is this listview. - * @param item is the currentItem() at the time the key was pressed. May be 0L. - */ - void menuShortCutPressed (TDEListView* list, TQListViewItem* item); - - /** - * This signal is emitted whenever a context-menu should be shown for item @p i. - * It automatically adjusts for all settings involved (Menu key, showMenuOnPress/Click). - * - * @param l is this listview. - * @param i is the item for which the menu should be shown. May be 0L. - * @param p is the point at which the menu should be shown. - */ - void contextMenu (TDEListView* l, TQListViewItem* i, const TQPoint& p); - - void itemAdded(TQListViewItem *item); - void itemRemoved(TQListViewItem *item); - -public slots: - /** - * Rename column @p c of @p item. - */ - virtual void rename(TQListViewItem *item, int c); - - /** - * By default, if you called setItemsRenameable(true), - * only the first column is renameable. - * Use this function to enable the feature on other columns. - * - * If you want more intelligent (dynamic) selection, - * you'll have to derive from TDEListView, - * and override rename() and call only call it - * if you want the item to be renamed. - */ - void setRenameable (int column, bool yesno=true); - - /** - * Set whether items in the list view can be moved. - * It is enabled by default. - * - * @see itemsMovable() - */ - virtual void setItemsMovable(bool b); - - /** - * Enables inplace-renaming of items. - * It is disabled by default. - * - * @see itemsRenameable() - * @see setRenameable() - */ - virtual void setItemsRenameable(bool b); - - /** - * Enable/Disable the dragging of items. - * It is disabled by default. - */ - virtual void setDragEnabled(bool b); - - /** - * Enable/Disable AutoOpen (not implemented currently). - */ - virtual void setAutoOpen(bool b); - - /** - * Enable/Disable the drawing of a drop-visualizer - * (a bar that shows where a dropped item would be inserted). - * It is enabled by default, if dragging is enabled - */ - virtual void setDropVisualizer(bool b); - - /** - * Set the width of the (default) drop-visualizer. - * If you don't call this method, the width is set to 4. - */ - void setDropVisualizerWidth (int w); - - /** - * Set which column should be used for automatic tooltips. - * - * @param column is the column for which tooltips will be shown. - * Set -1 to disable this feature. - */ - virtual void setTooltipColumn(int column); - - /** - * Enable/Disable the drawing of a drop-highlighter - * (a rectangle around the item under the mouse cursor). - * It is disabled by default. - */ - virtual void setDropHighlighter(bool b); - - /** - * For future expansions. - * - * Do not use. - * @deprecated - */ - virtual void setCreateChildren(bool b) KDE_DEPRECATED; - - /** - * Set the selection mode. - * - * A different name was chosen to avoid API-clashes with TQListView::setSelectionMode(). - */ - void setSelectionModeExt (SelectionModeExt mode); - - /** - * Enable/disable tabbing between editable cells - * @since 3.1 - */ - void setTabOrderedRenaming(bool b); - - /** - * Returns whether tab ordered renaming is enabled - * @since 3.1 - */ - bool tabOrderedRenaming() const; - - /** - * Override TQListView selectAll() so that filtered - * items are not selected - * - * @since 14.0 - */ - virtual void selectAll( bool select ); - -protected: - /** - * Determine whether a drop on position @p p would count as - * being above or below the TQRect @p rect. - * - * @param rect is the rectangle we examine. - * @param p is the point located in the rectangle, p is assumed to be in - * viewport coordinates. - */ - inline bool below (const TQRect& rect, const TQPoint& p) - { - return (p.y() > (rect.top() + (rect.bottom() - rect.top())/2)); - } - - /** - * An overloaded version of below(const TQRect&, const TQPoint&). - * - * It differs from the above only in what arguments it takes. - * - * @param i the item whose rect() is passed to the above function. - * @param p is translated from contents coordinates to viewport coordinates - * before being passed to the above function. - */ - inline bool below (TQListViewItem* i, const TQPoint& p) - { - return below (itemRect(i), contentsToViewport(p)); - } - - /** - * Reimplemented to reload the alternate background in palette changes. - * @internal - */ - virtual bool event( TQEvent * ); - - /** - * Emit signal executed. - * @internal - */ - void emitExecute( TQListViewItem *item, const TQPoint &pos, int c ); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void focusInEvent(TQFocusEvent* fe); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void focusOutEvent( TQFocusEvent *fe ); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void leaveEvent( TQEvent *e ); - - /** - * @return the tooltip for @p column of @p item. - */ - virtual TQString tooltip(TQListViewItem* item, int column) const; - - /** - * @return whether the tooltip for @p column of @p item shall be shown at point @p pos. - */ - virtual bool showTooltip(TQListViewItem *item, const TQPoint &pos, int column) const; - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void contentsDragMoveEvent (TQDragMoveEvent *event); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void contentsMousePressEvent( TQMouseEvent *e ); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void contentsMouseMoveEvent( TQMouseEvent *e ); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void contentsMouseDoubleClickEvent ( TQMouseEvent *e ); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void contentsDragLeaveEvent (TQDragLeaveEvent *event); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void contentsMouseReleaseEvent (TQMouseEvent*); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void contentsDropEvent (TQDropEvent*); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void contentsDragEnterEvent (TQDragEnterEvent *); - - /** - * @return a dragobject encoding the current selection. - * - * @see setDragEnabled() - */ - virtual TQDragObject *dragObject(); - - /** - * @return true if the @p event provides some acceptable - * format. - * A common mistake is to forget the "const" in your reimplementation - */ - virtual bool acceptDrag (TQDropEvent* event) const; - - /** - * Paint the drag line. If painter is null, don't try to :) - * - * If after == 0 then the marker should be drawn at the top. - * - * @return the rectangle that you painted to. - */ - virtual TQRect drawDropVisualizer (TQPainter *p, TQListViewItem *parent, TQListViewItem *after); - - /** - * Paint the drag rectangle. If painter is null, don't try to :) - * - * - * @return the rectangle that you painted to. - */ - virtual TQRect drawItemHighlighter(TQPainter *painter, TQListViewItem *item); - - /** - * This method calls dragObject() and starts the drag. - * - * Reimplement it to do fancy stuff like setting a pixmap or - * using a non-default DragMode - */ - virtual void startDrag(); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void keyPressEvent (TQKeyEvent*); - - /** - * Reimplemented for internal reasons. - * Further reimplementations should call this function or else - * some features may not work correctly. - * - * The API is unaffected. - */ - virtual void viewportPaintEvent(TQPaintEvent*); - - /** - * In FileManager selection mode: explicitly activate the mode - * in which the current item is automatically selected. - */ - void activateAutomaticSelection(); - /** - * In FileManager selection mode: explicitly deactivate the mode - * in which the current item is automatically selected. - */ - void deactivateAutomaticSelection(); - /** - * In FileManager selection mode: return whether it is currently in the mode - * where the current item is selected automatically. - * Returns false if items were selected explicitly, e.g. using the mouse. - */ - bool automaticSelection() const; - - /** - * Reimplemented for setFullWidth() - */ - virtual void viewportResizeEvent(TQResizeEvent* e); - - /** - * Disable AutoSelection. This overrides the system wide setting for - * AutoSelection. Please don't call this unless you have good reasons to - * override the system wide setting for AutoSelection. - * @see resetAutoSelection() - * @since 3.2 - */ - void disableAutoSelection(); - - /** - * Reset AutoSelection to the system wide setting. - * @see disableAutoSelection() - * @since 3.2 - */ - void resetAutoSelection(); - - /** - * @deprecated This is just here for binary compatibility. Use the signal - * in TQListView instead. - */ - // KDE 4: remove - void doubleClicked( TQListViewItem *item, const TQPoint &pos, int c ); - -protected slots: - /** - * Update internal settings whenever the global ones change. - * @internal - */ - void slotSettingsChanged(int); - - void slotMouseButtonClicked( int btn, TQListViewItem *item, const TQPoint &pos, int c ); - void doneEditing(TQListViewItem *item, int row); - - /** - * Repaint the rect where I was drawing the drop line. - */ - void cleanDropVisualizer(); - - /** - * Repaint the rect where I was drawing the drop rectangle. - */ - void cleanItemHighlighter(); - - /** - * Emit the contextMenu signal. This slot is for mouse actions. - */ - void emitContextMenu (TQListViewItem*, const TQPoint&, int); - - /** - * Emit the contextMenu signal. This slot is for key presses. - */ - void emitContextMenu (TDEListView*, TQListViewItem*); - - /** - * Accessory slot for AutoSelect - * @internal - */ - void slotOnItem( TQListViewItem *item ); - - /** - * Accessory slot for AutoSelect/ChangeCursorOverItem - * @internal - */ - void slotOnViewport(); - - /** - * Process AutoSelection. - * @internal - */ - void slotAutoSelect(); - - void slotDragExpand(); - - /** - * Reacts to header changes in full width mode - * @internal - */ - void slotHeaderChanged(); - -protected: - /** - * Handle dropEvent when itemsMovable() is set to true. - */ - virtual void movableDropEvent (TQListViewItem* parent, TQListViewItem* afterme); - - /** - * Where is the nearest TQListViewItem that I'm going to drop? - * - * FIXME KDE 4.0: Make this method const so it can be called from an - * acceptDrag method without ugly casts - */ - virtual void findDrop(const TQPoint &pos, TQListViewItem *&parent, TQListViewItem *&after); - - /** - * A special keyPressEvent (for FileManager selection mode). - */ - void fileManagerKeyPressEvent (TQKeyEvent*); - - /** - * Convert the depth of an item into its indentation in pixels - */ - int depthToPixels( int depth ); - -private: - class Tooltip; -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEListViewPrivate; - TDEListViewPrivate* const d; - bool isExecuteArea( int x, TQListViewItem* item ); -}; - -/** - * A listview item with support for alternate background colors. It is - * a drop-in replacement for QListViewItem - * - * @short listview item with alternate background color support - */ -class TDEUI_EXPORT TDEListViewItem : public TQListViewItem -{ - friend class TDEListView; -public: - /** - * constructors. The semantics remain as in TQListViewItem. - * Although they accept a TQListViewItem as parent, please - * don't mix TDEListViewItem (or subclasses) with QListViewItem - * (or subclasses). - */ - TDEListViewItem(TQListView *parent); - TDEListViewItem(TQListViewItem *parent); - TDEListViewItem(TQListView *parent, TQListViewItem *after); - TDEListViewItem(TQListViewItem *parent, TQListViewItem *after); - - TDEListViewItem(TQListView *parent, - TQString, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null); - - TDEListViewItem(TQListViewItem *parent, - TQString, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null); - - TDEListViewItem(TQListView *parent, TQListViewItem *after, - TQString, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null); - - TDEListViewItem(TQListViewItem *parent, TQListViewItem *after, - TQString, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null, - TQString = TQString::null, TQString = TQString::null); - - virtual ~TDEListViewItem(); - - virtual void insertItem(TQListViewItem *item); - virtual void takeItem(TQListViewItem *item); - /** - * returns true if this item is to be drawn with the alternate background - */ - bool isAlternate(); - /** - * returns the background color for this item - */ - const TQColor &backgroundColor() KDE_DEPRECATED; // #### should be removed in 4.0; use below instead - - /** - * returns the background color for this item at given column - * This can be different in the column which is sorted due to shading - * ### could be merged with above (column = -1) to be source compatible - * ### but will only work if sort-shading is not used or the listView has - * ### only 1 column - * @since 3.4 - */ - TQColor backgroundColor(int column); - - virtual void paintCell(TQPainter *p, const TQColorGroup &cg, - int column, int width, int alignment); - -private: - void init(); - -private: - uint m_odd : 1; - uint m_known : 1; - uint m_unused : 30; -}; - -#endif - -// vim: ts=2 sw=2 et diff --git a/tdeui/klistviewlineedit.h b/tdeui/klistviewlineedit.h deleted file mode 100644 index d0019698e..000000000 --- a/tdeui/klistviewlineedit.h +++ /dev/null @@ -1,65 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2000 Charles Samuels - - 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 KLISTVIEWLINEEDIT_H -#define KLISTVIEWLINEEDIT_H - -#include -#include - -/** - * the editor for a TDEListView. please don't use this. - * @internal - **/ -class TDEUI_EXPORT TDEListViewLineEdit : public KLineEdit -{ -Q_OBJECT -public: - TDEListViewLineEdit(TDEListView *parent); - ~TDEListViewLineEdit(); - - TQListViewItem *currentItem() const; - -signals: - void done(TQListViewItem*, int); - -public slots: - void terminate(); - void load(TQListViewItem *i, int c); - -protected: - virtual void focusOutEvent(TQFocusEvent *); - virtual void keyPressEvent(TQKeyEvent *e); - virtual void paintEvent(TQPaintEvent *e); - virtual bool event (TQEvent *pe); - - /// @since 3.1 - void selectNextCell (TQListViewItem *pi, int column, bool forward); - void terminate(bool commit); - TQListViewItem *item; - int col; - TDEListView* const p; - -protected slots: - void slotSelectionChanged(); - - /// @since 3.5.4 - void slotItemRemoved(TQListViewItem *i); - -}; - -#endif diff --git a/tdeui/klistviewsearchline.cpp b/tdeui/klistviewsearchline.cpp deleted file mode 100644 index 96bf82370..000000000 --- a/tdeui/klistviewsearchline.cpp +++ /dev/null @@ -1,501 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (c) 2003 Scott Wheeler - - 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. -*/ - -#include "klistviewsearchline.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID 2004 - -class TDEListViewSearchLine::TDEListViewSearchLinePrivate -{ -public: - TDEListViewSearchLinePrivate() : - listView(0), - caseSensitive(false), - activeSearch(false), - keepParentsVisible(true), - queuedSearches(0) {} - - TDEListView *listView; - bool caseSensitive; - bool activeSearch; - bool keepParentsVisible; - TQString search; - int queuedSearches; - TQValueList searchColumns; -}; - -//////////////////////////////////////////////////////////////////////////////// -// public methods -//////////////////////////////////////////////////////////////////////////////// - -TDEListViewSearchLine::TDEListViewSearchLine(TQWidget *parent, TDEListView *listView, const char *name) : - KLineEdit(parent, name) -{ - d = new TDEListViewSearchLinePrivate; - - d->listView = listView; - - connect(this, TQT_SIGNAL(textChanged(const TQString &)), - this, TQT_SLOT(queueSearch(const TQString &))); - - if(listView) { - connect(listView, TQT_SIGNAL(destroyed()), - this, TQT_SLOT(listViewDeleted())); - - connect(listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), - this, TQT_SLOT(itemAdded(TQListViewItem *))); - } - else - setEnabled(false); -} - -TDEListViewSearchLine::TDEListViewSearchLine(TQWidget *parent, const char *name) : - KLineEdit(parent, name) -{ - d = new TDEListViewSearchLinePrivate; - - d->listView = 0; - - connect(this, TQT_SIGNAL(textChanged(const TQString &)), - this, TQT_SLOT(queueSearch(const TQString &))); - - setEnabled(false); -} - -TDEListViewSearchLine::~TDEListViewSearchLine() -{ - delete d; -} - -bool TDEListViewSearchLine::caseSensitive() const -{ - return d->caseSensitive; -} - -TQValueList TDEListViewSearchLine::searchColumns() const -{ - return d->searchColumns; -} - -bool TDEListViewSearchLine::keepParentsVisible() const -{ - return d->keepParentsVisible; -} - -TDEListView *TDEListViewSearchLine::listView() const -{ - return d->listView; -} - -//////////////////////////////////////////////////////////////////////////////// -// public slots -//////////////////////////////////////////////////////////////////////////////// - -void TDEListViewSearchLine::updateSearch(const TQString &s) -{ - if(!d->listView) - return; - - d->search = s.isNull() ? text() : s; - - // If there's a selected item that is visible, make sure that it's visible - // when the search changes too (assuming that it still matches). - - TQListViewItem *currentItem = 0; - - switch(d->listView->selectionMode()) - { - case TDEListView::NoSelection: - break; - case TDEListView::Single: - currentItem = d->listView->selectedItem(); - break; - default: - { - int flags = TQListViewItemIterator::Selected | TQListViewItemIterator::Visible; - for(TQListViewItemIterator it(d->listView, flags); - it.current() && !currentItem; - ++it) - { - if(d->listView->itemRect(it.current()).isValid()) - currentItem = it.current(); - } - } - } - - if(d->keepParentsVisible) - checkItemParentsVisible(d->listView->firstChild()); - else - checkItemParentsNotVisible(); - - if(currentItem) - d->listView->ensureItemVisible(currentItem); -} - -void TDEListViewSearchLine::setCaseSensitive(bool cs) -{ - d->caseSensitive = cs; -} - -void TDEListViewSearchLine::setKeepParentsVisible(bool v) -{ - d->keepParentsVisible = v; -} - -void TDEListViewSearchLine::setSearchColumns(const TQValueList &columns) -{ - d->searchColumns = columns; -} - -void TDEListViewSearchLine::setListView(TDEListView *lv) -{ - if(d->listView) { - disconnect(d->listView, TQT_SIGNAL(destroyed()), - this, TQT_SLOT(listViewDeleted())); - - disconnect(d->listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), - this, TQT_SLOT(itemAdded(TQListViewItem *))); - } - - d->listView = lv; - - if(lv) { - connect(d->listView, TQT_SIGNAL(destroyed()), - this, TQT_SLOT(listViewDeleted())); - - connect(d->listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), - this, TQT_SLOT(itemAdded(TQListViewItem *))); - } - - setEnabled(bool(lv)); -} - -//////////////////////////////////////////////////////////////////////////////// -// protected members -//////////////////////////////////////////////////////////////////////////////// - -bool TDEListViewSearchLine::itemMatches(const TQListViewItem *item, const TQString &s) const -{ - if(s.isEmpty()) - return true; - - // If the search column list is populated, search just the columns - // specifified. If it is empty default to searching all of the columns. - - if(!d->searchColumns.isEmpty()) { - TQValueList::ConstIterator it = d->searchColumns.begin(); - for(; it != d->searchColumns.end(); ++it) { - if(*it < item->listView()->columns() && - item->text(*it).find(s, 0, d->caseSensitive) >= 0) - return true; - } - } - else { - for(int i = 0; i < item->listView()->columns(); i++) { - if(item->listView()->columnWidth(i) > 0 && - item->text(i).find(s, 0, d->caseSensitive) >= 0) - { - return true; - } - } - } - - return false; -} - -TQPopupMenu *TDEListViewSearchLine::createPopupMenu() -{ - TQPopupMenu *popup = KLineEdit::createPopupMenu(); - - if (d->listView->columns()>1) { - TQPopupMenu *subMenu = new TQPopupMenu(popup); - connect(subMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(searchColumnsMenuActivated(int))); - - popup->insertSeparator(); - popup->insertItem(i18n("Search Columns"), subMenu); - - subMenu->insertItem(i18n("All Visible Columns"), KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID); - subMenu->insertSeparator(); - - bool allColumnsAreSearchColumns = true; - // TODO Make the entry order match the actual column order - TQHeader* const header = d->listView->header(); - int visibleColumns = 0; - for(int i = 0; i < d->listView->columns(); i++) { - if(d->listView->columnWidth(i)>0) { - TQString columnText = d->listView->columnText(i); - if(columnText.isEmpty()) { - int visiblePosition=1; - for(int j = 0; j < header->mapToIndex(i); j++) - if(d->listView->columnWidth(header->mapToSection(j))>0) - visiblePosition++; - columnText = i18n("Column number %1","Column No. %1").arg(visiblePosition); - } - subMenu->insertItem(columnText, visibleColumns); - if(d->searchColumns.isEmpty() || d->searchColumns.find(i) != d->searchColumns.end()) - subMenu->setItemChecked(visibleColumns, true); - else - allColumnsAreSearchColumns = false; - visibleColumns++; - } - } - subMenu->setItemChecked(KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID, allColumnsAreSearchColumns); - - // searchColumnsMenuActivated() relies on one possible "all" representation - if(allColumnsAreSearchColumns && !d->searchColumns.isEmpty()) - d->searchColumns.clear(); - } - - return popup; -} - -//////////////////////////////////////////////////////////////////////////////// -// protected slots -//////////////////////////////////////////////////////////////////////////////// - -void TDEListViewSearchLine::queueSearch(const TQString &search) -{ - d->queuedSearches++; - d->search = search; - TQTimer::singleShot(200, this, TQT_SLOT(activateSearch())); -} - -void TDEListViewSearchLine::activateSearch() -{ - --(d->queuedSearches); - - if(d->queuedSearches == 0) - updateSearch(d->search); -} - -//////////////////////////////////////////////////////////////////////////////// -// private slots -//////////////////////////////////////////////////////////////////////////////// - -void TDEListViewSearchLine::itemAdded(TQListViewItem *item) const -{ - item->setVisible(itemMatches(item, text())); -} - -void TDEListViewSearchLine::listViewDeleted() -{ - d->listView = 0; - setEnabled(false); -} - -void TDEListViewSearchLine::searchColumnsMenuActivated(int id) -{ - if(id == KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID) { - if(d->searchColumns.isEmpty()) - d->searchColumns.append(0); - else - d->searchColumns.clear(); - } - else { - if(d->searchColumns.find(id) != d->searchColumns.end()) - d->searchColumns.remove(id); - else { - if(d->searchColumns.isEmpty()) { - for(int i = 0; i < d->listView->columns(); i++) { - if(i != id) - d->searchColumns.append(i); - } - } - else - d->searchColumns.append(id); - } - } - updateSearch(); -} - -//////////////////////////////////////////////////////////////////////////////// -// private methods -//////////////////////////////////////////////////////////////////////////////// - -void TDEListViewSearchLine::checkItemParentsNotVisible() -{ - TQListViewItemIterator it(d->listView); - for(; it.current(); ++it) - { - TQListViewItem *item = it.current(); - if(itemMatches(item, d->search)) - item->setVisible(true); - else - item->setVisible(false); - } -} - -#include - -/** Check whether \p item, its siblings and their descendents should be shown. Show or hide the items as necessary. - * - * \p item The list view item to start showing / hiding items at. Typically, this is the first child of another item, or the - * the first child of the list view. - * \p highestHiddenParent The highest (closest to root) ancestor of \p item which is hidden. If 0, all parents of - * \p item must be visible. - * \return \c true if an item which should be visible is found, \c false if all items found should be hidden. If this function - * returns true and \p highestHiddenParent was not 0, highestHiddenParent will have been shown. - */ -bool TDEListViewSearchLine::checkItemParentsVisible(TQListViewItem *item, TQListViewItem *highestHiddenParent) -{ - bool visible = false; - TQListViewItem * first = item; - for(; item; item = item->nextSibling()) - { - //What we pass to our children as highestHiddenParent: - TQListViewItem * hhp = highestHiddenParent ? highestHiddenParent : item->isVisible() ? 0L : item; - bool childMatch = false; - if(item->firstChild() && checkItemParentsVisible(item->firstChild(), hhp)) - childMatch = true; - // Should this item be shown? It should if any children should be, or if it matches. - if(childMatch || itemMatches(item, d->search)) - { - visible = true; - if (highestHiddenParent) - { - highestHiddenParent->setVisible(true); - // Calling setVisible on our ancestor will unhide all its descendents. Hide the ones - // before us that should not be shown. - for(TQListViewItem *hide = first; hide != item; hide = hide->nextSibling()) - hide->setVisible(false); - highestHiddenParent = 0; - // If we matched, than none of our children matched, yet the setVisible() call on our - // ancestor unhid them, undo the damage: - if(!childMatch) - for(TQListViewItem *hide = item->firstChild(); hide; hide = hide->nextSibling()) - hide->setVisible(false); - } - else - item->setVisible(true); - } - else - item->setVisible(false); - } - return visible; -} - -//////////////////////////////////////////////////////////////////////////////// -// TDEListViewSearchLineWidget -//////////////////////////////////////////////////////////////////////////////// - -class TDEListViewSearchLineWidget::TDEListViewSearchLineWidgetPrivate -{ -public: - TDEListViewSearchLineWidgetPrivate() : listView(0), searchLine(0), clearButton(0) {} - TDEListView *listView; - TDEListViewSearchLine *searchLine; - TQToolButton *clearButton; -}; - -TDEListViewSearchLineWidget::TDEListViewSearchLineWidget(TDEListView *listView, - TQWidget *parent, - const char *name) : - TQHBox(parent, name) -{ - d = new TDEListViewSearchLineWidgetPrivate; - d->listView = listView; - - setSpacing(5); - - TQTimer::singleShot(0, this, TQT_SLOT(createWidgets())); -} - -TDEListViewSearchLineWidget::~TDEListViewSearchLineWidget() -{ - delete d; -} - -TDEListViewSearchLine *TDEListViewSearchLineWidget::createSearchLine(TDEListView *listView) -{ - if(!d->searchLine) - d->searchLine = new TDEListViewSearchLine(this, listView); - return d->searchLine; -} - -void TDEListViewSearchLineWidget::createWidgets() -{ - positionInToolBar(); - - if(!d->clearButton) { - d->clearButton = new TQToolButton(this); - TQIconSet icon = SmallIconSet(TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase"); - d->clearButton->setIconSet(icon); - } - - d->clearButton->show(); - - TQLabel *label = new TQLabel(i18n("S&earch:"), this, "kde toolbar widget"); - - d->searchLine = createSearchLine(d->listView); - d->searchLine->show(); - - label->setBuddy(d->searchLine); - label->show(); - - connect(d->clearButton, TQT_SIGNAL(clicked()), d->searchLine, TQT_SLOT(clear())); -} - -TDEListViewSearchLine *TDEListViewSearchLineWidget::searchLine() const -{ - return d->searchLine; -} - -void TDEListViewSearchLineWidget::positionInToolBar() -{ - TDEToolBar *toolBar = tqt_dynamic_cast(parent()); - - if(toolBar) { - - // Here we have The Big Ugly. Figure out how many widgets are in the - // and do a hack-ish iteration over them to find this widget so that we - // can insert the clear button before it. - - int widgetCount = toolBar->count(); - - for(int index = 0; index < widgetCount; index++) { - int id = toolBar->idAt(index); - if(toolBar->getWidget(id) == this) { - toolBar->setItemAutoSized(id); - if(!d->clearButton) { - TQString icon = TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase"; - d->clearButton = new TDEToolBarButton(icon, 2005, toolBar); - } - toolBar->insertWidget(2005, d->clearButton->width(), d->clearButton, index); - break; - } - } - } - - if(d->searchLine) - d->searchLine->show(); -} - -#include "klistviewsearchline.moc" diff --git a/tdeui/klistviewsearchline.h b/tdeui/klistviewsearchline.h deleted file mode 100644 index 4c278a9d9..000000000 --- a/tdeui/klistviewsearchline.h +++ /dev/null @@ -1,264 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (c) 2003 Scott Wheeler - - 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 KLISTVIEWSEARCHLINE_H -#define KLISTVIEWSEARCHLINE_H - -#include -#include - -class TDEListView; -class TQListViewItem; -class TQToolButton; - -/** - * This class makes it easy to add a search line for filtering the items in a - * listview based on a simple text search. - * - * No changes to the application other than instantiating this class with an - * appropriate TDEListView should be needed. - * - * If you want the clear button and the search label, you should take a look at - * the TDEListViewSearchLineWidget - * - * @note { When iterating over items in the TDEListView, make sure that - * the iterator only includes visible items (for example, by adding - * TQListViewItemIterator::Visible to the iterator flags). Otherwise, - * actions (such as deletion) may be taken on items that have been - * hidden by the search function. } - * @since 3.3 - */ - -class TDEUI_EXPORT TDEListViewSearchLine : public KLineEdit -{ - Q_OBJECT - -public: - - /** - * Constructs a TDEListViewSearchLine with \a listView being the TDEListView to - * be filtered. - * - * If \a listView is null then the widget will be disabled until a listview - * is set with setListView(). - */ - TDEListViewSearchLine(TQWidget *parent = 0, TDEListView *listView = 0, const char *name = 0); - - /** - * Constructs a TDEListViewSearchLine without any TDEListView to filter. The - * TDEListView object has to be set later with setListView(). - */ - TDEListViewSearchLine(TQWidget *parent, const char *name); - - /** - * Destroys the TDEListViewSearchLine. - */ - virtual ~TDEListViewSearchLine(); - - /** - * Returns true if the search is case sensitive. This defaults to false. - * - * @see setCaseSensitive() - */ - bool caseSensitive() const; - - /** - * Returns the current list of columns that will be searched. If the - * returned list is empty all visible columns will be searched. - * - * @see setSearchColumns - */ - TQValueList searchColumns() const; - - /** - * If this is true (the default) then the parents of matched items will also - * be shown. - * - * @see setKeepParentsVisible() - */ - bool keepParentsVisible() const; - - /** - * Returns the listview that is currently filtered by the search. - * - * @see setListView() - */ - TDEListView *listView() const; - -public slots: - /** - * Updates search to only make visible the items that match \a s. If - * \a s is null then the line edit's text will be used. - */ - virtual void updateSearch(const TQString &s = TQString::null); - - /** - * Make the search case sensitive or case insensitive. - * - * @see caseSenstive() - */ - void setCaseSensitive(bool cs); - - /** - * When a search is active on a list that's organized into a tree view if - * a parent or ancesestor of an item is does not match the search then it - * will be hidden and as such so too will any children that match. - * - * If this is set to true (the default) then the parents of matching items - * will be shown. - * - * @see keepParentsVisible - */ - void setKeepParentsVisible(bool v); - - /** - * Sets the list of columns to be searched. The default is to search all, - * visible columns which can be restored by passing \a columns as an empty - * list. - * - * @see searchColumns - */ - void setSearchColumns(const TQValueList &columns); - - /** - * Sets the TDEListView that is filtered by this search line. If \a lv is null - * then the widget will be disabled. - * - * @see listView() - */ - void setListView(TDEListView *lv); - -protected: - - /** - * Returns true if \a item matches the search \a s. This will be evaluated - * based on the value of caseSensitive(). This can be overridden in - * subclasses to implement more complicated matching schemes. - */ - virtual bool itemMatches(const TQListViewItem *item, const TQString &s) const; - - /** - * Re-implemented for internal reasons. API not affected. - * - * See TQLineEdit::mousePressEvent(). - */ - virtual TQPopupMenu *createPopupMenu(); - -protected slots: - /** - * When keys are pressed a new search string is created and a timer is - * activated. The most recent search is activated when this timer runs out - * if another key has not yet been pressed. - * - * This method makes @param search the most recent search and starts the - * timer. - * - * Together with activateSearch() this makes it such that searches are not - * started until there is a short break in the users typing. - * - * @see activateSearch() - */ - void queueSearch(const TQString &search); - - /** - * When the timer started with queueSearch() expires this slot is called. - * If there has been another timer started then this slot does nothing. - * However if there are no other pending searches this starts the list view - * search. - * - * @see queueSearch() - */ - void activateSearch(); - -private: - - /** - * This is used in case parent items of matching items shouldn't be - * visible. It hides all items that don't match the search string. - */ - void checkItemParentsNotVisible(); - - /** - * This is used in case parent items of matching items should be visible. - * It makes a recursive call to all children. It returns true if at least - * one item in the subtree with the given root item is visible. - */ - bool checkItemParentsVisible(TQListViewItem *item, TQListViewItem *highestHiddenParent = 0); - -private slots: - void itemAdded(TQListViewItem *item) const; - void listViewDeleted(); - void searchColumnsMenuActivated(int); - -private: - class TDEListViewSearchLinePrivate; - TDEListViewSearchLinePrivate *d; -}; - -/** - * Creates a widget featuring a TDEListViewSearchLine, a label with the text - * "Search" and a button to clear the search. - * - * @since 3.4 - */ -class TDEUI_EXPORT TDEListViewSearchLineWidget : public TQHBox -{ - Q_OBJECT - -public: - /** - * Creates a TDEListViewSearchLineWidget for \a listView with \a parent as the - * parent with and \a name. - */ - TDEListViewSearchLineWidget(TDEListView *listView = 0, TQWidget *parent = 0, - const char *name = 0); - - /** - * Destroys the TDEListViewSearchLineWidget - */ - ~TDEListViewSearchLineWidget(); - - /** - * Creates the search line. This can be useful to reimplement in cases where - * a TDEListViewSearchLine subclass is used. - */ - virtual TDEListViewSearchLine *createSearchLine(TDEListView *listView); - - /** - * Returns a pointer to the search line. - */ - TDEListViewSearchLine *searchLine() const; - -protected slots: - /** - * Creates the widgets inside of the widget. This is called from the - * constructor via a single shot timer so that it it guaranteed to run - * after construction is complete. This makes it suitable for overriding in - * subclasses. - */ - virtual void createWidgets(); - -private slots: - void positionInToolBar(); - -private: - class TDEListViewSearchLineWidgetPrivate; - TDEListViewSearchLineWidgetPrivate *d; -}; - -#endif diff --git a/tdeui/kmainwindow.cpp b/tdeui/kmainwindow.cpp deleted file mode 100644 index 743c273cc..000000000 --- a/tdeui/kmainwindow.cpp +++ /dev/null @@ -1,1249 +0,0 @@ - /* This file is part of the KDE libraries - Copyright - (C) 2000 Reginald Stadlbauer (reggie@kde.org) - (C) 1997 Stephan Kulow (coolo@kde.org) - (C) 1997-2000 Sven Radej (radej@kde.org) - (C) 1997-2000 Matthias Ettrich (ettrich@kde.org) - (C) 1999 Chris Schlaeger (cs@kde.org) - (C) 2002 Joseph Wenninger (jowenn@kde.org) - - 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. - */ -#include "config.h" - -#include "kmainwindow.h" -#include "kmainwindowiface.h" -#include "ktoolbarhandler.h" -#include "kwhatsthismanager_p.h" -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#if defined Q_WS_X11 -#include -#endif - -#include -#include -#include - -class TDEMainWindowPrivate { -public: - bool showHelpMenu:1; - - bool autoSaveSettings:1; - bool settingsDirty:1; - bool autoSaveWindowSize:1; - bool care_about_geometry:1; - bool shuttingDown:1; - TQString autoSaveGroup; - TDEAccel * kaccel; - TDEMainWindowInterface *m_interface; - KDEPrivate::ToolBarHandler *toolBarHandler; - TQTimer* settingsTimer; - TDEToggleAction *showStatusBarAction; - TQRect defaultWindowSize; - TQPtrList hiddenDockWindows; -}; - -TQPtrList* TDEMainWindow::memberList = 0L; -static bool no_query_exit = false; -static KMWSessionManaged* ksm = 0; -static KStaticDeleter ksmd; - -class KMWSessionManaged : public KSessionManaged -{ -public: - KMWSessionManaged() - { - } - ~KMWSessionManaged() - { - } - bool saveState( TQSessionManager& ) - { - TDEConfig* config = TDEApplication::kApplication()->sessionConfig(); - if ( TDEMainWindow::memberList->first() ){ - // According to Jochen Wilhelmy , this - // hook is useful for better document orientation - TDEMainWindow::memberList->first()->saveGlobalProperties(config); - } - - TQPtrListIterator it(*TDEMainWindow::memberList); - int n = 0; - for (it.toFirst(); it.current(); ++it){ - n++; - it.current()->savePropertiesInternal(config, n); - } - config->setGroup(TQString::fromLatin1("Number")); - config->writeEntry(TQString::fromLatin1("NumberOfWindows"), n ); - return true; - } - - bool commitData( TQSessionManager& sm ) - { - // not really a fast method but the only compatible one - if ( sm.allowsInteraction() ) { - bool canceled = false; - TQPtrListIterator it(*TDEMainWindow::memberList); - ::no_query_exit = true; - for (it.toFirst(); it.current() && !canceled;){ - TDEMainWindow *window = *it; - ++it; // Update now, the current window might get deleted - if ( !window->testWState( TQt::WState_ForceHide ) ) { - TQCloseEvent e; - TQApplication::sendEvent( window, &e ); - canceled = !e.isAccepted(); - /* Don't even think_about deleting widgets with - Qt::WDestructiveClose flag set at this point. We - are faking a close event, but we are *not*_ - closing the window. The purpose of the faked - close event is to prepare the application so it - can safely be quit without the user losing data - (possibly showing a message box "do you want to - save this or that?"). It is possible that the - session manager quits the application later - (emitting TQApplication::aboutToQuit() when this - happens), but it is also possible that the user - cancels the shutdown, so the application will - continue to run. - */ - } - } - ::no_query_exit = false; - if (canceled) - return false; - - TDEMainWindow* last = 0; - for (it.toFirst(); it.current() && !canceled; ++it){ - TDEMainWindow *window = *it; - if ( !window->testWState( TQt::WState_ForceHide ) ) { - last = window; - } - } - if ( last ) - return last->queryExit(); - // else - return true; - } - - // the user wants it, the user gets it - return true; - } -}; - -static bool being_first = true; - -TDEMainWindow::TDEMainWindow( TQWidget* parent, const char *name, WFlags f ) - : TQMainWindow( parent, name, f ), KXMLGUIBuilder( this ), helpMenu2( 0 ), factory_( 0 ) -{ - initTDEMainWindow(name, 0); -} - -TDEMainWindow::TDEMainWindow( int cflags, TQWidget* parent, const char *name, WFlags f ) - : TQMainWindow( parent, name, f ), KXMLGUIBuilder( this ), helpMenu2( 0 ), factory_( 0 ) -{ - initTDEMainWindow(name, cflags); -} - -void TDEMainWindow::initTDEMainWindow(const char *name, int cflags) -{ - KWhatsThisManager::init (); - setDockMenuEnabled( false ); - mHelpMenu = 0; - kapp->setTopWidget( this ); - actionCollection()->setWidget( this ); - connect(kapp, TQT_SIGNAL(shutDown()), this, TQT_SLOT(shuttingDown())); - if( !memberList ) - memberList = new TQPtrList; - - if ( !ksm ) - ksm = ksmd.setObject(ksm, new KMWSessionManaged()); - // set a unique object name. Required by session management. - TQCString objname; - TQCString s; - int unusedNumber; - if ( !name ) - { // no name given - objname = kapp->instanceName() + "-mainwindow#"; - s = objname + '1'; // start adding number immediately - unusedNumber = 1; - } - else if( name[0] != '\0' && name[ strlen( name ) - 1 ] == '#' ) - { // trailing # - always add a number - objname = name; - s = objname + '1'; // start adding number immediately - unusedNumber = 1; - } - else - { - objname = name; - s = objname; - unusedNumber = 0; // add numbers only when needed - } - for(;;) { - TQWidgetList* list = kapp->topLevelWidgets(); - TQWidgetListIt it( *list ); - bool found = false; - for( TQWidget* w = it.current(); - w != NULL; - ++it, w = it.current()) - if( w != this && w->name() == s ) - { - found = true; - break; - } - delete list; - if( !found ) - break; - s.setNum( ++unusedNumber ); - s = objname + s; - } - setName( s ); - - memberList->append( this ); - - d = new TDEMainWindowPrivate; - d->showHelpMenu = true; - d->settingsDirty = false; - d->autoSaveSettings = false; - d->autoSaveWindowSize = true; // for compatibility - d->kaccel = actionCollection()->kaccel(); - d->toolBarHandler = 0; - d->settingsTimer = 0; - d->showStatusBarAction = NULL; - d->shuttingDown = false; - if ((d->care_about_geometry = being_first)) { - being_first = false; - if ( kapp->geometryArgument().isNull() ) // if there is no geometry, it doesn't mater - d->care_about_geometry = false; - else - parseGeometry(false); - } - - setCaption( kapp->caption() ); - if ( cflags & NoDCOPObject) - d->m_interface = 0; - else - d->m_interface = new TDEMainWindowInterface(this); - - if (!kapp->authorize("movable_toolbars")) - setDockWindowsMovable(false); -} - -TDEAction *TDEMainWindow::toolBarMenuAction() -{ - if ( !d->toolBarHandler ) - return 0; - - return d->toolBarHandler->toolBarMenuAction(); -} - - -void TDEMainWindow::setupToolbarMenuActions() -{ - if ( d->toolBarHandler ) - d->toolBarHandler->setupActions(); -} - -void TDEMainWindow::parseGeometry(bool parsewidth) -{ - assert ( !kapp->geometryArgument().isNull() ); - assert ( d->care_about_geometry ); - -#if defined Q_WS_X11 - int x, y; - int w, h; - int m = XParseGeometry( kapp->geometryArgument().latin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h); - if (parsewidth) { - TQSize minSize = minimumSize(); - TQSize maxSize = maximumSize(); - if ( !(m & WidthValue) ) - w = width(); - if ( !(m & HeightValue) ) - h = height(); - w = QMIN(w,maxSize.width()); - h = QMIN(h,maxSize.height()); - w = QMAX(w,minSize.width()); - h = QMAX(h,minSize.height()); - resize(w, h); - } else { - if ( parsewidth && !(m & XValue) ) - x = geometry().x(); - if ( parsewidth && !(m & YValue) ) - y = geometry().y(); - if ( (m & XNegative) ) - x = TDEApplication::desktop()->width() + x - w; - if ( (m & YNegative) ) - y = TDEApplication::desktop()->height() + y - h; - move(x, y); - } -#endif -} - -TDEMainWindow::~TDEMainWindow() -{ - delete d->settingsTimer; - TQMenuBar* mb = internalMenuBar(); - delete mb; - delete d->m_interface; - delete d; - memberList->remove( this ); -} - -TDEPopupMenu* TDEMainWindow::helpMenu( const TQString &aboutAppText, bool showWhatsThis ) -{ - if( !mHelpMenu ) { - if ( aboutAppText.isEmpty() ) - mHelpMenu = new KHelpMenu( this, instance()->aboutData(), showWhatsThis); - else - mHelpMenu = new KHelpMenu( this, aboutAppText, showWhatsThis ); - - if ( !mHelpMenu ) - return 0; - connect( mHelpMenu, TQT_SIGNAL( showAboutApplication() ), - this, TQT_SLOT( showAboutApplication() ) ); - } - - return mHelpMenu->menu(); -} - -TDEPopupMenu* TDEMainWindow::customHelpMenu( bool showWhatsThis ) -{ - if( !mHelpMenu ) { - mHelpMenu = new KHelpMenu( this, TQString::null, showWhatsThis ); - connect( mHelpMenu, TQT_SIGNAL( showAboutApplication() ), - this, TQT_SLOT( showAboutApplication() ) ); - } - - return mHelpMenu->menu(); -} - -bool TDEMainWindow::canBeRestored( int number ) -{ - if ( !kapp->isRestored() ) - return false; - TDEConfig *config = kapp->sessionConfig(); - if ( !config ) - return false; - config->setGroup( TQString::fromLatin1("Number") ); - int n = config->readNumEntry( TQString::fromLatin1("NumberOfWindows") , 1 ); - return number >= 1 && number <= n; -} - -const TQString TDEMainWindow::classNameOfToplevel( int number ) -{ - if ( !kapp->isRestored() ) - return TQString::null; - TDEConfig *config = kapp->sessionConfig(); - if ( !config ) - return TQString::null; - TQString s; - s.setNum( number ); - s.prepend( TQString::fromLatin1("WindowProperties") ); - config->setGroup( s ); - if ( !config->hasKey( TQString::fromLatin1("ClassName") ) ) - return TQString::null; - else - return config->readEntry( TQString::fromLatin1("ClassName") ); -} - -void TDEMainWindow::show() -{ - TQMainWindow::show(); - - for ( TQPtrListIterator it( d->hiddenDockWindows ); it.current(); ++it ) - it.current()->show(); - - d->hiddenDockWindows.clear(); -} - -void TDEMainWindow::hide() -{ - if ( isVisible() ) { - - d->hiddenDockWindows.clear(); - - TQObjectList *list = queryList( TQDOCKWINDOW_OBJECT_NAME_STRING ); - for( TQObjectListIt it( *list ); it.current(); ++it ) { - TQDockWindow *dw = (TQDockWindow*)it.current(); - if ( dw->isTopLevel() && dw->isVisible() ) { - d->hiddenDockWindows.append( dw ); - dw->hide(); - } - } - delete list; - } - - TQWidget::hide(); -} - -bool TDEMainWindow::restore( int number, bool show ) -{ - if ( !canBeRestored( number ) ) - return false; - TDEConfig *config = kapp->sessionConfig(); - if ( readPropertiesInternal( config, number ) ){ - if ( show ) - TDEMainWindow::show(); - return false; - } - return false; -} - -KXMLGUIFactory *TDEMainWindow::guiFactory() -{ - if ( !factory_ ) - factory_ = new KXMLGUIFactory( this, TQT_TQOBJECT(this), "guifactory" ); - return factory_; -} - -int TDEMainWindow::configureToolbars() -{ - saveMainWindowSettings(TDEGlobal::config()); - KEditToolbar dlg(actionCollection(), xmlFile(), true, this); - connect(&dlg, TQT_SIGNAL(newToolbarConfig()), TQT_SLOT(saveNewToolbarConfig())); - return dlg.exec(); -} - -void TDEMainWindow::saveNewToolbarConfig() -{ - createGUI(xmlFile()); - applyMainWindowSettings( TDEGlobal::config() ); -} - -void TDEMainWindow::setupGUI( int options, const TQString & xmlfile ) { - setupGUI(TQSize(), options, xmlfile); -} - -void TDEMainWindow::setupGUI( TQSize defaultSize, int options, const TQString & xmlfile ) { - if( options & Keys ){ - KStdAction::keyBindings(guiFactory(), - TQT_SLOT(configureShortcuts()), actionCollection()); - } - - if( (options & StatusBar) && internalStatusBar() ){ - createStandardStatusBarAction(); - } - - if( options & ToolBar ){ - setStandardToolBarMenuEnabled( true ); - KStdAction::configureToolbars(TQT_TQOBJECT(this), - TQT_SLOT(configureToolbars() ), actionCollection()); - } - - if( options & Create ){ - createGUI(xmlfile,false); - } - - if( options & Save ){ - // setupGUI() is typically called in the constructor before show(), - // so the default window size will be incorrect unless the application - // hard coded the size which they should try not to do (i.e. use - // size hints). - if(initialGeometrySet()) - { - // Do nothing... - } - else if(defaultSize.isValid()) - { - resize(defaultSize); - } - else if(!isShown()) - { - adjustSize(); - } - setAutoSaveSettings(); - } - -} - -void TDEMainWindow::createGUI( const TQString &xmlfile, bool _conserveMemory ) -{ - // disabling the updates prevents unnecessary redraws - setUpdatesEnabled( false ); - - // just in case we are rebuilding, let's remove our old client - guiFactory()->removeClient( this ); - - // make sure to have an empty GUI - TQMenuBar* mb = internalMenuBar(); - if ( mb ) - mb->clear(); - - (void)toolBarIterator(); // make sure toolbarList is most-up-to-date - toolbarList.setAutoDelete( true ); - toolbarList.clear(); - toolbarList.setAutoDelete( false ); - - // don't build a help menu unless the user ask for it - if (d->showHelpMenu) { - // we always want a help menu - if (!helpMenu2) - helpMenu2 = new KHelpMenu(this, instance()->aboutData(), true, - actionCollection()); - } - - // we always want to load in our global standards file - setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) ); - - // now, merge in our local xml file. if this is null, then that - // means that we will be only using the global file - if ( !xmlfile.isNull() ) { - setXMLFile( xmlfile, true ); - } else { - TQString auto_file(instance()->instanceName() + "ui.rc"); - setXMLFile( auto_file, true ); - } - - // make sure we don't have any state saved already - setXMLGUIBuildDocument( TQDomDocument() ); - - // do the actual GUI building - guiFactory()->addClient( this ); - - // try and get back *some* of our memory - if ( _conserveMemory ) - { - // before freeing the memory allocated by the DOM document we also - // free all memory allocated internally in the KXMLGUIFactory for - // the menubar and the toolbars . This however implies that we - // have to take care of deleting those widgets ourselves. For - // destruction this is no problem, but when rebuilding we have - // to take care of that (and we want to rebuild the GUI when - // using stuff like the toolbar editor ). - // In addition we have to take care of not removing containers - // like popupmenus, defined in the XML document. - // this code should probably go into a separate method in TDEMainWindow. - // there's just one problem: I'm bad in finding names ;-) , so - // I skipped this ;-) - - TQDomDocument doc = domDocument(); - - for( TQDomNode n = doc.documentElement().firstChild(); - !n.isNull(); n = n.nextSibling()) - { - TQDomElement e = n.toElement(); - - if ( e.tagName().lower() == "toolbar" ) - factory_->resetContainer( e.attribute( "name" ) ); - else if ( e.tagName().lower() == "menubar" ) - factory_->resetContainer( e.tagName(), true ); - } - - conserveMemory(); - } - - setUpdatesEnabled( true ); - updateGeometry(); -} - -void TDEMainWindow::setHelpMenuEnabled(bool showHelpMenu) -{ - d->showHelpMenu = showHelpMenu; -} - -bool TDEMainWindow::isHelpMenuEnabled() -{ - return d->showHelpMenu; -} - -void TDEMainWindow::setCaption( const TQString &caption ) -{ - setPlainCaption( kapp->makeStdCaption(caption) ); -} - -void TDEMainWindow::setCaption( const TQString &caption, bool modified ) -{ - setPlainCaption( kapp->makeStdCaption(caption, true, modified) ); -} - -void TDEMainWindow::setPlainCaption( const TQString &caption ) -{ - TQMainWindow::setCaption( caption ); -#if defined Q_WS_X11 - NETWinInfo info( tqt_xdisplay(), winId(), tqt_xrootwin(), 0 ); - info.setName( caption.utf8().data() ); -#endif -} - -void TDEMainWindow::appHelpActivated( void ) -{ - if( !mHelpMenu ) { - mHelpMenu = new KHelpMenu( this ); - if ( !mHelpMenu ) - return; - } - mHelpMenu->appHelpActivated(); -} - -void TDEMainWindow::slotStateChanged(const TQString &newstate) -{ - stateChanged(newstate, KXMLGUIClient::StateNoReverse); -} - -/* - * Get rid of this for KDE 4.0 - */ -void TDEMainWindow::slotStateChanged(const TQString &newstate, - KXMLGUIClient::ReverseStateChange reverse) -{ - stateChanged(newstate, reverse); -} - -/* - * Enable this for KDE 4.0 - */ -// void TDEMainWindow::slotStateChanged(const TQString &newstate, -// bool reverse) -// { -// stateChanged(newstate, -// reverse ? KXMLGUIClient::StateReverse : KXMLGUIClient::StateNoReverse); -// } - -void TDEMainWindow::closeEvent ( TQCloseEvent *e ) -{ - // Save settings if auto-save is enabled, and settings have changed - if (d->settingsDirty && d->autoSaveSettings) - saveAutoSaveSettings(); - - if (queryClose()) { - e->accept(); - - int not_withdrawn = 0; - TQPtrListIterator it(*TDEMainWindow::memberList); - for (it.toFirst(); it.current(); ++it){ - if ( !it.current()->isHidden() && it.current()->isTopLevel() && it.current() != this ) - not_withdrawn++; - } - - if ( !no_query_exit && not_withdrawn <= 0 ) { // last window close accepted? - if ( queryExit() && !kapp->sessionSaving() && !d->shuttingDown ) { // Yes, Quit app? - // don't call queryExit() twice - disconnect(kapp, TQT_SIGNAL(shutDown()), this, TQT_SLOT(shuttingDown())); - d->shuttingDown = true; - kapp->deref(); // ...and quit application. - } else { - // cancel closing, it's stupid to end up with no windows at all.... - e->ignore(); - } - } - } -} - -bool TDEMainWindow::queryExit() -{ - return true; -} - -bool TDEMainWindow::queryClose() -{ - return true; -} - -void TDEMainWindow::saveGlobalProperties( TDEConfig* ) -{ -} - -void TDEMainWindow::readGlobalProperties( TDEConfig* ) -{ -} - -#if defined(KDE_COMPAT) -void TDEMainWindow::updateRects() -{ -} -#endif - -void TDEMainWindow::showAboutApplication() -{ -} - -void TDEMainWindow::savePropertiesInternal( TDEConfig *config, int number ) -{ - bool oldASWS = d->autoSaveWindowSize; - d->autoSaveWindowSize = true; // make saveMainWindowSettings save the window size - - TQString s; - s.setNum(number); - s.prepend(TQString::fromLatin1("WindowProperties")); - config->setGroup(s); - - // store objectName, className, Width and Height for later restoring - // (Only useful for session management) - config->writeEntry(TQString::fromLatin1("ObjectName"), name()); - config->writeEntry(TQString::fromLatin1("ClassName"), className()); - - saveMainWindowSettings(config); // Menubar, statusbar and Toolbar settings. - - s.setNum(number); - config->setGroup(s); - saveProperties(config); - - d->autoSaveWindowSize = oldASWS; -} - -void TDEMainWindow::saveMainWindowSettings(TDEConfig *config, const TQString &configGroup) -{ - kdDebug(200) << "TDEMainWindow::saveMainWindowSettings " << configGroup << endl; - TQString oldGroup; - - if (!configGroup.isEmpty()) - { - oldGroup = config->group(); - config->setGroup(configGroup); - } - - // Called by session management - or if we want to save the window size anyway - if ( d->autoSaveWindowSize ) - saveWindowSize( config ); - - TQStatusBar* sb = internalStatusBar(); - if (sb) { - if(!config->hasDefault("StatusBar") && !sb->isHidden() ) - config->revertToDefault("StatusBar"); - else - config->writeEntry("StatusBar", sb->isHidden() ? "Disabled" : "Enabled"); - } - - TQMenuBar* mb = internalMenuBar(); - if (mb) { - TQString MenuBar = TQString::fromLatin1("MenuBar"); - if(!config->hasDefault("MenuBar") && !mb->isHidden() ) - config->revertToDefault("MenuBar"); - else - config->writeEntry("MenuBar", mb->isHidden() ? "Disabled" : "Enabled"); - } - - int n = 1; // Toolbar counter. toolbars are counted from 1, - TDEToolBar *toolbar = 0; - TQPtrListIterator it( toolBarIterator() ); - while ( ( toolbar = it.current() ) ) { - ++it; - TQString group; - if (!configGroup.isEmpty()) - { - // Give a number to the toolbar, but prefer a name if there is one, - // because there's no real guarantee on the ordering of toolbars - group = (!::qstrcmp(toolbar->name(), "unnamed") ? TQString::number(n) : TQString(" ")+toolbar->name()); - group.prepend(" Toolbar"); - group.prepend(configGroup); - } - toolbar->saveSettings(config, group); - n++; - } - if (!configGroup.isEmpty()) - config->setGroup(oldGroup); -} - -void TDEMainWindow::setStandardToolBarMenuEnabled( bool enable ) -{ - if ( enable ) { - if ( d->toolBarHandler ) - return; - - d->toolBarHandler = new KDEPrivate::ToolBarHandler( this ); - - if ( factory() ) - factory()->addClient( d->toolBarHandler ); - } else { - if ( !d->toolBarHandler ) - return; - - if ( factory() ) - factory()->removeClient( d->toolBarHandler ); - - delete d->toolBarHandler; - d->toolBarHandler = 0; - } -} - -bool TDEMainWindow::isStandardToolBarMenuEnabled() const -{ - return ( d->toolBarHandler ); -} - -void TDEMainWindow::createStandardStatusBarAction(){ - if(!d->showStatusBarAction){ - d->showStatusBarAction = KStdAction::showStatusbar(TQT_TQOBJECT(this), TQT_SLOT(setSettingsDirty()), actionCollection()); - KStatusBar *sb = statusBar(); // Creates statusbar if it doesn't exist already. - connect(d->showStatusBarAction, TQT_SIGNAL(toggled(bool)), sb, TQT_SLOT(setShown(bool))); - d->showStatusBarAction->setChecked(sb->isHidden()); - } -} - -bool TDEMainWindow::readPropertiesInternal( TDEConfig *config, int number ) -{ - if ( number == 1 ) - readGlobalProperties( config ); - - // in order they are in toolbar list - TQString s; - s.setNum(number); - s.prepend(TQString::fromLatin1("WindowProperties")); - - config->setGroup(s); - - // restore the object name (window role) - if ( config->hasKey(TQString::fromLatin1("ObjectName" )) ) - setName( config->readEntry(TQString::fromLatin1("ObjectName")).latin1()); // latin1 is right here - - applyMainWindowSettings(config); // Menubar, statusbar and toolbar settings. - - s.setNum(number); - config->setGroup(s); - readProperties(config); - return true; -} - -void TDEMainWindow::applyMainWindowSettings(TDEConfig *config, const TQString &configGroup) -{ - return applyMainWindowSettings(config,configGroup,false); -} - -void TDEMainWindow::applyMainWindowSettings(TDEConfig *config, const TQString &configGroup,bool force) -{ - kdDebug(200) << "TDEMainWindow::applyMainWindowSettings" << endl; - - TDEConfigGroupSaver saver( config, configGroup.isEmpty() ? config->group() : configGroup ); - - restoreWindowSize(config); - - TQStatusBar* sb = internalStatusBar(); - if (sb) { - TQString entry = config->readEntry("StatusBar", "Enabled"); - if ( entry == "Disabled" ) - sb->hide(); - else - sb->show(); - if(d->showStatusBarAction) - d->showStatusBarAction->setChecked(!sb->isHidden()); - } - - TQMenuBar* mb = internalMenuBar(); - if (mb) { - TQString entry = config->readEntry ("MenuBar", "Enabled"); - if ( entry == "Disabled" ) - mb->hide(); - else - mb->show(); - } - - int n = 1; // Toolbar counter. toolbars are counted from 1, - TDEToolBar *toolbar; - TQPtrListIterator it( toolBarIterator() ); // must use own iterator - - for ( ; it.current(); ++it) { - toolbar= it.current(); - TQString group; - if (!configGroup.isEmpty()) - { - // Give a number to the toolbar, but prefer a name if there is one, - // because there's no real guarantee on the ordering of toolbars - group = (!::qstrcmp(toolbar->name(), "unnamed") ? TQString::number(n) : TQString(" ")+toolbar->name()); - group.prepend(" Toolbar"); - group.prepend(configGroup); - } - toolbar->applySettings(config, group, force); - n++; - } - - finalizeGUI( true ); -} - -void TDEMainWindow::finalizeGUI( bool force ) -{ - //kdDebug(200) << "TDEMainWindow::finalizeGUI force=" << force << endl; - // The whole reason for this is that moveToolBar relies on the indexes - // of the other toolbars, so in theory it should be called only once per - // toolbar, but in increasing order of indexes. - // Since we can't do that immediately, we move them, and _then_ - // we call positionYourself again for each of them, but this time - // the toolbariterator should give them in the proper order. - // Both the XMLGUI and applySettings call this, hence "force" for the latter. - TQPtrListIterator it( toolBarIterator() ); - for ( ; it.current() ; ++it ) { - it.current()->positionYourself( force ); - } - - d->settingsDirty = false; -} - -void TDEMainWindow::saveWindowSize( TDEConfig * config ) const -{ - int scnum = TQApplication::desktop()->screenNumber(parentWidget()); - TQRect desk = TQApplication::desktop()->screenGeometry(scnum); - int w, h; -#if defined Q_WS_X11 - // save maximalization as desktop size + 1 in that direction - KWin::WindowInfo info = KWin::windowInfo( winId(), NET::WMState ); - w = info.state() & NET::MaxHoriz ? desk.width() + 1 : width(); - h = info.state() & NET::MaxVert ? desk.height() + 1 : height(); -#else - if (isMaximized()) { - w = desk.width() + 1; - h = desk.height() + 1; - } - //TODO: add "Maximized" property instead "+1" hack -#endif - TQRect size( desk.width(), w, desk.height(), h ); - bool defaultSize = (size == d->defaultWindowSize); - TQString widthString = TQString::fromLatin1("Width %1").arg(desk.width()); - TQString heightString = TQString::fromLatin1("Height %1").arg(desk.height()); - if (!config->hasDefault(widthString) && defaultSize) - config->revertToDefault(widthString); - else - config->writeEntry(widthString, w ); - - if (!config->hasDefault(heightString) && defaultSize) - config->revertToDefault(heightString); - else - config->writeEntry(heightString, h ); -} - -void TDEMainWindow::restoreWindowSize( TDEConfig * config ) -{ - if (d->care_about_geometry) { - parseGeometry(true); - } else { - // restore the size - int scnum = TQApplication::desktop()->screenNumber(parentWidget()); - TQRect desk = TQApplication::desktop()->screenGeometry(scnum); - if ( d->defaultWindowSize.isNull() ) // only once - d->defaultWindowSize = TQRect(desk.width(), width(), desk.height(), height()); // store default values - TQSize size( config->readNumEntry( TQString::fromLatin1("Width %1").arg(desk.width()), 0 ), - config->readNumEntry( TQString::fromLatin1("Height %1").arg(desk.height()), 0 ) ); - if (size.isEmpty()) { - // try the KDE 2.0 way - size = TQSize( config->readNumEntry( TQString::fromLatin1("Width"), 0 ), - config->readNumEntry( TQString::fromLatin1("Height"), 0 ) ); - if (!size.isEmpty()) { - // make sure the other resolutions don't get old settings - config->writeEntry( TQString::fromLatin1("Width"), 0 ); - config->writeEntry( TQString::fromLatin1("Height"), 0 ); - } - } - if ( !size.isEmpty() ) { -#ifdef Q_WS_X11 - int state = ( size.width() > desk.width() ? NET::MaxHoriz : 0 ) - | ( size.height() > desk.height() ? NET::MaxVert : 0 ); - if(( state & NET::Max ) == NET::Max ) - ; // no resize - else if(( state & NET::MaxHoriz ) == NET::MaxHoriz ) - resize( width(), size.height()); - else if(( state & NET::MaxVert ) == NET::MaxVert ) - resize( size.width(), height()); - else - resize( size ); - // TQWidget::showMaximized() is both insufficient and broken - KWin::setState( winId(), state ); -#else - if (size.width() > desk.width() || size.height() > desk.height()) - setWindowState( WindowMaximized ); - else - resize( size ); -#endif - } - } -} - -bool TDEMainWindow::initialGeometrySet() const -{ - return d->care_about_geometry; -} - -void TDEMainWindow::ignoreInitialGeometry() -{ - d->care_about_geometry = false; -} - -void TDEMainWindow::setSettingsDirty() -{ - //kdDebug(200) << "TDEMainWindow::setSettingsDirty" << endl; - d->settingsDirty = true; - if ( d->autoSaveSettings ) - { - // Use a timer to save "immediately" user-wise, but not too immediately - // (to compress calls and save only once, in case of multiple changes) - if ( !d->settingsTimer ) - { - d->settingsTimer = new TQTimer( this ); - connect( d->settingsTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( saveAutoSaveSettings() ) ); - } - d->settingsTimer->start( 500, true ); - } -} - -bool TDEMainWindow::settingsDirty() const -{ - return d->settingsDirty; -} - -TQString TDEMainWindow::settingsGroup() const -{ - return d->autoSaveGroup; -} - -void TDEMainWindow::setAutoSaveSettings( const TQString & groupName, bool saveWindowSize ) -{ - d->autoSaveSettings = true; - d->autoSaveGroup = groupName; - d->autoSaveWindowSize = saveWindowSize; - // Get notified when the user moves a toolbar around - disconnect( this, TQT_SIGNAL( dockWindowPositionChanged( TQDockWindow * ) ), - this, TQT_SLOT( setSettingsDirty() ) ); - connect( this, TQT_SIGNAL( dockWindowPositionChanged( TQDockWindow * ) ), - this, TQT_SLOT( setSettingsDirty() ) ); - - // Now read the previously saved settings - applyMainWindowSettings( TDEGlobal::config(), groupName ); -} - -void TDEMainWindow::resetAutoSaveSettings() -{ - d->autoSaveSettings = false; - if ( d->settingsTimer ) - d->settingsTimer->stop(); -} - -bool TDEMainWindow::autoSaveSettings() const -{ - return d->autoSaveSettings; -} - -TQString TDEMainWindow::autoSaveGroup() const -{ - return d->autoSaveGroup; -} - -void TDEMainWindow::saveAutoSaveSettings() -{ - Q_ASSERT( d->autoSaveSettings ); - //kdDebug(200) << "TDEMainWindow::saveAutoSaveSettings -> saving settings" << endl; - saveMainWindowSettings( TDEGlobal::config(), d->autoSaveGroup ); - TDEGlobal::config()->sync(); - d->settingsDirty = false; - if ( d->settingsTimer ) - d->settingsTimer->stop(); -} - -void TDEMainWindow::resizeEvent( TQResizeEvent * ) -{ - if ( d->autoSaveWindowSize ) - setSettingsDirty(); -} - -bool TDEMainWindow::hasMenuBar() -{ - return (internalMenuBar()); -} - -KMenuBar *TDEMainWindow::menuBar() -{ - KMenuBar * mb = internalMenuBar(); - if ( !mb ) { - mb = new KMenuBar( this ); - // trigger a re-layout and trigger a call to the private - // setMenuBar method. - TQMainWindow::menuBar(); - } - return mb; -} - -KStatusBar *TDEMainWindow::statusBar() -{ - KStatusBar * sb = internalStatusBar(); - if ( !sb ) { - sb = new KStatusBar( this ); - // trigger a re-layout and trigger a call to the private - // setStatusBar method. - TQMainWindow::statusBar(); - } - return sb; -} - -void TDEMainWindow::shuttingDown() -{ - // Needed for Qt <= 3.0.3 at least to prevent reentrancy - // when queryExit() shows a dialog. Check before removing! - static bool reentrancy_protection = false; - if (!reentrancy_protection) - { - reentrancy_protection = true; - // call the virtual queryExit - queryExit(); - reentrancy_protection = false; - } - -} - -KMenuBar *TDEMainWindow::internalMenuBar() -{ - TQObjectList *l = queryList( "KMenuBar", 0, false, false ); - if ( !l || !l->first() ) { - delete l; - return 0; - } - - KMenuBar *m = (KMenuBar*)l->first(); - delete l; - return m; -} - -KStatusBar *TDEMainWindow::internalStatusBar() -{ - TQObjectList *l = queryList( "KStatusBar", 0, false, false ); - if ( !l || !l->first() ) { - delete l; - return 0; - } - - KStatusBar *s = (KStatusBar*)l->first(); - delete l; - return s; -} - -void TDEMainWindow::childEvent( TQChildEvent* e) -{ - TQMainWindow::childEvent( e ); -} - -TDEToolBar *TDEMainWindow::toolBar( const char * name ) -{ - if (!name) - name = "mainToolBar"; - TDEToolBar *tb = (TDEToolBar*)child( name, "TDEToolBar" ); - if ( tb ) - return tb; - bool honor_mode = (!strcmp(name, "mainToolBar")); - - if ( builderClient() ) - return new TDEToolBar(this, name, honor_mode); // XMLGUI constructor - else - return new TDEToolBar(this, DockTop, false, name, honor_mode ); // non-XMLGUI -} - -TQPtrListIterator TDEMainWindow::toolBarIterator() -{ - toolbarList.clear(); - TQPtrList lst; - for ( int i = (int)TQMainWindow::DockUnmanaged; i <= (int)DockMinimized; ++i ) { - lst = toolBars( (ToolBarDock)i ); - for ( TQToolBar *tb = lst.first(); tb; tb = lst.next() ) { - if ( !tb->inherits( "TDEToolBar" ) ) - continue; - toolbarList.append( (TDEToolBar*)tb ); - } - } - return TQPtrListIterator( toolbarList ); -} - -TDEAccel * TDEMainWindow::accel() -{ - if ( !d->kaccel ) - d->kaccel = new TDEAccel( this, "kmw-kaccel" ); - return d->kaccel; -} - -void TDEMainWindow::paintEvent( TQPaintEvent * pe ) -{ - TQMainWindow::paintEvent(pe); //Upcall to handle SH_MainWindow_SpaceBelowMenuBar rendering -} - -TQSize TDEMainWindow::sizeForCentralWidgetSize(TQSize size) -{ - TDEToolBar *tb = (TDEToolBar*)child( "mainToolBar", "TDEToolBar" ); - if (tb && !tb->isHidden()) { - switch( tb->barPos() ) - { - case TDEToolBar::Top: - case TDEToolBar::Bottom: - size += TQSize(0, tb->sizeHint().height()); - break; - - case TDEToolBar::Left: - case TDEToolBar::Right: - size += TQSize(toolBar()->sizeHint().width(), 0); - break; - - case TDEToolBar::Flat: - size += TQSize(0, 3+kapp->style().pixelMetric( TQStyle::PM_DockWindowHandleExtent )); - break; - - default: - break; - } - } - KMenuBar *mb = internalMenuBar(); - if (mb && !mb->isHidden()) { - size += TQSize(0,mb->heightForWidth(size.width())); - if (style().styleHint(TQStyle::SH_MainWindow_SpaceBelowMenuBar, this)) - size += TQSize( 0, dockWindowsMovable() ? 1 : 2); - } - TQStatusBar *sb = internalStatusBar(); - if( sb && !sb->isHidden() ) - size += TQSize(0, sb->sizeHint().height()); - - return size; -} - -#if KDE_IS_VERSION( 3, 9, 0 ) -#ifdef __GNUC__ -#warning Remove, should be in Qt -#endif -#endif -void TDEMainWindow::setIcon( const TQPixmap& p ) -{ - TQMainWindow::setIcon( p ); -#ifdef Q_WS_X11 - // Qt3 doesn't support _NET_WM_ICON, but TDEApplication::setTopWidget(), which - // is used by TDEMainWindow, sets it - KWin::setIcons( winId(), p, TQPixmap()); -#endif -} - -TQPtrList* TDEMainWindow::getMemberList() { return memberList; } - -// why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI; -// DF: because they compile KDE much faster :) -void TDEMainWindow::finalizeGUI( KXMLGUIClient *client ) -{ KXMLGUIBuilder::finalizeGUI( client ); } - -void TDEMainWindow::virtual_hook( int id, void* data ) -{ KXMLGUIBuilder::virtual_hook( id, data ); - KXMLGUIClient::virtual_hook( id, data ); } - - - -#include "kmainwindow.moc" - diff --git a/tdeui/kmainwindow.h b/tdeui/kmainwindow.h deleted file mode 100644 index 9ad7dedc6..000000000 --- a/tdeui/kmainwindow.h +++ /dev/null @@ -1,1076 +0,0 @@ -/* - This file is part of the KDE libraries - - 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 KMAINWINDOW_H -#define KMAINWINDOW_H - -#include "kxmlguifactory.h" -#include "kxmlguiclient.h" -#include "kxmlguibuilder.h" -#include -#include -#include - -class TDEPopupMenu; -class KXMLGUIFactory; -class TDEConfig; -class KHelpMenu; -class KStatusBar; -class TQStatusBar; -class KMenuBar; -class KMWSessionManaged; -class TDEMainWindowPrivate; -class TDEAccel; -class TDEToolBarMenuAction; -class DCOPObject; - -#define KDE_DEFAULT_WINDOWFLAGS WType_TopLevel | WDestructiveClose - - -/** - * @short %KDE top level main window - * - * Top level widget that provides toolbars, a status line and a frame. - * - * It should be used as a top level (parent-less) widget. - * It manages the geometry for all its children, including your - * main widget. - * - * Normally, you will inherit from TDEMainWindow, - * then construct (or use some existing) widget as - * your main view. You can set only one main view. - * - * You can add as many toolbars as you like. There can be only one menubar - * and only one statusbar. - * - * The toolbars, menubar, and statusbar can be created by the - * TDEMainWindow and - unlike the old TDEMainWindow - may, but do not - * have to, be deleted by you. TDEMainWindow will handle that internally. - * - * Height and width can be operated independently from each other. Simply - * define the minimum/maximum height/width of your main widget and - * TDEMainWindow will take this into account. For fixed size windows set - * your main widget to a fixed size. - * - * Fixed aspect ratios (heightForWidth()) and fixed width widgets are - * not supported. -* - * TDEMainWindow will set icon, mini icon and caption, which it gets - * from TDEApplication. It provides full session management, and - * will save its position, geometry and positions of toolbars and - * menubar on logout. If you want to save additional data, reimplement - * saveProperties() and (to read them again on next login) - * readProperties(). To save special data about your data, reimplement - * saveGlobalProperties(). To warn user that application or - * windows have unsaved data on close or logout, reimplement - * queryClose() and/or queryExit(). - * - * There are also kRestoreMainWindows convenience functions which - * can restore all your windows on next login. - * - * Note that a TDEMainWindow per-default is created with the - * WDestructiveClose flag, i.e. it is automatically destroyed when the - * window is closed. If you do not want this behavior, specify 0 as - * widget flag in the constructor. - * - * @see TDEApplication - * @author Reginald Stadlbauer (reggie@kde.org) Stephan Kulow (coolo@kde.org), Matthias Ettrich (ettrich@kde.org), Chris Schlaeger (cs@kde.org), Sven Radej (radej@kde.org). Maintained by Sven Radej (radej@kde.org) - - */ - -class TDEUI_EXPORT TDEMainWindow : public TQMainWindow, public KXMLGUIBuilder, virtual public KXMLGUIClient -{ - friend class KMWSessionManaged; - Q_OBJECT - -public: - /** - * Construct a main window. - * - * @param parent The widget parent. This is usually 0 but it may also be the window - * group leader. In that case, the TDEMainWindow becomes sort of a - * secondary window. - * - * @param name The object name. For session management and window management to work - * properly, all main windows in the application should have a - * different name. When passing 0 (the default), TDEMainWindow will create - * a unique name, but it's recommended to explicitly pass a window name that will - * also describe the type of the window. If there can be several windows of the same - * type, append '#' (hash) to the name, and TDEMainWindow will append numbers to make - * the names unique. For example, for a mail client which has one main window showing - * the mails and folders, and which can also have one or more windows for composing - * mails, the name for the folders window should be e.g. "mainwindow" and - * for the composer windows "composer#". - * - * @param f Specify the widget flags. The default is - * WType_TopLevel and WDestructiveClose. TopLevel indicates that a - * main window is a toplevel window, regardless of whether it has a - * parent or not. DestructiveClose indicates that a main window is - * automatically destroyed when its window is closed. Pass 0 if - * you do not want this behavior. - * - * @see http://doc.trolltech.com/3.2/tqt.html#WidgetFlags-enum - * - * TDEMainWindows must be created on the heap with 'new', like: - * \code - * TDEMainWindow *kmw = new TDEMainWindow (...); - * \endcode - **/ -#ifdef qdoc - TDEMainWindow( TQWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose ); -#else - TDEMainWindow( TQWidget* parent = 0, const char *name = 0, WFlags f = (WFlags)(WType_TopLevel | WDestructiveClose) ); -#endif - - /** - * Flags that can be passed in an argument to the constructor to - * change the behavior. - * - * NoDCOPObject tells TDEMainWindow not to create a TDEMainWindowInterface. - * This can be useful in particular for inherited classes, which - * might want to create more specific dcop interfaces. It's a good - * idea to use TDEMainWindowInterface as the base class for such interfaces - * though (to provide the standard mainwindow functionality via DCOP). - */ - enum CreationFlags - { - NoDCOPObject = 1 - }; - - /** - * Overloaded constructor which allows passing some TDEMainWindow::CreationFlags. - * - * @since 3.2 - */ -#ifdef qdoc - TDEMainWindow( int cflags, TQWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose ); -#else - TDEMainWindow( int cflags, TQWidget* parent = 0, const char *name = 0, WFlags f = (WFlags)(WType_TopLevel | WDestructiveClose) ); -#endif - - /** - * \brief Destructor. - * - * Will also destroy the toolbars, and menubar if - * needed. - */ - virtual ~TDEMainWindow(); - - /** - * Retrieve the standard help menu. - * - * It contains entires for the - * help system (activated by F1), an optional "What's This?" entry - * (activated by Shift F1), an application specific dialog box, - * and an "About KDE" dialog box. - * - * Example (adding a standard help menu to your application): - * \code - * TDEPopupMenu *help = helpMenu( ); - * menuBar()->insertItem( i18n("&Help"), help ); - * \endcode - * - * @param aboutAppText The string that is used in the application - * specific dialog box. If you leave this string empty the - * information in the global TDEAboutData of the - * application will be used to make a standard dialog box. - * - * @param showWhatsThis Set this to false if you do not want to include - * the "What's This" menu entry. - * - * @return A standard help menu. - */ - TDEPopupMenu* helpMenu( const TQString &aboutAppText = TQString::null, - bool showWhatsThis = true ); - - /** - * Returns the help menu. Creates a standard help menu if none exists yet. - * - * It contains entries for the - * help system (activated by F1), an optional "What's This?" entry - * (activated by Shift F1), an application specific dialog box, - * and an "About KDE" dialog box. You must create the application - * specific dialog box yourself. When the "About application" - * menu entry is activated, a signal will trigger the - * showAboutApplication slot. See showAboutApplication for more - * information. - * - * Example (adding a help menu to your application): - * \code - * menuBar()->insertItem( i18n("&Help"), customHelpMenu() ); - * \endcode - * - * @param showWhatsThis Set this to @p false if you do not want to include - * the "What's This" menu entry. - * - * @return A standard help menu. - */ - TDEPopupMenu* customHelpMenu( bool showWhatsThis = true ); - - /** - * Session Management - * - * Try to restore the toplevel widget as defined by the number (1..X). - * - * If the session did not contain so high a number, the configuration - * is not changed and @p false returned. - * - * That means clients could simply do the following: - * \code - * if (kapp->isRestored()){ - * int n = 1; - * while (TDEMainWindow::canBeRestored(n)){ - * (new childMW)->restore(n); - * n++; - * } - * } else { - * // create default application as usual - * } - * \endcode - * Note that TQWidget::show() is called implicitly in restore. - * - * With this you can easily restore all toplevel windows of your - * application. - * - * If your application uses different kinds of toplevel - * windows, then you can use TDEMainWindow::classNameOfToplevel(n) - * to determine the exact type before calling the childMW - * constructor in the example from above. - * - * If your client has only one kind of toplevel widgets (which - * should be pretty usual) then you should use the RESTORE-macro - * for backwards compatibility with 3.1 and 3.0 branches: - * - * \code - * if (kapp->isRestored()) - * RESTORE(childMW) - * else { - * // create default application as usual - * } - * \endcode - * - * The macro expands to the term above but is easier to use and - * less code to write. - * - * For new code or if you have more than one kind of toplevel - * widget (each derived from TDEMainWindow, of course), you can - * use the templated kRestoreMainWindows global functions: - * - * \code - * if (kapp->isRestored()) - * kRestoreMainWindows< childMW1, childMW2, childMW3 >(); - * else { - * // create default application as usual - * } - * \endcode - * - * Currently, these functions are provided for up to three - * template arguments. If you need more, tell us. To help you in - * deciding whether or not you can use kRestoreMainWindows, a - * define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS is provided. - * - * @see restore() - * @see classNameOfToplevel() - * - **/ - static bool canBeRestored( int number ); - - /** - * Returns the className() of the @p number of the toplevel window which - * should be restored. - * - * This is only useful if your application uses - * different kinds of toplevel windows. - */ - // KDE 4 return TQCString - TQObject::className() returns const char* - static const TQString classNameOfToplevel( int number ); - - /** - * Reimplementation of TQMainWindow::show() - */ - // KDE4 remove this method if this has been fixed in Qt - virtual void show(); - - /** - * Reimplementation of TQMainWindow::hide() - */ - // KDE4 remove this method if this has been fixed in Qt - virtual void hide(); - - /** - * Restore the session specified by @p number. - * - * Returns @p false if this - * fails, otherwise returns @p true and shows the window. - * You should call canBeRestored() first. - * If @p show is true (default), this widget will be shown automatically. - */ - bool restore( int number, bool show = true ); - - virtual KXMLGUIFactory *guiFactory(); - - /** - * Create a GUI given a local XML file. - * - * If @p xmlfile is NULL, - * then it will try to construct a local XML filename like - * appnameui.rc where 'appname' is your app's name. If that file - * does not exist, then the XML UI code will only use the global - * (standard) XML file for the layout purposes. - * - * Note that when passing true for the conserveMemory argument subsequent - * calls to guiFactory()->addClient/removeClient may not work as expected. - * Also retrieving references to containers like popup menus or toolbars using - * the container method will not work. - * - * @param xmlfile The local xmlfile (relative or absolute) - * @param _conserveMemory Specify whether createGUI() should call - * KXMLGUIClient::conserveMemory() to free all memory - * allocated by the TQDomDocument and by the KXMLGUIFactory. - */ - void createGUI( const TQString &xmlfile = TQString::null, bool _conserveMemory = true ); - - /** - * Enables the build of a standard help menu when calling createGUI(). - * - * The default behavior is to build one, you must call this function - * to disable it - */ - void setHelpMenuEnabled(bool showHelpMenu = true); - - /** - * Return @p true when the help menu is enabled - */ - bool isHelpMenuEnabled(); - - - /** - * Returns true, if there is a menubar - * @since 3.1 - */ - bool hasMenuBar(); - - /** - * Returns a pointer to the menu bar. - * - * If there is no menu bar yet one will be created. - **/ - KMenuBar *menuBar(); - - /** - * Returns a pointer to the status bar. - * - * If there is no status bar yet, one will be created. - * - * Note that tooltips for kactions in actionCollection() are not - * automatically connected to this statusBar. - * See the TDEActionCollection documentation for more details. - * - * @see TDEActionCollection - */ - KStatusBar *statusBar(); - - /** - * List of members of TDEMainWindow class. - */ - static TQPtrList* memberList; - - //KDE4: replace with memberList() and make memberList member private - /** - * List of members of TDEMainWindow class. - * @since 3.4 - */ - static TQPtrList* getMemberList(); - - /** - * Returns a pointer to the toolbar with the specified name. - * This refers to toolbars created dynamically from the XML UI - * framework. If the toolbar does not exist one will be created. - * - * @param name The internal name of the toolbar. If no name is - * specified "mainToolBar" is assumed. - * - * @return A pointer to the toolbar - **/ - TDEToolBar *toolBar( const char *name=0 ); - - /** - * @return An iterator over the list of all toolbars for this window. - */ - TQPtrListIterator toolBarIterator(); - - /** - * @return A TDEAccel instance bound to this mainwindow. Used automatically - * by TDEAction to make keybindings work in all cases. - */ - TDEAccel *accel(); - - void setFrameBorderWidth( int ) {} - - /** - * Call this to enable "auto-save" of toolbar/menubar/statusbar settings - * (and optionally window size). - * If the *bars were moved around/shown/hidden when the window is closed, - * saveMainWindowSettings( TDEGlobal::config(), groupName ) will be called. - * - * @param groupName a name that identifies this "type of window". - * You can have several types of window in the same application. - * - * @param saveWindowSize set it to true to include the window size - * when saving. - * - * Typically, you will call setAutoSaveSettings() in your - * TDEMainWindow-inherited class constructor, and it will take care - * of restoring and saving automatically. Make sure you call this - * _after all_ your *bars have been created. - * - * To make sure that TDEMainWindow propertly obtains the default - * size of the window you should do the following: - * - Remove hard coded resize() calls in the constructor or main, they - * should be removed in favor of letting the automatic resizing - * determine the default window size. Hard coded window sizes will - * be wrong for users that have big fonts, use different styles, - * long/small translations, large toolbars, and other factors. - * - Put the setAutoSaveSettings ( or setupGUI() ) call after all widgets - * have been created and placed inside the main window (i.e. for 99% of - * apps setCentralWidget()) - * - Widgets that inherit from TQWidget (like game boards) should overload - * "virtual TQSize sizeHint() const;" to specify a default size rather - * than letting TQWidget::adjust use the default size of 0x0. - */ - void setAutoSaveSettings( const TQString & groupName = TQString::fromLatin1("MainWindow"), - bool saveWindowSize = true ); - - /** - * Disable the auto-save-settings feature. - * You don't normally need to call this, ever. - */ - void resetAutoSaveSettings(); - - /** - * @return the current autosave setting, i.e. true if setAutoSaveSettings() was called, - * false by default or if resetAutoSaveSettings() was called. - * @since 3.1 - */ - bool autoSaveSettings() const; - - /** - * @return the group used for setting-autosaving. - * Only meaningful if setAutoSaveSettings() was called. - * This can be useful for forcing a save or an apply, e.g. before and after - * using KEditToolbar. - * @since 3.1 - */ - TQString autoSaveGroup() const; - - /** - * Read settings for statusbar, menubar and toolbar from their respective - * groups in the config file and apply them. - * - * @param config Config file to read the settings from. - * @param groupName Group name to use. If not specified, the last used - * group name is used. - * @param force if set, even default settings are re-applied - */ - void applyMainWindowSettings(TDEConfig *config, const TQString &groupName, bool force); - // KDE4 merge with force=false - void applyMainWindowSettings(TDEConfig *config, const TQString &groupName = TQString::null); - - /** - * Save settings for statusbar, menubar and toolbar to their respective - * groups in the config file @p config. - * - * @param config Config file to save the settings to. - * @param groupName Group name to use. If not specified, the last used - * group name is used - */ - void saveMainWindowSettings(TDEConfig *config, const TQString &groupName = TQString::null); - - /** - * Sets whether TDEMainWindow should provide a menu that allows showing/hiding - * the available toolbars ( using TDEToggleToolBarAction ) . In case there - * is only one toolbar configured a simple 'Show \' menu item - * is shown. - * - * The menu / menu item is implemented using xmlgui. It will be inserted in your - * menu structure in the 'Settings' menu. - * - * If your application uses a non-standard xmlgui resource file then you can - * specify the exact position of the menu / menu item by adding a - * <Merge name="StandardToolBarMenuHandler" /> - * line to the settings menu section of your resource file ( usually appname.rc ). - * - * Note that you should enable this feature before calling createGUI() ( or similar ) . - * You enable/disable it anytime if you pass false to the conserveMemory argument of createGUI. - * @since 3.1 - */ - void setStandardToolBarMenuEnabled( bool enable ); - /// @since 3.1 - bool isStandardToolBarMenuEnabled() const; - - - /** - * Sets whether TDEMainWindow should provide a menu that allows showing/hiding - * of the statusbar ( using TDEToggleStatusBarAction ). - * - * The menu / menu item is implemented using xmlgui. It will be inserted - * in your menu structure in the 'Settings' menu. - * - * Note that you should enable this feature before calling createGUI() - * ( or similar ). - * - * If an application maintains the action on its own (i.e. never calls - * this function) a connection needs to be made to let TDEMainWindow - * know when that status (hidden/shown) of the statusbar has changed. - * For example: - * connect(action, TQT_SIGNAL(activated()), - * kmainwindow, TQT_SLOT(setSettingsDirty())); - * Otherwise the status (hidden/show) of the statusbar might not be saved - * by TDEMainWindow. - * @since 3.2 - */ - void createStandardStatusBarAction(); - - /** - * @see setupGUI() - */ - enum StandardWindowOptions - { - /** - * adds action to show/hide the toolbar(s) and adds - * action to configure the toolbar(s). - * @see setStandardToolBarMenuEnabled - */ - ToolBar = 1, - - /** - * adds action to show the key configure action. - */ - Keys = 2, - - /** - * adds action to show/hide the statusbar if the - * statusbar exists. See createStandardStatusBarAction - */ - StatusBar = 4, - - /** - * auto-saves (and loads) the toolbar/menubar/statusbar settings and - * window size using the default name. See setAutoSaveSettings - * - * Typically you want to let the default window size be determined by - * the widgets size hints. Make sure that setupGUI() is called after - * all the widgets are created ( including setCentralWidget ) so the - * default size's will be correct. See setAutoSaveSettings for - * more information on this topic. - */ - Save = 8, - - /** - * calls createGUI() once ToolBar, Keys and Statusbar have been - * taken care of. See createGUI - */ - Create = 16 - }; - - /** - * Configures the current windows and its actions in the typical KDE - * fashion. The options are all enabled by default but can be turned - * off if desired through the params or if the prereqs don't exists. - * - * Typically this function replaces createGUI(). - * - * @see StandardWindowOptions - * - * @since 3.3 - */ - void setupGUI( int options = ToolBar | Keys | StatusBar | Save | Create, const TQString& xmlfile = TQString::null ); - - /** - * Configures the current windows and its actions in the typical KDE - * fashion. The options are all enabled by default but can be turned - * off if desired through the params or if the prereqs don't exists. - * - * @p defaultSize The default size of the window - * - * Typically this function replaces createGUI(). - * - * @see StandardWindowOptions - * - * @since 3.5 - */ - void setupGUI( TQSize defaultSize, int options = ToolBar | Keys | StatusBar | Save | Create, const TQString& xmlfile = TQString::null ); - - /** - * Returns a pointer to the mainwindows action responsible for the toolbars menu - * @since 3.1 - */ - TDEAction *toolBarMenuAction(); - - /** - * @internal for TDEToolBar - * @since 3.3.1 - */ - void setupToolbarMenuActions(); - - // why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI; - /// @since 3.1 - virtual void finalizeGUI( KXMLGUIClient *client ); - - /** - * @internal - */ - void finalizeGUI( bool force ); - - /** - * @return true if a -geometry argument was given on the command line, - * and this is the first window created (the one on which this option applies) - */ - bool initialGeometrySet() const; - - /** - * @internal - * Used from Konqueror when reusing the main window. - */ - void ignoreInitialGeometry(); - - /** - * @return the size the mainwindow should have so that the central - * widget will be of @p size. - * - * @deprecated You normally don't need this, the recommended way to achieve a - * certain central widget size is as follows: - * @li Override sizeHint() in the central widget so that it - * returns the desired size. - * @li Call updateGeometry() in the central widget whenever the - * desired size changes. This ensures that the new sizeHint() is properly - * propagated to any parent layout. - * @li Now call adjustSize() in the mainwindow to resize the - * mainwindow such that the central widget will become the desired size. - * - */ - // KDE4 to be removed - TQSize sizeForCentralWidgetSize(TQSize size) KDE_DEPRECATED; - - /** - * @internal - */ - // KDE4 remove - virtual void setIcon( const TQPixmap & ); - -public slots: - /** - * Show a standard configure toolbar dialog. - * - * This slot can be connected dirrectly to the action to configure shortcuts. - * This is very simple to do that by adding a single line - * \code - * KStdAction::configureToolbars( guiFactory(), TQT_SLOT( configureToolbars() ), - * actionCollection() ); - * \endcode - * - * @since 3.3 - */ - int configureToolbars(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow - - /** - * Makes a KDE compliant caption. - * - * @param caption Your caption. @em Do @em not include the application name - * in this string. It will be added automatically according to the KDE - * standard. - */ - virtual void setCaption( const TQString &caption ); - /** - * Makes a KDE compliant caption. - * - * @param caption Your caption. @em Do @em not include the application name - * in this string. It will be added automatically according to the KDE - * standard. - * @param modified Specify whether the document is modified. This displays - * an additional sign in the title bar, usually "**". - */ - virtual void setCaption( const TQString &caption, bool modified ); - - /** - * Make a plain caption without any modifications. - * - * @param caption Your caption. This is the string that will be - * displayed in the window title. - */ - virtual void setPlainCaption( const TQString &caption ); - - /** - * Open the help page for the application. - * - * The application name is - * used as a key to determine what to display and the system will attempt - * to open \/index.html. - * - * This method is intended for use by a help button in the toolbar or - * components outside the regular help menu. Use helpMenu() when you - * want to provide access to the help system from the help menu. - * - * Example (adding a help button to the first toolbar): - * - * \code - * KIconLoader &loader = *TDEGlobal::iconLoader(); - * TQPixmap pixmap = loader.loadIcon( "help" ); - * toolBar(0)->insertButton( pixmap, 0, TQT_SIGNAL(clicked()), - * this, TQT_SLOT(appHelpActivated()), true, i18n("Help") ); - * \endcode - * - */ - void appHelpActivated( void ); - - /** - * Apply a state change - * - * Enable and disable actions as defined in the XML rc file - * @since 3.1 - */ - virtual void slotStateChanged(const TQString &newstate); - - /** - * Apply a state change - * - * Enable and disable actions as defined in the XML rc file, - * can "reverse" the state (disable the actions which should be - * enabled, and vice-versa) if specified. - * @since 3.1 - */ - void slotStateChanged(const TQString &newstate, - KXMLGUIClient::ReverseStateChange); // KDE 4.0: remove this - - - /** - * Apply a state change - * - * Enable and disable actions as defined in the XML rc file, - * can "reverse" the state (disable the actions which should be - * enabled, and vice-versa) if specified. - */ -// void slotStateChanged(const TQString &newstate, -// bool reverse); // KDE 4.0: enable this - - /** - * Tell the main window that it should save its settings when being closed. - * This is part of the auto-save-settings feature. - * For everything related to toolbars this happens automatically, - * but you have to call setSettingsDirty() in the slot that toggles - * the visibility of the statusbar. - */ - void setSettingsDirty(); - -protected: - void paintEvent( TQPaintEvent* e ); - void childEvent( TQChildEvent* e); - void resizeEvent( TQResizeEvent* e); - /** - * Reimplemented to call the queryClose() and queryExit() handlers. - * - * We recommend that you reimplement the handlers rather than closeEvent(). - * If you do it anyway, ensure to call the base implementation to keep - * queryExit() running. - */ - virtual void closeEvent ( TQCloseEvent *); - - // KDE4 This seems to be flawed to me. Either the app has only one - // mainwindow, so queryClose() is enough, or if it can have more of them, - // then the windows should take care of themselves, and queryExit() - // would be useful only for the annoying 'really quit' dialog, which - // also doesn't make sense in apps with multiple mainwindows. - // And saving configuration in something called queryExit()? IMHO - // one can e.g. use TDEApplication::shutDown(), which if nothing else - // has at least better fitting name. - // See also TDEApplication::sessionSaving(). - // This stuff should get changed somehow, so that it at least doesn't - // mess with session management. - /** - Called before the very last window is closed, either by the - user or indirectly by the session manager. - - It is not recommended to do any user interaction in this - function other than indicating severe errors. Better ask the - user on queryClose() (see below). - - A typical usage of queryExit() is to write configuration data back. - Note that the application may continue to run after queryExit() - (the user may have canceled a shutdown), so you should not do any cleanups - here. The purpose of queryExit() is purely to prepare the application - (with possible user interaction) so it can safely be closed later (without - user interaction). - - If you need to do serious things on exit (like shutting a - dial-up connection down), connect to the signal - TDEApplication::shutDown(). - - Default implementation returns @p true. Returning @p false will - cancel the exiting. In the latter case, the last window will - remain visible. If TDEApplication::sessionSaving() is true, refusing - the exit will also cancel KDE logout. - - @see queryClose() - @see TDEApplication::sessionSaving() - */ - virtual bool queryExit(); - - /** - Called before the window is closed, either by the user or indirectly by - the session manager. - - The purpose of this function is to prepare the window in a way that it is - safe to close it, i.e. without the user losing some data. - - Default implementation returns true. Returning @p false will cancel - the closing, and, if TDEApplication::sessionSaving() is true, it will also - cancel KDE logout. - - Reimplement this function to prevent the user from losing data. - Example: - \code - switch ( KMessageBox::warningYesNoCancel( this, - i18n("Save changes to document foo?")) ) { - case KMessageBox::Yes : - // save document here. If saving fails, return false; - return true; - case KMessageBox::No : - return true; - default: // cancel - return false; - \endcode - - Note that you should probably @em not actually close the document from - within this method, as it may be called by the session manager before the - session is saved. If the document is closed before the session save occurs, - its location might not be properly saved. In addition, the session shutdown - may be canceled, in which case the document should remain open. - - @see queryExit() - @see TDEApplication::sessionSaving() - */ - virtual bool queryClose(); - - /** - * Save your instance-specific properties. The function is - * invoked when the session manager requests your application - * to save its state. - * - * You @em must @em not change the group of the @p tdeconfig object, since - * TDEMainWindow uses one group for each window. Please - * reimplement these function in childclasses. - * - * Note: No user interaction is allowed - * in this function! - * - */ - virtual void saveProperties( TDEConfig* ) {} - - /** - * Read your instance-specific properties. - */ - virtual void readProperties( TDEConfig* ) {} - - /** - * Save your application-wide properties. The function is - * invoked when the session manager requests your application - * to save its state. - * - * This function is similar to saveProperties() but is only called for - * the very first main window, regardless how many main window are open. - - * Override it if you need to save other data about your documents on - * session end. sessionConfig is a config to which that data should be - * saved. Normally, you don't need this function. But if you want to save - * data about your documents that are not in opened windows you might need - * it. - * - * Default implementation does nothing. - */ - virtual void saveGlobalProperties( TDEConfig* sessionConfig ); - - /** - * The counterpart of saveGlobalProperties(). - * - * Read the application-specific properties in again. - */ - virtual void readGlobalProperties( TDEConfig* sessionConfig ); - void savePropertiesInternal( TDEConfig*, int ); - bool readPropertiesInternal( TDEConfig*, int ); - - /** - * For inherited classes - */ - bool settingsDirty() const; - /** - * For inherited classes - */ - TQString settingsGroup() const; - /** - * For inherited classes - * Note that the group must be set before calling - */ - void saveWindowSize( TDEConfig * config ) const; - /** - * For inherited classes - * Note that the group must be set before calling, and that - * a -geometry on the command line has priority. - */ - void restoreWindowSize( TDEConfig * config ); - - /// parse the geometry from the geometry command line argument - void parseGeometry(bool parsewidth); - -protected slots: - /** - * Rebuilds the GUI after KEditToolbar changed the toolbar layout. - * @see configureToolbars() - */ - void saveNewToolbarConfig(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow - - /** - * This slot does nothing. - * - * It must be reimplemented if you want - * to use a custom About Application dialog box. This slot is - * connected to the About Application entry in the menu returned - * by customHelpMenu. - * - * Example: - * \code - * - * void MyMainLevel::setupInterface() - * { - * .. - * menuBar()->insertItem( i18n("&Help"), customHelpMenu() ); - * .. - * } - * - * void MyMainLevel::showAboutApplication() - * { - * - * } - * \endcode - */ - virtual void showAboutApplication(); - - /** - * This slot should only be called in case you reimplement closeEvent() and - * if you are using the "auto-save" feature. In all other cases, - * setSettingsDirty() should be called instead to benefit from the delayed - * saving. - * - * @see setAutoSaveSettings - * @see setSettingsDirty - * - * @since 3.2 - * - * Example: - * \code - * - * void MyMainWindow::closeEvent( TQCloseEvent *e ) - * { - * // Save settings if auto-save is enabled, and settings have changed - * if ( settingsDirty() && autoSaveSettings() ) - * saveAutoSaveSettings(); - * .. - * } - * \endcode - */ - void saveAutoSaveSettings(); - -private slots: - /** - * Called when the app is shutting down. - */ - void shuttingDown(); - -private: - KMenuBar *internalMenuBar(); - KStatusBar *internalStatusBar(); - KHelpMenu *mHelpMenu, *helpMenu2; - KXMLGUIFactory *factory_; - TQPtrList toolbarList; -protected: - virtual void virtual_hook( int id, void* data ); -private: - TDEMainWindowPrivate *d; - void initTDEMainWindow(const char *name, int cflags); -}; - -#define RESTORE(type) { int n = 1;\ - while (TDEMainWindow::canBeRestored(n)){\ - (new type)->restore(n);\ - n++;}} - -#define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3 - -/** - * These global convenience functions (that come with a varying - * number of template arguments) are a replacement for the RESTORE - * macro provided in earlier versions of KDE. The old RESTORE macro - * is still provided for backwards compatibility. See - * TDEMainWindow documentation for more. - * - * \since KDE 3.2 - * - **/ -template -inline void kRestoreMainWindows() { - for ( int n = 1 ; TDEMainWindow::canBeRestored( n ) ; ++n ) { - const TQString className = TDEMainWindow::classNameOfToplevel( n ); - if ( className == TQString::fromLatin1( T::staticMetaObject()->className() ) ) - (new T)->restore( n ); - } -} - -template -inline void kRestoreMainWindows() { - const char * classNames[2]; - classNames[0] = T0::staticMetaObject()->className(); - classNames[1] = T1::staticMetaObject()->className(); - for ( int n = 1 ; TDEMainWindow::canBeRestored( n ) ; ++n ) { - const TQString className = TDEMainWindow::classNameOfToplevel( n ); - if ( className == TQString::fromLatin1( classNames[0] ) ) - (new T0)->restore( n ); - else if ( className == TQString::fromLatin1( classNames[1] ) ) - (new T1)->restore( n ); - } -} - -template -inline void kRestoreMainWindows() { - const char * classNames[3]; - classNames[0] = T0::staticMetaObject()->className(); - classNames[1] = T1::staticMetaObject()->className(); - classNames[2] = T2::staticMetaObject()->className(); - for ( int n = 1 ; TDEMainWindow::canBeRestored( n ) ; ++n ) { - const TQString className = TDEMainWindow::classNameOfToplevel( n ); - if ( className == TQString::fromLatin1( classNames[0] ) ) - (new T0)->restore( n ); - else if ( className == TQString::fromLatin1( classNames[1] ) ) - (new T1)->restore( n ); - else if ( className == TQString::fromLatin1( classNames[2] ) ) - (new T2)->restore( n ); - } -} - -#endif - diff --git a/tdeui/kmainwindowiface.cpp b/tdeui/kmainwindowiface.cpp deleted file mode 100644 index ec8ee3630..000000000 --- a/tdeui/kmainwindowiface.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001 Ian Reinhart Geiser - - This program is free software; you can redistribute it and/or - modify it under the terms of the Lesser GNU General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This program 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 - General Public License for more details. - - You should have received a copy of the Lesser GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kmainwindowiface.h" - -#include -#include -#include -#include -#include -#include -#include - - -TDEMainWindowInterface::TDEMainWindowInterface(TDEMainWindow * mainWindow) - : DCOPObject( mainWindow->name()) -{ - m_MainWindow = mainWindow; - m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); - m_dcopPropertyProxy = new KDCOPPropertyProxy(TQT_TQOBJECT(m_MainWindow)); -} - -TDEMainWindowInterface::~TDEMainWindowInterface() -{ - delete m_dcopActionProxy; - delete m_dcopPropertyProxy; -} - -QCStringList TDEMainWindowInterface::actions() -{ - delete m_dcopActionProxy; - m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); - QCStringList tmp_actions; - TQValueList lst = m_dcopActionProxy->actions(); - TQValueList::ConstIterator it = lst.begin(); - TQValueList::ConstIterator end = lst.end(); - for (; it != end; ++it ) - if ((*it)->isPlugged()) - tmp_actions.append( (TQCString)(*it)->name() ); - return tmp_actions; -} -bool TDEMainWindowInterface::activateAction( TQCString action) -{ - delete m_dcopActionProxy; - m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); - TDEAction *tmp_Action = m_dcopActionProxy->action(action); - if (tmp_Action) - { - tmp_Action->activate(); - return true; - } - else - return false; -} -bool TDEMainWindowInterface::disableAction( TQCString action) -{ - delete m_dcopActionProxy; - m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); - TDEAction *tmp_Action = m_dcopActionProxy->action(action); - if (tmp_Action) - { - tmp_Action->setEnabled(false); - return true; - } - else - return false; -} -bool TDEMainWindowInterface::enableAction( TQCString action) -{ - delete m_dcopActionProxy; - m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); - TDEAction *tmp_Action = m_dcopActionProxy->action(action); - if (tmp_Action) - { - tmp_Action->setEnabled(true); - return true; - } - else - return false; -} -bool TDEMainWindowInterface::actionIsEnabled( TQCString action) -{ - delete m_dcopActionProxy; - m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); - TDEAction *tmp_Action = m_dcopActionProxy->action(action); - if (tmp_Action) - { - return tmp_Action->isEnabled(); - } - else - return false; -} -TQCString TDEMainWindowInterface::actionToolTip( TQCString action) -{ - delete m_dcopActionProxy; - m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); - TDEAction *tmp_Action = m_dcopActionProxy->action(action); - if (tmp_Action) - { - return tmp_Action->toolTip().utf8(); - } - else - return "Error no such object!"; -} - -DCOPRef TDEMainWindowInterface::action( const TQCString &name ) -{ - return DCOPRef( kapp->dcopClient()->appId(), m_dcopActionProxy->actionObjectId( name ) ); -} - -TQMap TDEMainWindowInterface::actionMap() -{ - return m_dcopActionProxy->actionMap(); -} - -int TDEMainWindowInterface::getWinID() -{ - return (int) m_MainWindow->winId(); -} -void TDEMainWindowInterface::grabWindowToClipBoard() -{ - TQClipboard *clipboard = TQApplication::clipboard(); - clipboard->setPixmap(TQPixmap::grabWidget(m_MainWindow)); -} -void TDEMainWindowInterface::hide() -{ - m_MainWindow->hide(); -} -void TDEMainWindowInterface::maximize() -{ - m_MainWindow->showMaximized(); -} -void TDEMainWindowInterface::minimize() -{ - m_MainWindow->showMinimized(); -} -void TDEMainWindowInterface::resize(int newX, int newY) -{ - m_MainWindow->resize(newX, newY); -} -void TDEMainWindowInterface::move(int newX, int newY) -{ - m_MainWindow->move(newX, newY); -} -void TDEMainWindowInterface::setGeometry(int newX, int newY, int newWidth, int newHeight) -{ - m_MainWindow->setGeometry(newX, newY, newWidth, newHeight); -} -void TDEMainWindowInterface::raise() -{ - m_MainWindow->raise(); -} -void TDEMainWindowInterface::lower() -{ - m_MainWindow->lower(); -} -void TDEMainWindowInterface::restore() -{ - m_MainWindow->showNormal(); -} -void TDEMainWindowInterface::close() -{ - m_MainWindow->close(); -} -void TDEMainWindowInterface::show() -{ - m_MainWindow->show(); -} -QCStringList TDEMainWindowInterface::functionsDynamic() -{ - return m_dcopPropertyProxy->functions(); -} -bool TDEMainWindowInterface::processDynamic(const TQCString &fun, const TQByteArray &data, TQCString& replyType, TQByteArray &replyData) -{ - return m_dcopPropertyProxy->processPropertyRequest( fun, data, replyType, replyData); - -} - diff --git a/tdeui/kmainwindowiface.h b/tdeui/kmainwindowiface.h deleted file mode 100644 index 9ba1c4da9..000000000 --- a/tdeui/kmainwindowiface.h +++ /dev/null @@ -1,161 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001 Ian Reinhart Geiser - - 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. - - This program 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 - General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KWINDOW_INTERFACE_H -#define KWINDOW_INTERFACE_H - -#include -#include -#include -#include - -class KDCOPActionProxy; -class KDCOPPropertyProxy; -class TDEMainWindow; - -/** - * @short DCOP interface to TDEMainWindow. - * - * This is the main interface to the TDEMainWindow. This will provide a consistent - * DCOP interface to all KDE applications that use it. - * - * @author Ian Reinhart Geiser - */ -class TDEUI_EXPORT TDEMainWindowInterface : virtual public DCOPObject -{ -K_DCOP - -public: - /** - Construct a new interface object. - @param mainWindow - The parent TDEMainWindow object - that will provide us with the TDEAction objects. - */ - TDEMainWindowInterface( TDEMainWindow * mainWindow ); - /** - Destructor - Cleans up the dcop action proxy object. - **/ - ~TDEMainWindowInterface(); - - QCStringList functionsDynamic(); - bool processDynamic(const TQCString &fun, const TQByteArray &data, TQCString& replyType, TQByteArray &replyData); - - -k_dcop: - /** - Return a list of actions available to the application's window. - @return A QCStringList containing valid names actions. - */ - QCStringList actions(); - - /** - Activates the requested action. - @param action The name of the action to activate. The names of valid - actions can be found by calling actions(). - @return The success of the operation. - */ - bool activateAction( TQCString action); - - /** - Disables the requested action. - @param action The name of the action to disable. The names of valid - actions can be found by calling actions(). - @return The success of the operation. - */ - bool disableAction( TQCString action); - - /** - Enables the requested action. - @param action The name of the action to enable. The names of valid - actions can be found by calling actions(). - @return The success of the operation. - */ - bool enableAction( TQCString action); - - /** - Returns the status of the requested action. - @param action The name of the action. The names of valid - actions can be found by calling actions(). - @returns The state of the action, true - enabled, false - disabled. - */ - bool actionIsEnabled( TQCString action); - - /** - Returns the tool tip text of the requested action. - @param action The name of the action to activate. The names of valid - actions can be found by calling actions(). - @return A TQCString containing the text of the action's tool tip. - */ - TQCString actionToolTip( TQCString action); - - /** - Returns a dcop reference to the selected TDEAction - @param name The name of the action. The names of valid - actions can be found by calling actions(). - @return A DCOPRef for the kaction. - **/ - DCOPRef action( const TQCString &name ); - - /** - Returns and action map - **/ - TQMap actionMap(); - /** - Returns the ID of the current main window. - This is useful for automated screen captures or other evil - widget fun. - @return A integer value of the main window's ID. - **/ - int getWinID(); - /** - Copies a pixmap representation of the current main window to - the clipboard. - **/ - void grabWindowToClipBoard(); -// bool isHidden(); - void hide(); -// bool isMaximized(); - void maximize(); -// bool isMinimized(); - void minimize(); -// int width(); -// int height(); - void resize(int newWidth, int newHeight); -// int Xpos(); -// int Ypos(); - void move(int newX, int newY); - void setGeometry(int newX, int newY, int newWidth, int newHeight); - void raise(); - void lower(); - void restore(); - void show(); - void close(); - -// QCStringList getQTProperties(); - -private: - TDEMainWindow *m_MainWindow; - KDCOPActionProxy *m_dcopActionProxy; - KDCOPPropertyProxy *m_dcopPropertyProxy; -}; - -#endif - - diff --git a/tdeui/kpopupmenu.cpp b/tdeui/kpopupmenu.cpp deleted file mode 100644 index 5547d9316..000000000 --- a/tdeui/kpopupmenu.cpp +++ /dev/null @@ -1,694 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2000 Daniel M. Duley - Copyright (C) 2002 Hamish Rodda - - 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. -*/ -#include -#include -#include -#include - -#ifdef USE_QT4 -#undef None -#endif // USE_QT4 - -#include - -#include "kpopupmenu.h" - -#include -#include - -TDEPopupTitle::TDEPopupTitle(TQWidget *parent, const char *name) - : TQWidget(parent, name) -{ - setMinimumSize(16, fontMetrics().height()+8); -} - -TDEPopupTitle::TDEPopupTitle(KPixmapEffect::GradientType /* gradient */, - const TQColor &/* color */, const TQColor &/* textColor */, - TQWidget *parent, const char *name) - : TQWidget(parent, name) -{ - calcSize(); -} - -TDEPopupTitle::TDEPopupTitle(const KPixmap & /* background */, const TQColor &/* color */, - const TQColor &/* textColor */, TQWidget *parent, - const char *name) - : TQWidget(parent, name) -{ - calcSize(); -} - -void TDEPopupTitle::setTitle(const TQString &text, const TQPixmap *icon) -{ - titleStr = text; - if (icon) - miniicon = *icon; - else - miniicon.resize(0, 0); - - calcSize(); -} - -void TDEPopupTitle::setText( const TQString &text ) -{ - titleStr = text; - calcSize(); -} - -void TDEPopupTitle::setIcon( const TQPixmap &pix ) -{ - miniicon = pix; - calcSize(); -} - -void TDEPopupTitle::calcSize() -{ - TQFont f = font(); - f.setBold(true); - int w = miniicon.width()+TQFontMetrics(f).width(titleStr); - int h = QMAX( fontMetrics().height(), miniicon.height() ); - setMinimumSize( w+16, h+8 ); -} - -void TDEPopupTitle::paintEvent(TQPaintEvent *) -{ - TQRect r(rect()); - TQPainter p(this); - kapp->style().tqdrawPrimitive(TQStyle::PE_HeaderSectionMenu, &p, r, palette().active()); - - if (!miniicon.isNull()) - p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon); - - if (!titleStr.isNull()) - { - p.setPen(palette().active().text()); - TQFont f = p.font(); - f.setBold(true); - p.setFont(f); - if(!miniicon.isNull()) - { - p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8), - height(), AlignLeft | AlignVCenter | SingleLine, - titleStr); - } - else - { - p.drawText(0, 0, width(), height(), - AlignCenter | SingleLine, titleStr); - } - } -} - -TQSize TDEPopupTitle::sizeHint() const -{ - return minimumSize(); -} - -class TDEPopupMenu::TDEPopupMenuPrivate -{ -public: - TDEPopupMenuPrivate () - : noMatches(false) - , shortcuts(false) - , autoExec(false) - , lastHitIndex(-1) - , state(Qt::NoButton) - , m_ctxMenu(0) - {} - - ~TDEPopupMenuPrivate () - { - delete m_ctxMenu; - } - - TQString m_lastTitle; - - // variables for keyboard navigation - TQTimer clearTimer; - - bool noMatches : 1; - bool shortcuts : 1; - bool autoExec : 1; - - TQString keySeq; - TQString originalText; - - int lastHitIndex; - TQt::ButtonState state; - - // support for RMB menus on menus - TQPopupMenu* m_ctxMenu; - static bool s_continueCtxMenuShow; - static int s_highlightedItem; - static TDEPopupMenu* s_contextedMenu; -}; - -int TDEPopupMenu::TDEPopupMenuPrivate::s_highlightedItem(-1); -TDEPopupMenu* TDEPopupMenu::TDEPopupMenuPrivate::s_contextedMenu(0); -bool TDEPopupMenu::TDEPopupMenuPrivate::s_continueCtxMenuShow(true); - -TDEPopupMenu::TDEPopupMenu(TQWidget *parent, const char *name) - : TQPopupMenu(parent, name) -{ - d = new TDEPopupMenuPrivate; - resetKeyboardVars(); - connect(&(d->clearTimer), TQT_SIGNAL(timeout()), TQT_SLOT(resetKeyboardVars())); -} - -TDEPopupMenu::~TDEPopupMenu() -{ - if (TDEPopupMenuPrivate::s_contextedMenu == this) - { - TDEPopupMenuPrivate::s_contextedMenu = 0; - TDEPopupMenuPrivate::s_highlightedItem = -1; - } - - delete d; -} - -int TDEPopupMenu::insertTitle(const TQString &text, int id, int index) -{ - TDEPopupTitle *titleItem = new TDEPopupTitle(); - titleItem->setTitle(text); - int ret = insertItem(titleItem, id, index); - setItemEnabled(ret, false); - return ret; -} - -int TDEPopupMenu::insertTitle(const TQPixmap &icon, const TQString &text, int id, - int index) -{ - TDEPopupTitle *titleItem = new TDEPopupTitle(); - titleItem->setTitle(text, &icon); - int ret = insertItem(titleItem, id, index); - setItemEnabled(ret, false); - return ret; -} - -void TDEPopupMenu::changeTitle(int id, const TQString &text) -{ - TQMenuItem *item = findItem(id); - if(item){ - if(item->widget()) - ((TDEPopupTitle *)item->widget())->setTitle(text); -#ifndef NDEBUG - else - kdWarning() << "TDEPopupMenu: changeTitle() called with non-title id "<< id << endl; -#endif - } -#ifndef NDEBUG - else - kdWarning() << "TDEPopupMenu: changeTitle() called with invalid id " << id << endl; -#endif -} - -void TDEPopupMenu::changeTitle(int id, const TQPixmap &icon, const TQString &text) -{ - TQMenuItem *item = findItem(id); - if(item){ - if(item->widget()) - ((TDEPopupTitle *)item->widget())->setTitle(text, &icon); -#ifndef NDEBUG - else - kdWarning() << "TDEPopupMenu: changeTitle() called with non-title id "<< id << endl; -#endif - } -#ifndef NDEBUG - else - kdWarning() << "TDEPopupMenu: changeTitle() called with invalid id " << id << endl; -#endif -} - -TQString TDEPopupMenu::title(int id) const -{ - if(id == -1) // obsolete - return d->m_lastTitle; - TQMenuItem *item = findItem(id); - if(item){ - if(item->widget()) - return ((TDEPopupTitle *)item->widget())->title(); - else - tqWarning("TDEPopupMenu: title() called with non-title id %d.", id); - } - else - tqWarning("TDEPopupMenu: title() called with invalid id %d.", id); - return TQString::null; -} - -TQPixmap TDEPopupMenu::titlePixmap(int id) const -{ - TQMenuItem *item = findItem(id); - if(item){ - if(item->widget()) - return ((TDEPopupTitle *)item->widget())->icon(); - else - tqWarning("TDEPopupMenu: titlePixmap() called with non-title id %d.", id); - } - else - tqWarning("TDEPopupMenu: titlePixmap() called with invalid id %d.", id); - TQPixmap tmp; - return tmp; -} - -/** - * This is re-implemented for keyboard navigation. - */ -void TDEPopupMenu::closeEvent(TQCloseEvent*e) -{ - if (d->shortcuts) - resetKeyboardVars(); - TQPopupMenu::closeEvent(e); -} - -void TDEPopupMenu::activateItemAt(int index) -{ - d->state = Qt::NoButton; - TQPopupMenu::activateItemAt(index); -} - -TQt::ButtonState TDEPopupMenu::state() const -{ - return d->state; -} - -void TDEPopupMenu::keyPressEvent(TQKeyEvent* e) -{ - d->state = Qt::NoButton; - if (!d->shortcuts) { - // continue event processing by Qpopup - //e->ignore(); - d->state = e->state(); - TQPopupMenu::keyPressEvent(e); - return; - } - - int i = 0; - bool firstpass = true; - TQString keyString = e->text(); - - // check for common commands dealt with by QPopup - int key = e->key(); - if (key == Key_Escape || key == Key_Return || key == Key_Enter - || key == Key_Up || key == Key_Down || key == Key_Left - || key == Key_Right || key == Key_F1) { - - resetKeyboardVars(); - // continue event processing by Qpopup - //e->ignore(); - d->state = e->state(); - TQPopupMenu::keyPressEvent(e); - return; - } else if ( key == Key_Shift || key == Key_Control || key == Key_Alt || key == Key_Meta ) - return TQPopupMenu::keyPressEvent(e); - - // check to see if the user wants to remove a key from the sequence (backspace) - // or clear the sequence (delete) - if (!d->keySeq.isNull()) { - - if (key == Key_Backspace) { - - if (d->keySeq.length() == 1) { - resetKeyboardVars(); - return; - } - - // keep the last sequence in keyString - keyString = d->keySeq.left(d->keySeq.length() - 1); - - // allow sequence matching to be tried again - resetKeyboardVars(); - - } else if (key == Key_Delete) { - resetKeyboardVars(); - - // clear active item - setActiveItem(0); - return; - - } else if (d->noMatches) { - // clear if there are no matches - resetKeyboardVars(); - - // clear active item - setActiveItem(0); - - } else { - // the key sequence is not a null string - // therefore the lastHitIndex is valid - i = d->lastHitIndex; - } - } else if (key == Key_Backspace && parentMenu) { - // backspace with no chars in the buffer... go back a menu. - hide(); - resetKeyboardVars(); - return; - } - - d->keySeq += keyString; - int seqLen = d->keySeq.length(); - - for (; i < (int)count(); i++) { - // compare typed text with text of this entry - int j = idAt(i); - - // don't search disabled entries - if (!isItemEnabled(j)) - continue; - - TQString thisText; - - // retrieve the right text - // (the last selected item one may have additional ampersands) - if (i == d->lastHitIndex) - thisText = d->originalText; - else - thisText = text(j); - - // if there is an accelerator present, remove it - if ((int)accel(j) != 0) - thisText = thisText.replace("&", TQString()); - - // chop text to the search length - thisText = thisText.left(seqLen); - - // do the search - if (!thisText.find(d->keySeq, 0, false)) { - - if (firstpass) { - // match - setActiveItem(i); - - // check to see if we're underlining a different item - if (d->lastHitIndex != i) - // yes; revert the underlining - changeItem(idAt(d->lastHitIndex), d->originalText); - - // set the original text if it's a different item - if (d->lastHitIndex != i || d->lastHitIndex == -1) - d->originalText = text(j); - - // underline the currently selected item - changeItem(j, underlineText(d->originalText, d->keySeq.length())); - - // remember what's going on - d->lastHitIndex = i; - - // start/restart the clear timer - d->clearTimer.start(5000, true); - - // go around for another try, to see if we can execute - firstpass = false; - } else { - // don't allow execution - return; - } - } - - // fall through to allow execution - } - - if (!firstpass) { - if (d->autoExec) { - // activate anything - activateItemAt(d->lastHitIndex); - resetKeyboardVars(); - - } else if (findItem(idAt(d->lastHitIndex)) && - findItem(idAt(d->lastHitIndex))->popup()) { - // only activate sub-menus - activateItemAt(d->lastHitIndex); - resetKeyboardVars(); - } - - return; - } - - // no matches whatsoever, clean up - resetKeyboardVars(true); - //e->ignore(); - TQPopupMenu::keyPressEvent(e); -} - -bool TDEPopupMenu::focusNextPrevChild( bool next ) -{ - resetKeyboardVars(); - return TQPopupMenu::focusNextPrevChild( next ); -} - -TQString TDEPopupMenu::underlineText(const TQString& text, uint length) -{ - TQString ret = text; - for (uint i = 0; i < length; i++) { - if (ret[2*i] != '&') - ret.insert(2*i, "&"); - } - return ret; -} - -void TDEPopupMenu::resetKeyboardVars(bool noMatches /* = false */) -{ - // Clean up keyboard variables - if (d->lastHitIndex != -1) { - changeItem(idAt(d->lastHitIndex), d->originalText); - d->lastHitIndex = -1; - } - - if (!noMatches) { - d->keySeq = TQString::null; - } - - d->noMatches = noMatches; -} - -void TDEPopupMenu::setKeyboardShortcutsEnabled(bool enable) -{ - d->shortcuts = enable; -} - -void TDEPopupMenu::setKeyboardShortcutsExecute(bool enable) -{ - d->autoExec = enable; -} -/** - * End keyboard navigation. - */ - -/** - * RMB menus on menus - */ - -void TDEPopupMenu::mousePressEvent(TQMouseEvent* e) -{ - if (d->m_ctxMenu && d->m_ctxMenu->isVisible()) - { - // hide on a second context menu event - d->m_ctxMenu->hide(); - } - - TQPopupMenu::mousePressEvent(e); -} - -void TDEPopupMenu::mouseReleaseEvent(TQMouseEvent* e) -{ - // Save the button, and the modifiers from state() - d->state = TQt::ButtonState(e->button() | (e->state() & KeyButtonMask)); - - if ( !d->m_ctxMenu || !d->m_ctxMenu->isVisible() ) - TQPopupMenu::mouseReleaseEvent(e); -} - -TQPopupMenu* TDEPopupMenu::contextMenu() -{ - if (!d->m_ctxMenu) - { - d->m_ctxMenu = new TQPopupMenu(this); - connect(d->m_ctxMenu, TQT_SIGNAL(aboutToHide()), this, TQT_SLOT(ctxMenuHiding())); - } - - return d->m_ctxMenu; -} - -const TQPopupMenu* TDEPopupMenu::contextMenu() const -{ - return const_cast< TDEPopupMenu* >( this )->contextMenu(); -} - -void TDEPopupMenu::hideContextMenu() -{ - TDEPopupMenuPrivate::s_continueCtxMenuShow = false; -} - -int TDEPopupMenu::contextMenuFocusItem() -{ - return TDEPopupMenuPrivate::s_highlightedItem; -} - -TDEPopupMenu* TDEPopupMenu::contextMenuFocus() -{ - return TDEPopupMenuPrivate::s_contextedMenu; -} - -void TDEPopupMenu::itemHighlighted(int /* whichItem */) -{ - if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible()) - { - return; - } - - d->m_ctxMenu->hide(); - showCtxMenu(mapFromGlobal(TQCursor::pos())); -} - -void TDEPopupMenu::showCtxMenu(TQPoint pos) -{ - TQMenuItem* item = findItem(TDEPopupMenuPrivate::s_highlightedItem); - if (item) - { - TQPopupMenu* subMenu = item->popup(); - if (subMenu) - { - disconnect(subMenu, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(ctxMenuHideShowingMenu())); - } - } - - TDEPopupMenuPrivate::s_highlightedItem = idAt(pos); - - if (TDEPopupMenuPrivate::s_highlightedItem == -1) - { - TDEPopupMenuPrivate::s_contextedMenu = 0; - return; - } - - emit aboutToShowContextMenu(this, TDEPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu); - - TQPopupMenu* subMenu = findItem(TDEPopupMenuPrivate::s_highlightedItem)->popup(); - if (subMenu) - { - connect(subMenu, TQT_SIGNAL(aboutToShow()), TQT_SLOT(ctxMenuHideShowingMenu())); - TQTimer::singleShot(100, subMenu, TQT_SLOT(hide())); - } - - if (!TDEPopupMenuPrivate::s_continueCtxMenuShow) - { - TDEPopupMenuPrivate::s_continueCtxMenuShow = true; - return; - } - - TDEPopupMenuPrivate::s_contextedMenu = this; - d->m_ctxMenu->popup(this->mapToGlobal(pos)); - connect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(itemHighlighted(int))); -} - -/* - * this method helps prevent submenus popping up while we have a context menu - * showing - */ -void TDEPopupMenu::ctxMenuHideShowingMenu() -{ - TQMenuItem* item = findItem(TDEPopupMenuPrivate::s_highlightedItem); - if (item) - { - TQPopupMenu* subMenu = item->popup(); - if (subMenu) - { - TQTimer::singleShot(0, subMenu, TQT_SLOT(hide())); - } - } -} - -void TDEPopupMenu::ctxMenuHiding() -{ - if (TDEPopupMenuPrivate::s_highlightedItem) - { - TQPopupMenu* subMenu = findItem(TDEPopupMenuPrivate::s_highlightedItem)->popup(); - if (subMenu) - { - disconnect(subMenu, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(ctxMenuHideShowingMenu())); - } - } - - disconnect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(itemHighlighted(int))); - TDEPopupMenuPrivate::s_continueCtxMenuShow = true; -} - -void TDEPopupMenu::contextMenuEvent(TQContextMenuEvent* e) -{ - if (d->m_ctxMenu) - { - if (e->reason() == TQContextMenuEvent::Mouse) - { - showCtxMenu(e->pos()); - } - else if (actItem != -1) - { - showCtxMenu(itemGeometry(actItem).center()); - } - - e->accept(); - return; - } - - TQPopupMenu::contextMenuEvent(e); -} - -void TDEPopupMenu::hideEvent(TQHideEvent*) -{ - if (d->m_ctxMenu && d->m_ctxMenu->isVisible()) - { - // we need to block signals here when the ctxMenu is showing - // to prevent the TQPopupMenu::activated(int) signal from emitting - // when hiding with a context menu, the user doesn't expect the - // menu to actually do anything. - // since hideEvent gets called very late in the process of hiding - // (deep within TQWidget::hide) the activated(int) signal is the - // last signal to be emitted, even after things like aboutToHide() - // AJS - blockSignals(true); - d->m_ctxMenu->hide(); - blockSignals(false); - } -} -/** - * end of RMB menus on menus support - */ - -// Obsolete -TDEPopupMenu::TDEPopupMenu(const TQString& title, TQWidget *parent, const char *name) - : TQPopupMenu(parent, name) -{ - d = new TDEPopupMenuPrivate; - insertTitle(title); -} - -// Obsolete -void TDEPopupMenu::setTitle(const TQString &title) -{ - TDEPopupTitle *titleItem = new TDEPopupTitle(); - titleItem->setTitle(title); - insertItem(titleItem); - d->m_lastTitle = title; -} - -void TDEPopupTitle::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -void TDEPopupMenu::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -#include "kpopupmenu.moc" diff --git a/tdeui/kpopupmenu.h b/tdeui/kpopupmenu.h deleted file mode 100644 index 2d50e2d56..000000000 --- a/tdeui/kpopupmenu.h +++ /dev/null @@ -1,282 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2000 Daniel M. Duley - - 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 _KPOPUP_H -#define _KPOPUP_H "$Id$" - -#define INCLUDE_MENUITEM_DEF - -#include -#include -#include -#include -/** - * @short TDEPopupMenu title widget. - * - * Title widget for use in TDEPopupMenu. - * - * You usually don't have to create this manually since - * TDEPopupMenu::insertTitle will do it for you, but it is allowed if - * you wish to customize it's look. - * - * @author Daniel M. Duley - */ -class TDEUI_EXPORT TDEPopupTitle : public TQWidget -{ - Q_OBJECT - -public: - /** - * Constructs a title widget with the user specified gradient, pixmap, - * and colors. - */ - TDEPopupTitle(TQWidget *parent=0, const char *name=0); - /** - * @deprecated - * Constructs a title widget with the specified gradient and colors. - */ - TDEPopupTitle(KPixmapEffect::GradientType gradient, const TQColor &color, - const TQColor &textColor, TQWidget *parent=0, - const char *name=0) KDE_DEPRECATED; - /** - * @deprecated - * Constructs a title widget with the specified pixmap and colors. - */ - TDEPopupTitle(const KPixmap &background, const TQColor &color, - const TQColor &textColor, TQWidget *parent=0, - const char *name=0) KDE_DEPRECATED; - /** - * Sets the title string and optional icon for the title widget. - * - * You will want to call this before inserting into a menu. - */ - void setTitle(const TQString &text, const TQPixmap *icon=0); - /** - * Returns the current title. - */ - TQString title() const { return titleStr; } - /** - * Returns the current icon. - */ - TQPixmap icon() const { return miniicon; } - - TQSize sizeHint() const; - -public slots: - /// @since 3.1 - void setText( const TQString &text ); - /// @since 3.1 - void setIcon( const TQPixmap &pix ); - -protected: - void calcSize(); - void paintEvent(TQPaintEvent *ev); - - // Remove in KDE4 - KPixmapEffect::GradientType grType; - TQString titleStr; - // Remove in KDE4 - KPixmap fill; - TQPixmap miniicon; - TQColor fgColor, bgColor, grHigh, grLow; - bool useGradient; - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDEPopupTitlePrivate; - TDEPopupTitlePrivate *d; -}; - -/** - * @short A menu with title items. - * - * TDEPopupMenu is a class for menus with standard title items and keyboard - * accessibility for popups with many options and/or varying options. It acts - * identically to TQPopupMenu, with the addition of insertTitle(), - * changeTitle(), setKeyboardShortcutsEnabled() and - * setKeyboardShortcutsExecute() methods. - * - * The titles support a text string, an icon, plus user defined gradients, - * colors, and background pixmaps. - * - * The keyboard search algorithm is incremental with additional underlining - * for user feedback. - * - * @author Daniel M. Duley - * @author Hamish Rodda - */ -class TDEUI_EXPORT TDEPopupMenu : public TQPopupMenu { - Q_OBJECT - -public: - /** - * Constructs a TDEPopupMenu. - */ - TDEPopupMenu(TQWidget *parent=0, const char *name=0); - - /** - * Destructs the object - */ - ~TDEPopupMenu(); - - /** - * Inserts a title item with no icon. - */ - int insertTitle(const TQString &text, int id=-1, int index=-1); - /** - * Inserts a title item with the given icon and title. - */ - int insertTitle(const TQPixmap &icon, const TQString &text, int id=-1, - int index=-1); - /** - * Changes the title of the item at the specified id. If a icon was - * previously set it is cleared. - */ - void changeTitle(int id, const TQString &text); - /** - * Changes the title and icon of the title item at the specified id. - */ - void changeTitle(int id, const TQPixmap &icon, const TQString &text); - /** - * Returns the title of the title item at the specified id. The default - * id of -1 is for backwards compatibility only, you should always specify - * the id. - */ - TQString title(int id=-1) const; - /** - * Returns the icon of the title item at the specified id. - */ - TQPixmap titlePixmap(int id) const; - - /** - * Enables keyboard navigation by searching for the entered key sequence. - * Also underlines the currently selected item, providing feedback on the search. - * - * Defaults to off. - * - * WARNING: calls to text() of currently keyboard-selected items will - * contain additional ampersand characters. - * - * WARNING: though pre-existing keyboard shortcuts will not interfere with the - * operation of this feature, they may be confusing to the user as the existing - * shortcuts will not work. - * @since 3.1 - */ - void setKeyboardShortcutsEnabled(bool enable); - - /** - * Enables execution of the menu item once it is uniquely specified. - * Defaults to off. - * @since 3.1 - */ - void setKeyboardShortcutsExecute(bool enable); - - /** - * @deprecated - * Obsolete method provided for backwards compatibility only. Use the - * normal constructor and insertTitle instead. - */ - TDEPopupMenu(const TQString &title, TQWidget *parent=0, const char *name=0) KDE_DEPRECATED; - - /** - * @deprecated - * Obsolete method provided for backwards compatibility only. Use - * insertTitle and changeTitle instead. - */ - void setTitle(const TQString &title) KDE_DEPRECATED; - - /** - * Returns the context menu associated with this menu - * @since 3.2 - */ - TQPopupMenu* contextMenu(); - - /** - * Returns the context menu associated with this menu - * @since 3.2 - */ - const TQPopupMenu* contextMenu() const; - - /** - * Hides the context menu if shown - * @since 3.2 - */ - void hideContextMenu(); - - /** - * Returns the TDEPopupMenu associated with the current context menu - * @since 3.2 - */ - static TDEPopupMenu* contextMenuFocus(); - - /** - * returns the ID of the menuitem associated with the current context menu - * @since 3.2 - */ - static int contextMenuFocusItem(); - - /** - * Reimplemented for internal purposes - * @since 3.4 - */ - virtual void activateItemAt(int index); - /** - * Return the state of the mouse button and keyboard modifiers - * when the last menuitem was activated. - * @since 3.4 - */ - TQt::ButtonState state() const; - -signals: - /** - * connect to this signal to be notified when a context menu is about to be shown - * @param menu The menu that the context menu is about to be shown for - * @param menuItem The menu item that the context menu is currently on - * @param ctxMenu The context menu itself - * @since 3.2 - */ - void aboutToShowContextMenu(TDEPopupMenu* menu, int menuItem, TQPopupMenu* ctxMenu); - -protected: - virtual void closeEvent(TQCloseEvent *); - virtual void keyPressEvent(TQKeyEvent* e); - /// @since 3.4 - virtual void mouseReleaseEvent(TQMouseEvent* e); - virtual void mousePressEvent(TQMouseEvent* e); - virtual bool focusNextPrevChild( bool next ); - virtual void contextMenuEvent(TQContextMenuEvent *e); - virtual void hideEvent(TQHideEvent*); - - virtual void virtual_hook( int id, void* data ); - -protected slots: - /// @since 3.1 - TQString underlineText(const TQString& text, uint length); - /// @since 3.1 - void resetKeyboardVars(bool noMatches = false); - void itemHighlighted(int whichItem); - void showCtxMenu(TQPoint pos); - void ctxMenuHiding(); - void ctxMenuHideShowingMenu(); - -private: - class TDEPopupMenuPrivate; - TDEPopupMenuPrivate *d; -}; - -#endif diff --git a/tdeui/kselect.cpp b/tdeui/kselect.cpp deleted file mode 100644 index 19214ede3..000000000 --- a/tdeui/kselect.cpp +++ /dev/null @@ -1,534 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997 Martin Jones (mjones@kde.org) - - This library 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. - - 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. -*/ - -#include -#include -#include -#include -#include -#include "kselect.h" - -#define STORE_W 8 -#define STORE_W2 STORE_W * 2 - -//----------------------------------------------------------------------------- -/* - * 2D value selector. - * The contents of the selector are drawn by derived class. - */ - -KXYSelector::KXYSelector( TQWidget *parent, const char *name ) - : TQWidget( parent, name ) -{ - xPos = 0; - yPos = 0; - minX = 0; - minY = 0; - maxX = 100; - maxY = 100; - store.setOptimization( TQPixmap::BestOptim ); - store.resize( STORE_W2, STORE_W2 ); -} - - -KXYSelector::~KXYSelector() -{} - - -void KXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY ) -{ - int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); - px = w; - py = w; - minX = _minX; - minY = _minY; - maxX = _maxX; - maxY = _maxY; -} - -void KXYSelector::setXValue( int _xPos ) -{ - setValues(_xPos, yPos); -} - -void KXYSelector::setYValue( int _yPos ) -{ - setValues(xPos, _yPos); -} - -void KXYSelector::setValues( int _xPos, int _yPos ) -{ - int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); - if (w < 5) w = 5; - - xPos = _xPos; - yPos = _yPos; - - if ( xPos > maxX ) - xPos = maxX; - else if ( xPos < minX ) - xPos = minX; - - if ( yPos > maxY ) - yPos = maxY; - else if ( yPos < minY ) - yPos = minY; - - int xp = w + (width() - 2 * w) * xPos / (maxX - minX); - int yp = height() - w - (height() - 2 * w) * yPos / (maxY - minY); - - setPosition( xp, yp ); -} - -TQRect KXYSelector::contentsRect() const -{ - int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); - if (w < 5) { - w = 5; - } - TQRect contents(rect()); - contents.addCoords(w, w, -w, -w); - return contents; -} - -void KXYSelector::paintEvent( TQPaintEvent *ev ) -{ - TQRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2); - TQRect paintRect = ev->rect(); - TQRect borderRect = rect(); - - int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); - if (w < 5) { - w = 5 - w; - } - borderRect.addCoords(w, w, -w, -w); - - TQPainter painter; - painter.begin( this ); - - style().tqdrawPrimitive(TQStyle::PE_Panel, &painter, - borderRect, colorGroup(), - TQStyle::Style_Sunken); - - drawContents( &painter ); - if (paintRect.contains(cursorRect)) - { - bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W, - STORE_W2, STORE_W2, CopyROP ); - drawCursor( &painter, px, py ); - } - else if (paintRect.intersects(cursorRect)) - { - repaint( cursorRect, false); - } - - painter.end(); -} - -void KXYSelector::mousePressEvent( TQMouseEvent *e ) -{ - mouseMoveEvent(e); -} - -void KXYSelector::mouseMoveEvent( TQMouseEvent *e ) -{ - int xVal, yVal; - - int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); - valuesFromPosition( e->pos().x() - w, e->pos().y() - w, xVal, yVal ); - - setValues( xVal, yVal ); - - emit valueChanged( xPos, yPos ); -} - -void KXYSelector::wheelEvent( TQWheelEvent *e ) -{ - if ( e->orientation() == Qt::Horizontal ) - setValues( xValue() + e->delta()/120, yValue() ); - else - setValues( xValue(), yValue() + e->delta()/120 ); - - emit valueChanged( xPos, yPos ); -} - -void KXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const -{ - int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); - if (w < 5) w = 5; - xVal = ( (maxX-minX) * (x-w) ) / ( width()-2*w ); - yVal = maxY - ( ( (maxY-minY) * (y-w) ) / ( height()-2*w ) ); - - if ( xVal > maxX ) - xVal = maxX; - else if ( xVal < minX ) - xVal = minX; - - if ( yVal > maxY ) - yVal = maxY; - else if ( yVal < minY ) - yVal = minY; -} - -void KXYSelector::setPosition( int xp, int yp ) -{ - int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); - if (w < 5) w = 5; - if ( xp < w ) - xp = w; - else if ( xp > width() - w ) - xp = width() - w; - - if ( yp < w ) - yp = w; - else if ( yp > height() - w ) - yp = height() - w; - - TQPainter painter; - painter.begin( this ); - - bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0, - STORE_W2, STORE_W2, CopyROP ); - bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W, - STORE_W2, STORE_W2, CopyROP ); - drawCursor( &painter, xp, yp ); - px = xp; - py = yp; - - painter.end(); -} - -void KXYSelector::drawContents( TQPainter * ) -{} - - -void KXYSelector::drawCursor( TQPainter *p, int xp, int yp ) -{ - p->setPen( TQPen( white ) ); - - p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 ); - p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 ); - p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 ); - p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 ); -} - -//----------------------------------------------------------------------------- -/* - * 1D value selector with contents drawn by derived class. - * See KColorDialog for example. - */ - - -TDESelector::TDESelector( TQWidget *parent, const char *name ) - : TQWidget( parent, name ), TQRangeControl() -{ - _orientation = Qt::Horizontal; - _indent = true; -} - -TDESelector::TDESelector( Orientation o, TQWidget *parent, const char *name ) - : TQWidget( parent, name ), TQRangeControl() -{ - _orientation = o; - _indent = true; -} - - -TDESelector::~TDESelector() -{} - - -TQRect TDESelector::contentsRect() const -{ - int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); - int iw = (w < 5) ? 5 : w; - if ( orientation() == Qt::Vertical ) - return TQRect( w, iw, width() - w * 2 - 5, height() - 2 * iw ); - else - return TQRect( iw, w, width() - 2 * iw, height() - w * 2 - 5 ); -} - -void TDESelector::paintEvent( TQPaintEvent * ) -{ - TQPainter painter; - int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); - int iw = (w < 5) ? 5 : w; - - painter.begin( this ); - - drawContents( &painter ); - - if ( indent() ) - { - TQRect r = rect(); - if ( orientation() == Qt::Vertical ) - r.addCoords(0, iw - w, -iw, w - iw); - else - r.addCoords(iw - w, 0, w - iw, -iw); - style().tqdrawPrimitive(TQStyle::PE_Panel, &painter, - r, colorGroup(), - TQStyle::Style_Sunken); - } - - TQPoint pos = calcArrowPos( value() ); - drawArrow( &painter, true, pos ); - - painter.end(); -} - -void TDESelector::mousePressEvent( TQMouseEvent *e ) -{ - moveArrow( e->pos() ); -} - -void TDESelector::mouseMoveEvent( TQMouseEvent *e ) -{ - moveArrow( e->pos() ); -} - -void TDESelector::wheelEvent( TQWheelEvent *e ) -{ - int val = value() + e->delta()/120; - setValue( val ); -} - -void TDESelector::valueChange() -{ - TQPainter painter; - TQPoint pos; - - painter.begin( this ); - - pos = calcArrowPos( prevValue() ); - drawArrow( &painter, false, pos ); - - pos = calcArrowPos( value() ); - drawArrow( &painter, true, pos ); - - painter.end(); - - emit valueChanged( value() ); -} - -void TDESelector::moveArrow( const TQPoint &pos ) -{ - int val; - int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); - int iw = (w < 5) ? 5 : w; - - if ( orientation() == Qt::Vertical ) - val = ( maxValue() - minValue() ) * (height()-pos.y()-5+w) - / (height()-iw*2) + minValue(); - else - val = ( maxValue() - minValue() ) * (width()-pos.x()-5+w) - / (width()-iw*2) + minValue(); - - setValue( val ); -} - -TQPoint TDESelector::calcArrowPos( int val ) -{ - TQPoint p; - - int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); - int iw = (w < 5) ? 5 : w; - if ( orientation() == Qt::Vertical ) - { - p.setY( height() - ( (height()-2*iw) * val - / ( maxValue() - minValue() ) + 5 ) ); - p.setX( width() - 5 ); - } - else - { - p.setX( width() - ( (width()-2*iw) * val - / ( maxValue() - minValue() ) + 5 ) ); - p.setY( height() - 5 ); - } - - return p; -} - -void TDESelector::drawContents( TQPainter * ) -{} - -void TDESelector::drawArrow( TQPainter *painter, bool show, const TQPoint &pos ) -{ - if ( show ) - { - TQPointArray array(3); - - painter->setPen( TQPen() ); - painter->setBrush( TQBrush( colorGroup().buttonText() ) ); - array.setPoint( 0, pos.x()+0, pos.y()+0 ); - array.setPoint( 1, pos.x()+5, pos.y()+5 ); - if ( orientation() == Qt::Vertical ) - { - array.setPoint( 2, pos.x()+5, pos.y()-5 ); - } - else - { - array.setPoint( 2, pos.x()-5, pos.y()+5 ); - } - - painter->drawPolygon( array ); - } - else - { - if ( orientation() == Qt::Vertical ) - { - repaint(pos.x(), pos.y()-5, 6, 11, true); - } - else - { - repaint(pos.x()-5, pos.y(), 11, 6, true); - } - } -} - -//---------------------------------------------------------------------------- - -KGradientSelector::KGradientSelector( TQWidget *parent, const char *name ) - : TDESelector( parent, name ) -{ - init(); -} - - -KGradientSelector::KGradientSelector( Orientation o, TQWidget *parent, - const char *name ) - : TDESelector( o, parent, name ) -{ - init(); -} - - -KGradientSelector::~KGradientSelector() -{} - - -void KGradientSelector::init() -{ - color1.setRgb( 0, 0, 0 ); - color2.setRgb( 255, 255, 255 ); - - text1 = text2 = ""; -} - - -void KGradientSelector::drawContents( TQPainter *painter ) -{ - TQImage image( contentsRect().width(), contentsRect().height(), 32 ); - - TQColor col; - float scale; - - int redDiff = color2.red() - color1.red(); - int greenDiff = color2.green() - color1.green(); - int blueDiff = color2.blue() - color1.blue(); - - if ( orientation() == Qt::Vertical ) - { - for ( int y = 0; y < image.height(); y++ ) - { - scale = 1.0 * y / image.height(); - col.setRgb( color1.red() + int(redDiff*scale), - color1.green() + int(greenDiff*scale), - color1.blue() + int(blueDiff*scale) ); - - unsigned int *p = (uint *) image.scanLine( y ); - for ( int x = 0; x < image.width(); x++ ) - *p++ = col.rgb(); - } - } - else - { - unsigned int *p = (uint *) image.scanLine( 0 ); - - for ( int x = 0; x < image.width(); x++ ) - { - scale = 1.0 * x / image.width(); - col.setRgb( color1.red() + int(redDiff*scale), - color1.green() + int(greenDiff*scale), - color1.blue() + int(blueDiff*scale) ); - *p++ = col.rgb(); - } - - for ( int y = 1; y < image.height(); y++ ) - memcpy( image.scanLine( y ), image.scanLine( y - 1), - sizeof( unsigned int ) * image.width() ); - } - - TQColor ditherPalette[8]; - - for ( int s = 0; s < 8; s++ ) - ditherPalette[s].setRgb( color1.red() + redDiff * s / 8, - color1.green() + greenDiff * s / 8, - color1.blue() + blueDiff * s / 8 ); - - KImageEffect::dither( image, ditherPalette, 8 ); - - TQPixmap p; - p.convertFromImage( image ); - - painter->drawPixmap( contentsRect().x(), contentsRect().y(), p ); - - if ( orientation() == Qt::Vertical ) - { - int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2; - int xPos = contentsRect().left() + (contentsRect().width() - - painter->fontMetrics().width( text2 )) / 2; - TQPen pen( color2 ); - painter->setPen( pen ); - painter->drawText( xPos, yPos, text2 ); - - yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2; - xPos = contentsRect().left() + (contentsRect().width() - - painter->fontMetrics().width( text1 )) / 2; - pen.setColor( color1 ); - painter->setPen( pen ); - painter->drawText( xPos, yPos, text1 ); - } - else - { - int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2; - - TQPen pen( color2 ); - painter->setPen( pen ); - painter->drawText( contentsRect().left() + 2, yPos, text1 ); - - pen.setColor( color1 ); - painter->setPen( pen ); - painter->drawText( contentsRect().right() - - painter->fontMetrics().width( text2 ) - 2, yPos, text2 ); - } -} - -//----------------------------------------------------------------------------- - -void KXYSelector::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -void TDESelector::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -void KGradientSelector::virtual_hook( int id, void* data ) -{ TDESelector::virtual_hook( id, data ); } - -#include "kselect.moc" - diff --git a/tdeui/kselect.h b/tdeui/kselect.h deleted file mode 100644 index fd9a90ccd..000000000 --- a/tdeui/kselect.h +++ /dev/null @@ -1,373 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997 Martin Jones (mjones@kde.org) - - This library 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. - - 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. -*/ -//----------------------------------------------------------------------------- -// Selector widgets for KDE Color Selector, but probably useful for other -// stuff also. - -#ifndef __KSELECT_H__ -#define __KSELECT_H__ - -#include -#include -#include - -#include - -/** - * KXYSelector is the base class for other widgets which - * provides the ability to choose from a two-dimensional - * range of values. The currently chosen value is indicated - * by a cross. An example is the KHSSelector which - * allows to choose from a range of colors, and which is - * used in KColorDialog. - * - * A custom drawing routine for the widget surface has - * to be provided by the subclass. - */ -class TDEUI_EXPORT KXYSelector : public TQWidget -{ - Q_OBJECT - TQ_PROPERTY( int xValue READ xValue WRITE setXValue ) - TQ_PROPERTY( int yValue READ yValue WRITE setYValue ) - -public: - /** - * Constructs a two-dimensional selector widget which - * has a value range of [0..100] in both directions. - */ - KXYSelector( TQWidget *parent=0, const char *name=0 ); - /** - * Destructs the widget. - */ - ~KXYSelector(); - - /** - * Sets the current values in horizontal and - * vertical direction. - * @param xPos the horizontal value - * @param yPos the veritcal value - */ - void setValues( int xPos, int yPos ); - - /** - * Sets the current horizontal value - * @param xPos the horizontal value - */ - void setXValue( int xPos ); - - /** - * Sets the current vertical value - * @param yPos the veritcal value - */ - void setYValue( int yPos ); - - /** - * Sets the range of possible values. - */ - void setRange( int minX, int minY, int maxX, int maxY ); - - /** - * @return the current value in horizontal direction. - */ - int xValue() const { return xPos; } - /** - * @return the current value in vertical direction. - */ - int yValue() const { return yPos; } - - /** - * @return the rectangle on which subclasses should draw. - */ - TQRect contentsRect() const; - -signals: - /** - * This signal is emitted whenever the user chooses a value, - * e.g. by clicking with the mouse on the widget. - */ - void valueChanged( int x, int y ); - -protected: - /** - * Override this function to draw the contents of the widget. - * The default implementation does nothing. - * - * Draw within contentsRect() only. - */ - virtual void drawContents( TQPainter * ); - /** - * Override this function to draw the cursor which - * indicates the currently selected value pair. - */ - virtual void drawCursor( TQPainter *p, int xp, int yp ); - - virtual void paintEvent( TQPaintEvent *e ); - virtual void mousePressEvent( TQMouseEvent *e ); - virtual void mouseMoveEvent( TQMouseEvent *e ); - virtual void wheelEvent( TQWheelEvent * ); - - /** - * Converts a pixel position to its corresponding values. - */ - void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const; - -private: - void setPosition( int xp, int yp ); - int px; - int py; - int xPos; - int yPos; - int minX; - int maxX; - int minY; - int maxY; - TQPixmap store; - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class KXYSelectorPrivate; - KXYSelectorPrivate *d; -}; - - -/** - * TDESelector is the base class for other widgets which - * provides the ability to choose from a one-dimensional - * range of values. An example is the KGradientSelector - * which allows to choose from a range of colors. - * - * A custom drawing routine for the widget surface has - * to be provided by the subclass. - */ -class TDEUI_EXPORT TDESelector : public TQWidget, public TQRangeControl -{ - Q_OBJECT - TQ_PROPERTY( int value READ value WRITE setValue ) - TQ_PROPERTY( int minValue READ minValue WRITE setMinValue ) - TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) -public: - - /** - * Constructs a horizontal one-dimensional selection widget. - */ - TDESelector( TQWidget *parent=0, const char *name=0 ); - /** - * Constructs a one-dimensional selection widget with - * a given orientation. - */ - TDESelector( Orientation o, TQWidget *parent = 0L, const char *name = 0L ); - /* - * Destructs the widget. - */ - ~TDESelector(); - - /** - * @return the orientation of the widget. - */ - Orientation orientation() const - { return _orientation; } - - /** - * @return the rectangle on which subclasses should draw. - */ - TQRect contentsRect() const; - - /** - * Sets the indent option of the widget to i. - * This determines whether a shaded frame is drawn. - */ - void setIndent( bool i ) - { _indent = i; } - /** - * @return whether the indent option is set. - */ - bool indent() const - { return _indent; } - - /** - * Sets the value. - */ - void setValue(int value) - { TQRangeControl::setValue(value); } - - /** - * @returns the value. - */ - int value() const - { return TQRangeControl::value(); } - - /** - * Sets the min value. - */ - void setMinValue(int value) - { TQRangeControl::setMinValue(value); } - - /** - * @return the min value. - */ - int minValue() const - { return TQRangeControl::minValue(); } - - /** - * Sets the max value. - */ - void setMaxValue(int value) - { TQRangeControl::setMaxValue(value); } - - /** - * @return the max value. - */ - int maxValue() const - { return TQRangeControl::maxValue(); } - -signals: - /** - * This signal is emitted whenever the user chooses a value, - * e.g. by clicking with the mouse on the widget. - */ - void valueChanged( int value ); - -protected: - /** - * Override this function to draw the contents of the control. - * The default implementation does nothing. - * - * Draw only within contentsRect(). - */ - virtual void drawContents( TQPainter * ); - /** - * Override this function to draw the cursor which - * indicates the current value. This function is - * always called twice, once with argument show=false - * to clear the old cursor, once with argument show=true - * to draw the new one. - */ - virtual void drawArrow( TQPainter *painter, bool show, const TQPoint &pos ); - - virtual void valueChange(); - virtual void paintEvent( TQPaintEvent * ); - virtual void mousePressEvent( TQMouseEvent *e ); - virtual void mouseMoveEvent( TQMouseEvent *e ); - virtual void wheelEvent( TQWheelEvent * ); - -private: - TQPoint calcArrowPos( int val ); - void moveArrow( const TQPoint &pos ); - - Orientation _orientation; - bool _indent; - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class TDESelectorPrivate; - TDESelectorPrivate *d; -}; - - -/** - * The KGradientSelector widget allows the user to choose - * from a one-dimensional range of colors which is given as a - * gradient between two colors provided by the programmer. - * - * \image html kgradientselector.png "KDE Gradient Selector Widget" - * - **/ -class TDEUI_EXPORT KGradientSelector : public TDESelector -{ - Q_OBJECT - - TQ_PROPERTY( TQColor firstColor READ firstColor WRITE setFirstColor ) - TQ_PROPERTY( TQColor secondColor READ secondColor WRITE setSecondColor ) - TQ_PROPERTY( TQString firstText READ firstText WRITE setFirstText ) - TQ_PROPERTY( TQString secondText READ secondText WRITE setSecondText ) - -public: - /** - * Constructs a horizontal color selector which - * contains a gradient between white and black. - */ - KGradientSelector( TQWidget *parent=0, const char *name=0 ); - /** - * Constructs a colors selector with orientation o which - * contains a gradient between white and black. - */ - KGradientSelector( Orientation o, TQWidget *parent=0, const char *name=0 ); - /** - * Destructs the widget. - */ - ~KGradientSelector(); - /** - * Sets the two colors which span the gradient. - */ - void setColors( const TQColor &col1, const TQColor &col2 ) - { color1 = col1; color2 = col2; update();} - void setText( const TQString &t1, const TQString &t2 ) - { text1 = t1; text2 = t2; update(); } - - /** - * Set each color on its own. - */ - void setFirstColor( const TQColor &col ) - { color1 = col; update(); } - void setSecondColor( const TQColor &col ) - { color2 = col; update(); } - - /** - * Set each description on its own - */ - void setFirstText( const TQString &t ) - { text1 = t; update(); } - void setSecondText( const TQString &t ) - { text2 = t; update(); } - - const TQColor firstColor() const - { return color1; } - const TQColor secondColor() const - { return color2; } - - const TQString firstText() const - { return text1; } - const TQString secondText() const - { return text2; } - -protected: - - virtual void drawContents( TQPainter * ); - virtual TQSize minimumSize() const - { return sizeHint(); } - -private: - void init(); - TQColor color1; - TQColor color2; - TQString text1; - TQString text2; - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class KGradientSelectorPrivate; - KGradientSelectorPrivate *d; -}; - - -#endif // __KSELECT_H__ - diff --git a/tdeui/kshortcutdialog.cpp b/tdeui/kshortcutdialog.cpp deleted file mode 100644 index 14cdd9190..000000000 --- a/tdeui/kshortcutdialog.cpp +++ /dev/null @@ -1,529 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2002,2003 Ellis Whitehead - - This library 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. - - 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. -*/ - -#include "kshortcutdialog.h" - -#include - -#ifdef Q_WS_X11 - #define XK_XKB_KEYS - #define XK_MISCELLANY - #include // For x11Event() - #include // For XK_... - - #ifdef KeyPress - const int XKeyPress = KeyPress; - const int XKeyRelease = KeyRelease; - const int XFocusOut = FocusOut; - const int XFocusIn = FocusIn; - #undef KeyRelease - #undef KeyPress - #undef FocusOut - #undef FocusIn - #endif -#elif defined(Q_WS_WIN) -# include -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -bool TDEShortcutDialog::s_showMore = false; - -TDEShortcutDialog::TDEShortcutDialog( const TDEShortcut& shortcut, bool bQtShortcut, TQWidget* parent, const char* name ) -: KDialogBase( parent, name, true, i18n("Configure Shortcut"), - KDialogBase::Details|KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Cancel, true ) -{ - setButtonText(Details, i18n("Advanced")); - m_stack = new TQVBox(this); - m_stack->setMinimumWidth(360); - m_stack->setSpacing(0); - m_stack->setMargin(0); - setMainWidget(m_stack); - - m_simple = new TDEShortcutDialogSimple(m_stack); - - m_adv = new TDEShortcutDialogAdvanced(m_stack); - m_adv->hide(); - - m_bQtShortcut = bQtShortcut; - - m_bGrab = false; - m_iSeq = 0; - m_iKey = 0; - m_ptxtCurrent = 0; - m_bRecording = false; - m_mod = 0; - - m_simple->m_btnClearShortcut->setPixmap( SmallIcon( "locationbar_erase" ) ); - m_adv->m_btnClearPrimary->setPixmap( SmallIcon( "locationbar_erase" ) ); - m_adv->m_btnClearAlternate->setPixmap( SmallIcon( "locationbar_erase" ) ); - connect(m_simple->m_btnClearShortcut, TQT_SIGNAL(clicked()), - this, TQT_SLOT(slotClearShortcut())); - connect(m_adv->m_btnClearPrimary, TQT_SIGNAL(clicked()), - this, TQT_SLOT(slotClearPrimary())); - connect(m_adv->m_btnClearAlternate, TQT_SIGNAL(clicked()), - this, TQT_SLOT(slotClearAlternate())); - - connect(m_adv->m_txtPrimary, TQT_SIGNAL(clicked()), - m_adv->m_btnPrimary, TQT_SLOT(animateClick())); - connect(m_adv->m_txtAlternate, TQT_SIGNAL(clicked()), - m_adv->m_btnAlternate, TQT_SLOT(animateClick())); - connect(m_adv->m_btnPrimary, TQT_SIGNAL(clicked()), - this, TQT_SLOT(slotSelectPrimary())); - connect(m_adv->m_btnAlternate, TQT_SIGNAL(clicked()), - this, TQT_SLOT(slotSelectAlternate())); - - KGuiItem ok = KStdGuiItem::ok(); - ok.setText( i18n( "OK" ) ); - setButtonOK( ok ); - - KGuiItem cancel = KStdGuiItem::cancel(); - cancel.setText( i18n( "Cancel" ) ); - setButtonCancel( cancel ); - - setShortcut( shortcut ); - resize( 0, 0 ); - - s_showMore = TDEConfigGroup(TDEGlobal::config(), "General").readBoolEntry("ShowAlternativeShortcutConfig", s_showMore); - updateDetails(); - - #ifdef Q_WS_X11 - kapp->installX11EventFilter( this ); // Allow button to capture X Key Events. - #endif -} - -TDEShortcutDialog::~TDEShortcutDialog() -{ - TDEConfigGroup group(TDEGlobal::config(), "General"); - group.writeEntry("ShowAlternativeShortcutConfig", s_showMore); -} - -void TDEShortcutDialog::setShortcut( const TDEShortcut & shortcut ) -{ - m_shortcut = shortcut; - updateShortcutDisplay(); -} - -void TDEShortcutDialog::updateShortcutDisplay() -{ - TQString s[2] = { m_shortcut.seq(0).toString(), m_shortcut.seq(1).toString() }; - - if( m_bRecording ) { - m_ptxtCurrent->setDefault( true ); - m_ptxtCurrent->setFocus(); - - // Display modifiers for the first key in the KKeySequence - if( m_iKey == 0 ) { - if( m_mod ) { - TQString keyModStr; - if( m_mod & KKey::WIN ) keyModStr += KKey::modFlagLabel(KKey::WIN) + "+"; - if( m_mod & KKey::ALT ) keyModStr += KKey::modFlagLabel(KKey::ALT) + "+"; - if( m_mod & KKey::CTRL ) keyModStr += KKey::modFlagLabel(KKey::CTRL) + "+"; - if( m_mod & KKey::SHIFT ) keyModStr += KKey::modFlagLabel(KKey::SHIFT) + "+"; - s[m_iSeq] = keyModStr; - } - } - // When in the middle of entering multi-key shortcuts, - // add a "," to the end of the displayed shortcut. - else - s[m_iSeq] += ","; - } - else { - m_adv->m_txtPrimary->setDefault( false ); - m_adv->m_txtAlternate->setDefault( false ); - this->setFocus(); - } - - s[0].replace('&', TQString::fromLatin1("&&")); - s[1].replace('&', TQString::fromLatin1("&&")); - - m_simple->m_txtShortcut->setText( s[0] ); - m_adv->m_txtPrimary->setText( s[0] ); - m_adv->m_txtAlternate->setText( s[1] ); - - // Determine the enable state of the 'Less' button - bool bLessOk; - // If there is no shortcut defined, - if( m_shortcut.count() == 0 ) - bLessOk = true; - // If there is a single shortcut defined, and it is not a multi-key shortcut, - else if( m_shortcut.count() == 1 && m_shortcut.seq(0).count() <= 1 ) - bLessOk = true; - // Otherwise, we have an alternate shortcut or multi-key shortcut(s). - else - bLessOk = false; - enableButton(Details, bLessOk); -} - -void TDEShortcutDialog::slotDetails() -{ - s_showMore = (m_adv->isHidden()); - updateDetails(); -} - -void TDEShortcutDialog::updateDetails() -{ - bool showAdvanced = s_showMore || (m_shortcut.count() > 1); - setDetails(showAdvanced); - m_bRecording = false; - m_iSeq = 0; - m_iKey = 0; - - if (showAdvanced) - { - m_simple->hide(); - m_adv->show(); - m_adv->m_btnPrimary->setChecked( true ); - slotSelectPrimary(); - } - else - { - m_ptxtCurrent = m_simple->m_txtShortcut; - m_adv->hide(); - m_simple->show(); - m_simple->m_txtShortcut->setDefault( true ); - m_simple->m_txtShortcut->setFocus(); - m_adv->m_btnMultiKey->setChecked( false ); - } - kapp->processEvents(); - adjustSize(); -} - -void TDEShortcutDialog::slotSelectPrimary() -{ - m_bRecording = false; - m_iSeq = 0; - m_iKey = 0; - m_ptxtCurrent = m_adv->m_txtPrimary; - m_ptxtCurrent->setDefault(true); - m_ptxtCurrent->setFocus(); - updateShortcutDisplay(); -} - -void TDEShortcutDialog::slotSelectAlternate() -{ - m_bRecording = false; - m_iSeq = 1; - m_iKey = 0; - m_ptxtCurrent = m_adv->m_txtAlternate; - m_ptxtCurrent->setDefault(true); - m_ptxtCurrent->setFocus(); - updateShortcutDisplay(); -} - -void TDEShortcutDialog::slotClearShortcut() -{ - m_shortcut.setSeq( 0, KKeySequence() ); - updateShortcutDisplay(); -} - -void TDEShortcutDialog::slotClearPrimary() -{ - m_shortcut.setSeq( 0, KKeySequence() ); - m_adv->m_btnPrimary->setChecked( true ); - slotSelectPrimary(); -} - -void TDEShortcutDialog::slotClearAlternate() -{ - if( m_shortcut.count() == 2 ) - m_shortcut.init( m_shortcut.seq(0) ); - m_adv->m_btnAlternate->setChecked( true ); - slotSelectAlternate(); -} - -void TDEShortcutDialog::slotMultiKeyMode( bool bOn ) -{ - // If turning off multi-key mode during a recording, - if( !bOn && m_bRecording ) { - m_bRecording = false; - m_iKey = 0; - updateShortcutDisplay(); - } -} - -#ifdef Q_WS_X11 -/* we don't use the generic Qt code on X11 because it allows us - to grab the keyboard so that all keypresses are seen - */ -bool TDEShortcutDialog::x11Event( XEvent *pEvent ) -{ - switch( pEvent->type ) { - case XKeyPress: - x11KeyPressEvent( pEvent ); - return true; - case XKeyRelease: - x11KeyReleaseEvent( pEvent ); - return true; - case XFocusIn: - if (!m_bGrab) { - //kdDebug(125) << "FocusIn and Grab!" << endl; - grabKeyboard(); - m_bGrab = true; - } - //else - // kdDebug(125) << "FocusIn" << endl; - break; - case XFocusOut: - if (m_bGrab) { - //kdDebug(125) << "FocusOut and Ungrab!" << endl; - releaseKeyboard(); - m_bGrab = false; - } - //else - // kdDebug(125) << "FocusOut" << endl; - break; - default: - //kdDebug(125) << "x11Event->type = " << pEvent->type << endl; - break; - } - return KDialogBase::x11Event( pEvent ); -} - -static uint getModsFromModX( uint keyModX ) -{ - uint mod = 0; - if( keyModX & KKeyNative::modX(KKey::SHIFT) ) mod += KKey::SHIFT; - if( keyModX & KKeyNative::modX(KKey::CTRL) ) mod += KKey::CTRL; - if( keyModX & KKeyNative::modX(KKey::ALT) ) mod += KKey::ALT; - if( keyModX & KKeyNative::modX(KKey::WIN) ) mod += KKey::WIN; - return mod; -} - -static bool convertSymXToMod( uint keySymX, uint* pmod ) -{ - switch( keySymX ) { - // Don't allow setting a modifier key as an accelerator. - // Also, don't release the focus yet. We'll wait until - // we get a 'normal' key. - case XK_Shift_L: case XK_Shift_R: *pmod = KKey::SHIFT; break; - case XK_Control_L: case XK_Control_R: *pmod = KKey::CTRL; break; - case XK_Alt_L: case XK_Alt_R: *pmod = KKey::ALT; break; - // FIXME: check whether the Meta or Super key are for the Win modifier - case XK_Meta_L: case XK_Meta_R: - case XK_Super_L: case XK_Super_R: *pmod = KKey::WIN; break; - case XK_Hyper_L: case XK_Hyper_R: - case XK_Mode_switch: - case XK_Num_Lock: - case XK_Caps_Lock: - break; - default: - return false; - } - return true; -} - -void TDEShortcutDialog::x11KeyPressEvent( XEvent* pEvent ) -{ - KKeyNative keyNative( pEvent ); - uint keyModX = keyNative.mod(); - uint keySymX = keyNative.sym(); - - m_mod = getModsFromModX( keyModX ); - - if( keySymX ) { - m_bRecording = true; - - uint mod = 0; - if( convertSymXToMod( keySymX, &mod ) ) { - if( mod ) - m_mod |= mod; - } - else - keyPressed( KKey(keyNative) ); - } - updateShortcutDisplay(); -} - -void TDEShortcutDialog::x11KeyReleaseEvent( XEvent* pEvent ) -{ - // We're only interested in the release of modifier keys, - // and then only when it's for the first key in a sequence. - if( m_bRecording && m_iKey == 0 ) { - KKeyNative keyNative( pEvent ); - uint keyModX = keyNative.mod(); - uint keySymX = keyNative.sym(); - - m_mod = getModsFromModX( keyModX ); - - uint mod = 0; - if( convertSymXToMod( keySymX, &mod ) && mod ) { - m_mod &= ~mod; - if( !m_mod ) - m_bRecording = false; - } - updateShortcutDisplay(); - } -} -#elif defined(Q_WS_WIN) -void TDEShortcutDialog::keyPressEvent( TQKeyEvent * e ) -{ - kdDebug() << e->text() << " " << (int)e->text()[0].latin1()<< " " << (int)e->ascii() << endl; - //if key is a letter, it must be stored as lowercase - int keyQt = TQChar( e->key() & 0xff ).isLetter() ? - (TQChar( e->key() & 0xff ).lower().latin1() | (e->key() & 0xffff00) ) - : e->key(); - int modQt = KKeyServer::qtButtonStateToMod( e->state() ); - KKeyNative keyNative( KKey(keyQt, modQt) ); - m_mod = keyNative.mod(); - uint keySym = keyNative.sym(); - - switch( keySym ) { - case Key_Shift: - m_mod |= KKey::SHIFT; - m_bRecording = true; - break; - case Key_Control: - m_mod |= KKey::CTRL; - m_bRecording = true; - break; - case Key_Alt: - m_mod |= KKey::ALT; - m_bRecording = true; - break; - case Key_Menu: - case Key_Meta: //unused - break; - default: - if( keyNative.sym() == Key_Return && m_iKey > 0 ) { - accept(); - return; - } - //accept - if (keyNative.sym()) { - KKey key = keyNative; - key.simplify(); - KKeySequence seq; - if( m_iKey == 0 ) - seq = key; - else { - seq = m_shortcut.seq( m_iSeq ); - seq.setKey( m_iKey, key ); - } - m_shortcut.setSeq( m_iSeq, seq ); - - if(m_adv->m_btnMultiKey->isChecked()) - m_iKey++; - - m_bRecording = true; - - updateShortcutDisplay(); - - if( !m_adv->m_btnMultiKey->isChecked() ) - TQTimer::singleShot(500, this, TQT_SLOT(accept())); - } - return; - } - - // If we are editing the first key in the sequence, - // display modifier keys which are held down - if( m_iKey == 0 ) { - updateShortcutDisplay(); - } -} - -bool TDEShortcutDialog::event ( TQEvent * e ) -{ - if (e->type()==TQEvent::KeyRelease) { - int modQt = KKeyServer::qtButtonStateToMod( static_cast(e)->state() ); - KKeyNative keyNative( KKey(static_cast(e)->key(), modQt) ); - uint keySym = keyNative.sym(); - - bool change = true; - switch( keySym ) { - case Key_Shift: - if (m_mod & KKey::SHIFT) - m_mod ^= KKey::SHIFT; - break; - case Key_Control: - if (m_mod & KKey::CTRL) - m_mod ^= KKey::CTRL; - break; - case Key_Alt: - if (m_mod & KKey::ALT) - m_mod ^= KKey::ALT; - break; - default: - change = false; - } - if (change) - updateShortcutDisplay(); - } - return KDialogBase::event(e); -} -#endif - -void TDEShortcutDialog::keyPressed( KKey key ) -{ - kdDebug(125) << "keyPressed: " << key.toString() << endl; - - key.simplify(); - if( m_bQtShortcut ) { - key = key.keyCodeQt(); - if( key.isNull() ) { - // TODO: message box about key not able to be used as application shortcut - } - } - - KKeySequence seq; - if( m_iKey == 0 ) - seq = key; - else { - // Remove modifiers - key.init( key.sym(), 0 ); - seq = m_shortcut.seq( m_iSeq ); - seq.setKey( m_iKey, key ); - } - - m_shortcut.setSeq( m_iSeq, seq ); - - m_mod = 0; - if( m_adv->m_btnMultiKey->isChecked() && m_iKey < KKeySequence::MAX_KEYS - 1 ) - m_iKey++; - else { - m_iKey = 0; - m_bRecording = false; - } - - updateShortcutDisplay(); - - if( !m_adv->m_btnMultiKey->isChecked() ) - TQTimer::singleShot(500, this, TQT_SLOT(accept())); -} - -#include "kshortcutdialog.moc" diff --git a/tdeui/kshortcutdialog.h b/tdeui/kshortcutdialog.h deleted file mode 100644 index 59a4bb565..000000000 --- a/tdeui/kshortcutdialog.h +++ /dev/null @@ -1,96 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2002,2003 Ellis Whitehead - - This library 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. - - 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 _KSHORTCUTDIALOG_H_ -#define _KSHORTCUTDIALOG_H_ - -#include "kdialogbase.h" -#include "kshortcut.h" - -class TQVBox; -class KPushButton; -class TDEShortcutDialogSimple; -class TDEShortcutDialogAdvanced; - -/** - * @short Dialog for configuring a shortcut. - * - * This dialog allows configuring a single TDEShortcut. KKeyDialog - * should be usually used instead. - * - * @internal - * @see KKeyDialog - * @since 3.4 - */ -class TDEUI_EXPORT TDEShortcutDialog : public KDialogBase -{ - Q_OBJECT -public: - TDEShortcutDialog( const TDEShortcut& shortcut, bool bQtShortcut, TQWidget* parent = 0, const char* name = 0 ); - ~TDEShortcutDialog(); - - void setShortcut( const TDEShortcut & shortcut ); - const TDEShortcut& shortcut() const { return m_shortcut; } - -private: - // true if qt shortcut, false if native shortcut - bool m_bQtShortcut; - - TDEShortcut m_shortcut; - bool m_bGrab; - KPushButton* m_ptxtCurrent; - uint m_iSeq; - uint m_iKey; - bool m_bRecording; - uint m_mod; - TDEShortcutDialogSimple *m_simple; - TDEShortcutDialogAdvanced *m_adv; - TQVBox *m_stack; - - void updateShortcutDisplay(); - //void displayMods(); - void keyPressed( KKey key ); - void updateDetails(); - - #ifdef Q_WS_X11 - virtual bool x11Event( XEvent *pEvent ); - //void x11EventKeyPress( XEvent *pEvent ); - void x11KeyPressEvent( XEvent* pEvent ); - void x11KeyReleaseEvent( XEvent* pEvent ); - #endif - #ifdef Q_WS_WIN - virtual void keyPressEvent( TQKeyEvent * e ); - virtual bool event(TQEvent * e); - #endif - -protected slots: - void slotDetails(); - void slotSelectPrimary(); - void slotSelectAlternate(); - void slotClearShortcut(); - void slotClearPrimary(); - void slotClearAlternate(); - void slotMultiKeyMode( bool bOn ); - -private: - class TDEShortcutDialogPrivate* d; - static bool s_showMore; -}; - -#endif // _KSHORTCUTDIALOG_H_ diff --git a/tdeui/kshortcutdialog_advanced.ui b/tdeui/kshortcutdialog_advanced.ui deleted file mode 100644 index 77c7fae14..000000000 --- a/tdeui/kshortcutdialog_advanced.ui +++ /dev/null @@ -1,254 +0,0 @@ - -TDEShortcutDialogAdvanced - - - TDEShortcutDialogAdvanced - - - - 0 - 0 - 359 - 157 - - - - - 3 - 3 - 0 - 0 - - - - - unnamed - - - 0 - - - - m_frameMore - - - NoFrame - - - Plain - - - - - - - unnamed - - - 0 - - - - m_btnAlternate - - - NoFocus - - - Alternate shortcut: - - - - - m_btnPrimary - - - NoFocus - - - Primary shortcut: - - - - - layout6 - - - - unnamed - - - - m_txtAlternate - - - - 255 - 255 - 255 - - - - ClickFocus - - - - - - false - - - false - - - - - spacer6 - - - Horizontal - - - Expanding - - - - 21 - 20 - - - - - - - - layout7 - - - - unnamed - - - - m_txtPrimary - - - - 255 - 255 - 255 - - - - 4 - - - ClickFocus - - - - - - false - - - The currently set shortcut or the shortcut you are entering will show up here. - - - - - spacer5 - - - Horizontal - - - Expanding - - - - 21 - 20 - - - - - - - - m_btnClearPrimary - - - x - - - true - - - Clear shortcut - - - - - m_btnClearAlternate - - - x - - - true - - - Clear shortcut - - - - - m_btnMultiKey - - - NoFocus - - - Multi-key mode - - - Enable the entry of multi-key shortcuts - - - Select this checkbox to enable the entry of multi-key shortcuts. A multi-key shortcut consists of a sequence of up to 4 keys. For example, you could assign "Ctrl+F,B" to Font-Bold and "Ctrl+F,U" to Font-Underline. - - - - - - - - - m_txtPrimary - clicked() - m_btnPrimary - animateClick() - - - m_txtAlternate - clicked() - m_btnAlternate - animateClick() - - - - kshortcut.h - kdialog.h - kpushbutton.h - - - class TDEShortcut - - - - - kpushbutton.h - kpushbutton.h - - diff --git a/tdeui/kshortcutdialog_simple.ui b/tdeui/kshortcutdialog_simple.ui deleted file mode 100644 index e271e2bd6..000000000 --- a/tdeui/kshortcutdialog_simple.ui +++ /dev/null @@ -1,120 +0,0 @@ - -TDEShortcutDialogSimple - - - TDEShortcutDialogSimple - - - - 0 - 0 - 177 - 36 - - - - - unnamed - - - 0 - - - - textLabel2 - - - Shortcut: - - - - - spacer3 - - - Vertical - - - Expanding - - - - 20 - 0 - - - - - - m_txtShortcut - - - - 255 - 255 - 255 - - - - 4 - - - ClickFocus - - - Alt+Tab - - - false - - - false - - - - - m_btnClearShortcut - - - x - - - true - - - Clear shortcut - - - - - spacer2 - - - Horizontal - - - Expanding - - - - 40 - 20 - - - - - - - kshortcut.h - kdialog.h - kpushbutton.h - - - class TDEShortcut - - - - - kpushbutton.h - - diff --git a/tdeui/ktoolbar.cpp b/tdeui/ktoolbar.cpp deleted file mode 100644 index 71d182275..000000000 --- a/tdeui/ktoolbar.cpp +++ /dev/null @@ -1,2264 +0,0 @@ -/* This file is part of the KDE libraries - Copyright - (C) 2000 Reginald Stadlbauer (reggie@kde.org) - (C) 1997, 1998 Stephan Kulow (coolo@kde.org) - (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) - (C) 1997, 1998 Sven Radej (radej@kde.org) - (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) - (C) 1999 Chris Schlaeger (cs@kde.org) - (C) 1999 Kurt Granroth (granroth@kde.org) - - 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. -*/ - -#include - -#ifdef KDE_USE_FINAL -#undef Always -#include -#endif - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum { - CONTEXT_TOP = 0, - CONTEXT_LEFT = 1, - CONTEXT_RIGHT = 2, - CONTEXT_BOTTOM = 3, - CONTEXT_FLOAT = 4, - CONTEXT_FLAT = 5, - CONTEXT_ICONS = 6, - CONTEXT_TEXT = 7, - CONTEXT_TEXTRIGHT = 8, - CONTEXT_TEXTUNDER = 9, - CONTEXT_ICONSIZES = 50 // starting point for the icon size list, put everything else before -}; - -class TDEToolBarPrivate -{ -public: - TDEToolBarPrivate() { - m_iconSize = 0; - m_iconText = TDEToolBar::IconOnly; - m_highlight = true; - m_transparent = true; - m_honorStyle = false; - - m_enableContext = true; - - m_xmlguiClient = 0; - - oldPos = TQt::DockUnmanaged; - - modified = m_isHorizontal = positioned = false; - - IconSizeDefault = 0; - IconTextDefault = "IconOnly"; - - NewLineDefault = false; - OffsetDefault = 0; - PositionDefault = "Top"; - HiddenDefault = false; - idleButtons.setAutoDelete(true); - } - - int m_iconSize; - TDEToolBar::IconText m_iconText; - bool m_highlight : 1; - bool m_transparent : 1; - bool m_honorStyle : 1; - bool m_isHorizontal : 1; - bool m_enableContext : 1; - bool modified : 1; - bool positioned : 1; - - TQWidget *m_parent; - - TQMainWindow::ToolBarDock oldPos; - - KXMLGUIClient *m_xmlguiClient; - - struct ToolBarInfo - { - ToolBarInfo() : index( -1 ), offset( -1 ), newline( false ), dock( TQt::DockTop ) {} - ToolBarInfo( TQt::Dock d, int i, bool n, int o ) : index( i ), offset( o ), newline( n ), dock( d ) {} - int index, offset; - bool newline; - TQt::Dock dock; - }; - - ToolBarInfo toolBarInfo; - TQValueList iconSizes; - TQTimer repaintTimer; - - // Default Values. - bool HiddenDefault; - int IconSizeDefault; - TQString IconTextDefault; - bool NewLineDefault; - int OffsetDefault; - TQString PositionDefault; - - TQPtrList idleButtons; -}; - -TDEToolBarSeparator::TDEToolBarSeparator(Orientation o , bool l, TQToolBar *parent, - const char* name ) - :TQFrame( parent, name ), line( l ) -{ - connect( parent, TQT_SIGNAL(orientationChanged(Orientation)), - this, TQT_SLOT(setOrientation(Orientation)) ); - setOrientation( o ); - setBackgroundMode( parent->backgroundMode() ); - setBackgroundOrigin( ParentOrigin ); -} - -void TDEToolBarSeparator::setOrientation( Orientation o ) -{ - orient = o; - setFrameStyle( NoFrame ); -} - -void TDEToolBarSeparator::drawContents( TQPainter* p ) -{ - if ( line ) { - TQStyle::SFlags flags = TQStyle::Style_Default; - - if ( orientation() == Qt::Horizontal ) - flags = flags | TQStyle::Style_Horizontal; - - style().tqdrawPrimitive(TQStyle::PE_DockWindowSeparator, p, - contentsRect(), colorGroup(), flags); - } else { - TQFrame::drawContents(p); - } -} - -void TDEToolBarSeparator::styleChange( TQStyle& ) -{ - setOrientation( orient ); -} - -TQSize TDEToolBarSeparator::sizeHint() const -{ - int dim = style().pixelMetric( TQStyle::PM_DockWindowSeparatorExtent, this ); - return orientation() == Qt::Vertical ? TQSize( 0, dim ) : TQSize( dim, 0 ); -} - -TQSizePolicy TDEToolBarSeparator::sizePolicy() const -{ - return TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ); -} - -TDEToolBar::TDEToolBar( TQWidget *parent, const char *name, bool honorStyle, bool readConfig ) - : TQToolBar( TQString::fromLatin1( name ), - tqt_dynamic_cast(parent), - parent, false, - name ? name : "mainToolBar") -{ - init( readConfig, honorStyle ); -} - -TDEToolBar::TDEToolBar( TQMainWindow *parentWindow, TQMainWindow::ToolBarDock dock, bool newLine, const char *name, bool honorStyle, bool readConfig ) - : TQToolBar( TQString::fromLatin1( name ), - parentWindow, dock, newLine, - name ? name : "mainToolBar") -{ - init( readConfig, honorStyle ); -} - -TDEToolBar::TDEToolBar( TQMainWindow *parentWindow, TQWidget *dock, bool newLine, const char *name, bool honorStyle, bool readConfig ) - : TQToolBar( TQString::fromLatin1( name ), - parentWindow, dock, newLine, - name ? name : "mainToolBar") -{ - init( readConfig, honorStyle ); -} - -TDEToolBar::~TDEToolBar() -{ - emit toolbarDestroyed(); - delete d; -} - -void TDEToolBar::init( bool readConfig, bool honorStyle ) -{ - d = new TDEToolBarPrivate; - setFullSize( true ); - d->m_honorStyle = honorStyle; - context = 0; - layoutTimer = new TQTimer( this ); - connect( layoutTimer, TQT_SIGNAL( timeout() ), - this, TQT_SLOT( rebuildLayout() ) ); - connect( &(d->repaintTimer), TQT_SIGNAL( timeout() ), - this, TQT_SLOT( slotRepaint() ) ); - - if ( kapp ) { // may be null when started inside designer - connect(kapp, TQT_SIGNAL(toolbarAppearanceChanged(int)), this, TQT_SLOT(slotAppearanceChanged())); - // request notification of changes in icon style - kapp->addKipcEventMask(KIPC::IconChanged); - connect(kapp, TQT_SIGNAL(iconChanged(int)), this, TQT_SLOT(slotIconChanged(int))); - } - - // finally, read in our configurable settings - if ( readConfig ) - slotReadConfig(); - - if ( mainWindow() ) - connect( mainWindow(), TQT_SIGNAL( toolBarPositionChanged( TQToolBar * ) ), - this, TQT_SLOT( toolBarPosChanged( TQToolBar * ) ) ); - - // Hack to make sure we recalculate our size when we dock. - connect( this, TQT_SIGNAL(placeChanged(TQDockWindow::Place)), TQT_SLOT(rebuildLayout()) ); -} - -int TDEToolBar::insertButton(const TQString& icon, int id, bool enabled, - const TQString& text, int index, TDEInstance *_instance ) -{ - TDEToolBarButton *button = new TDEToolBarButton( icon, id, this, 0, text, _instance ); - - insertWidgetInternal( button, index, id ); - button->setEnabled( enabled ); - doConnections( button ); - return index; -} - - -int TDEToolBar::insertButton(const TQString& icon, int id, const char *signal, - const TQObject *receiver, const char *slot, - bool enabled, const TQString& text, int index, TDEInstance *_instance ) -{ - TDEToolBarButton *button = new TDEToolBarButton( icon, id, this, 0, text, _instance); - insertWidgetInternal( button, index, id ); - button->setEnabled( enabled ); - connect( button, signal, receiver, slot ); - doConnections( button ); - return index; -} - - -int TDEToolBar::insertButton(const TQPixmap& pixmap, int id, bool enabled, - const TQString& text, int index ) -{ - TDEToolBarButton *button = new TDEToolBarButton( pixmap, id, this, 0, text); - insertWidgetInternal( button, index, id ); - button->setEnabled( enabled ); - doConnections( button ); - return index; -} - - -int TDEToolBar::insertButton(const TQPixmap& pixmap, int id, const char *signal, - const TQObject *receiver, const char *slot, - bool enabled, const TQString& text, - int index ) -{ - TDEToolBarButton *button = new TDEToolBarButton( pixmap, id, this, 0, text); - insertWidgetInternal( button, index, id ); - button->setEnabled( enabled ); - connect( button, signal, receiver, slot ); - doConnections( button ); - return index; -} - - -int TDEToolBar::insertButton(const TQString& icon, int id, TQPopupMenu *popup, - bool enabled, const TQString &text, int index ) -{ - TDEToolBarButton *button = new TDEToolBarButton( icon, id, this, 0, text ); - insertWidgetInternal( button, index, id ); - button->setEnabled( enabled ); - button->setPopup( popup ); - doConnections( button ); - return index; -} - - -int TDEToolBar::insertButton(const TQPixmap& pixmap, int id, TQPopupMenu *popup, - bool enabled, const TQString &text, int index ) -{ - TDEToolBarButton *button = new TDEToolBarButton( pixmap, id, this, 0, text ); - insertWidgetInternal( button, index, id ); - button->setEnabled( enabled ); - button->setPopup( popup ); - doConnections( button ); - return index; -} - - -int TDEToolBar::insertLined (const TQString& text, int id, - const char *signal, - const TQObject *receiver, const char *slot, - bool enabled , - const TQString& toolTipText, - int size, int index ) -{ - KLineEdit *lined = new KLineEdit ( this, 0 ); - if ( !toolTipText.isEmpty() ) - TQToolTip::add( lined, toolTipText ); - if ( size > 0 ) - lined->setMinimumWidth( size ); - insertWidgetInternal( lined, index, id ); - connect( lined, signal, receiver, slot ); - lined->setText(text); - lined->setEnabled( enabled ); - return index; -} - -int TDEToolBar::insertCombo (const TQStringList &list, int id, bool writable, - const char *signal, const TQObject *receiver, - const char *slot, bool enabled, - const TQString& tooltiptext, - int size, int index, - TQComboBox::Policy policy ) -{ - KComboBox *combo = new KComboBox ( writable, this ); - - insertWidgetInternal( combo, index, id ); - combo->insertStringList (list); - combo->setInsertionPolicy(policy); - combo->setEnabled( enabled ); - if ( size > 0 ) - combo->setMinimumWidth( size ); - if (!tooltiptext.isNull()) - TQToolTip::add( combo, tooltiptext ); - - if ( signal && receiver && slot ) - connect ( combo, signal, receiver, slot ); - return index; -} - - -int TDEToolBar::insertCombo (const TQString& text, int id, bool writable, - const char *signal, TQObject *receiver, - const char *slot, bool enabled, - const TQString& tooltiptext, - int size, int index, - TQComboBox::Policy policy ) -{ - KComboBox *combo = new KComboBox ( writable, this ); - insertWidgetInternal( combo, index, id ); - combo->insertItem (text); - combo->setInsertionPolicy(policy); - combo->setEnabled( enabled ); - if ( size > 0 ) - combo->setMinimumWidth( size ); - if (!tooltiptext.isNull()) - TQToolTip::add( combo, tooltiptext ); - connect (combo, signal, receiver, slot); - return index; -} - -int TDEToolBar::insertSeparator(int index, int id) -{ - TQWidget *w = new TDEToolBarSeparator( orientation(), false, this, "tool bar separator" ); - insertWidgetInternal( w, index, id ); - return index; -} - -int TDEToolBar::insertLineSeparator(int index, int id) -{ - TQWidget *w = new TDEToolBarSeparator( orientation(), true, this, "tool bar separator" ); - insertWidgetInternal( w, index, id ); - return index; -} - - -int TDEToolBar::insertWidget(int id, int /*width*/, TQWidget *widget, int index) -{ - removeWidgetInternal( widget ); // in case we already have it ? - insertWidgetInternal( widget, index, id ); - return index; -} - -int TDEToolBar::insertAnimatedWidget(int id, TQObject *receiver, const char *slot, - const TQString& icons, int index ) -{ - KAnimWidget *anim = new KAnimWidget( icons, d->m_iconSize, this ); - insertWidgetInternal( anim, index, id ); - - if ( receiver ) - connect( anim, TQT_SIGNAL(clicked()), receiver, slot); - - return index; -} - -KAnimWidget *TDEToolBar::animatedWidget( int id ) -{ - Id2WidgetMap::Iterator it = id2widget.find( id ); - if ( it == id2widget.end() ) - return 0; - KAnimWidget *aw = tqt_dynamic_cast(*it); - if ( aw ) - return aw; - TQObjectList *l = queryList( "KAnimWidget" ); - if ( !l || !l->first() ) { - delete l; - return 0; - } - - for ( TQObject *o = l->first(); o; o = l->next() ) { - KAnimWidget *aw = tqt_dynamic_cast(o); - if ( aw ) - { - delete l; - return aw; - } - } - - delete l; - return 0; -} - - -void TDEToolBar::addConnection (int id, const char *signal, - const TQObject *receiver, const char *slot) -{ - TQWidget* w = getWidget( id ); - if ( w ) - connect( w, signal, receiver, slot ); -} - -void TDEToolBar::setItemEnabled( int id, bool enabled ) -{ - TQWidget* w = getWidget( id ); - if ( w ) - w->setEnabled( enabled ); -} - - -void TDEToolBar::setButtonPixmap( int id, const TQPixmap& _pixmap ) -{ - TDEToolBarButton * button = getButton( id ); - if ( button ) - button->setPixmap( _pixmap ); -} - - -void TDEToolBar::setButtonIcon( int id, const TQString& _icon ) -{ - TDEToolBarButton * button = getButton( id ); - if ( button ) - button->setIcon( _icon ); -} - -void TDEToolBar::setButtonIconSet( int id, const TQIconSet& iconset ) -{ - TDEToolBarButton * button = getButton( id ); - if ( button ) - button->setIconSet( iconset ); -} - - -void TDEToolBar::setDelayedPopup (int id , TQPopupMenu *_popup, bool toggle ) -{ - TDEToolBarButton * button = getButton( id ); - if ( button ) - button->setDelayedPopup( _popup, toggle ); -} - - -void TDEToolBar::setAutoRepeat (int id, bool flag) -{ - TDEToolBarButton * button = getButton( id ); - if ( button ) - button->setAutoRepeat( flag ); -} - - -void TDEToolBar::setToggle (int id, bool flag ) -{ - TDEToolBarButton * button = getButton( id ); - if ( button ) - button->setToggle( flag ); -} - - -void TDEToolBar::toggleButton (int id) -{ - TDEToolBarButton * button = getButton( id ); - if ( button ) - button->toggle(); -} - - -void TDEToolBar::setButton (int id, bool flag) -{ - TDEToolBarButton * button = getButton( id ); - if ( button ) - button->on( flag ); -} - - -bool TDEToolBar::isButtonOn (int id) const -{ - TDEToolBarButton * button = const_cast( this )->getButton( id ); - return button ? button->isOn() : false; -} - - -void TDEToolBar::setLinedText (int id, const TQString& text) -{ - KLineEdit * lineEdit = getLined( id ); - if ( lineEdit ) - lineEdit->setText( text ); -} - - -TQString TDEToolBar::getLinedText (int id) const -{ - KLineEdit * lineEdit = const_cast( this )->getLined( id ); - return lineEdit ? lineEdit->text() : TQString::null; -} - - -void TDEToolBar::insertComboItem (int id, const TQString& text, int index) -{ - KComboBox * comboBox = getCombo( id ); - if (comboBox) - comboBox->insertItem( text, index ); -} - -void TDEToolBar::insertComboList (int id, const TQStringList &list, int index) -{ - KComboBox * comboBox = getCombo( id ); - if (comboBox) - comboBox->insertStringList( list, index ); -} - - -void TDEToolBar::removeComboItem (int id, int index) -{ - KComboBox * comboBox = getCombo( id ); - if (comboBox) - comboBox->removeItem( index ); -} - - -void TDEToolBar::setCurrentComboItem (int id, int index) -{ - KComboBox * comboBox = getCombo( id ); - if (comboBox) - comboBox->setCurrentItem( index ); -} - - -void TDEToolBar::changeComboItem (int id, const TQString& text, int index) -{ - KComboBox * comboBox = getCombo( id ); - if (comboBox) - comboBox->changeItem( text, index ); -} - - -void TDEToolBar::clearCombo (int id) -{ - KComboBox * comboBox = getCombo( id ); - if (comboBox) - comboBox->clear(); -} - - -TQString TDEToolBar::getComboItem (int id, int index) const -{ - KComboBox * comboBox = const_cast( this )->getCombo( id ); - return comboBox ? comboBox->text( index ) : TQString::null; -} - - -KComboBox * TDEToolBar::getCombo(int id) -{ - Id2WidgetMap::Iterator it = id2widget.find( id ); - if ( it == id2widget.end() ) - return 0; - return tqt_dynamic_cast( *it ); -} - - -KLineEdit * TDEToolBar::getLined (int id) -{ - Id2WidgetMap::Iterator it = id2widget.find( id ); - if ( it == id2widget.end() ) - return 0; - return tqt_dynamic_cast( *it ); -} - - -TDEToolBarButton * TDEToolBar::getButton (int id) -{ - Id2WidgetMap::Iterator it = id2widget.find( id ); - if ( it == id2widget.end() ) - return 0; - return tqt_dynamic_cast( *it ); -} - - -void TDEToolBar::alignItemRight (int id, bool right ) -{ - Id2WidgetMap::Iterator it = id2widget.find( id ); - if ( it == id2widget.end() ) - return; - if ( rightAligned && !right && (*it) == rightAligned ) - rightAligned = 0; - if ( (*it) && right ) - rightAligned = (*it); -} - - -TQWidget *TDEToolBar::getWidget (int id) -{ - Id2WidgetMap::Iterator it = id2widget.find( id ); - return ( it == id2widget.end() ) ? 0 : (*it); -} - - -void TDEToolBar::setItemAutoSized (int id, bool yes ) -{ - TQWidget *w = getWidget(id); - if ( w && yes ) - setStretchableWidget( w ); -} - - -void TDEToolBar::clear () -{ - /* Delete any idle buttons, so TQToolBar doesn't delete them itself, making a mess */ - for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next()) - w->blockSignals(false); - d->idleButtons.clear(); - - TQToolBar::clear(); - widget2id.clear(); - id2widget.clear(); -} - - -void TDEToolBar::removeItem(int id) -{ - Id2WidgetMap::Iterator it = id2widget.find( id ); - if ( it == id2widget.end() ) - { - kdDebug(220) << name() << " TDEToolBar::removeItem item " << id << " not found" << endl; - return; - } - TQWidget * w = (*it); - id2widget.remove( id ); - widget2id.remove( w ); - widgets.removeRef( w ); - delete w; -} - - -void TDEToolBar::removeItemDelayed(int id) -{ - Id2WidgetMap::Iterator it = id2widget.find( id ); - if ( it == id2widget.end() ) - { - kdDebug(220) << name() << " TDEToolBar::removeItem item " << id << " not found" << endl; - return; - } - TQWidget * w = (*it); - id2widget.remove( id ); - widget2id.remove( w ); - widgets.removeRef( w ); - - w->blockSignals(true); - d->idleButtons.append(w); - layoutTimer->start( 50, true ); -} - - -void TDEToolBar::hideItem (int id) -{ - TQWidget *w = getWidget(id); - if ( w ) - w->hide(); -} - - -void TDEToolBar::showItem (int id) -{ - TQWidget *w = getWidget(id); - if ( w ) - w->show(); -} - - -int TDEToolBar::itemIndex (int id) -{ - TQWidget *w = getWidget(id); - return w ? widgets.findRef(w) : -1; -} - -int TDEToolBar::idAt (int index) -{ - TQWidget *w = widgets.at(index); - return widget2id[w]; -} - -void TDEToolBar::setFullSize(bool flag ) -{ - setHorizontalStretchable( flag ); - setVerticalStretchable( flag ); -} - - -bool TDEToolBar::fullSize() const -{ - return isHorizontalStretchable() || isVerticalStretchable(); -} - - -void TDEToolBar::enableMoving(bool flag ) -{ - setMovingEnabled(flag); -} - - -void TDEToolBar::setBarPos (BarPosition bpos) -{ - if ( !mainWindow() ) - return; - mainWindow()->moveDockWindow( this, (Dock)bpos ); - //kdDebug(220) << name() << " setBarPos dockWindowIndex=" << dockWindowIndex() << endl; -} - - -TDEToolBar::BarPosition TDEToolBar::barPos() const -{ - if ( !this->mainWindow() ) - return place() == TQDockWindow::InDock ? TDEToolBar::Top : TDEToolBar::Floating; - Dock dock; - int dm1, dm2; - bool dm3; - this->mainWindow()->getLocation( (TQToolBar*)this, dock, dm1, dm3, dm2 ); - if ( dock == DockUnmanaged ) { - return (TDEToolBar::BarPosition)DockTop; - } - return (BarPosition)dock; -} - - -bool TDEToolBar::enable(BarStatus stat) -{ - bool mystat = isVisible(); - - if ( (stat == Toggle && mystat) || stat == Hide ) - hide(); - else - show(); - - return isVisible() == mystat; -} - - -void TDEToolBar::setMaxHeight ( int h ) -{ - setMaximumHeight( h ); -} - -int TDEToolBar::maxHeight() -{ - return maximumHeight(); -} - - -void TDEToolBar::setMaxWidth (int dw) -{ - setMaximumWidth( dw ); -} - - -int TDEToolBar::maxWidth() -{ - return maximumWidth(); -} - - -void TDEToolBar::setTitle (const TQString& _title) -{ - setLabel( _title ); -} - - -void TDEToolBar::enableFloating (bool ) -{ -} - - -void TDEToolBar::setIconText(IconText it) -{ - setIconText( it, true ); -} - - -void TDEToolBar::setIconText(IconText icontext, bool update) -{ - bool doUpdate=false; - - if (icontext != d->m_iconText) { - d->m_iconText = icontext; - doUpdate=true; - //kdDebug(220) << name() << " icontext has changed, doUpdate=true" << endl; - } - else { - //kdDebug(220) << name() << " icontext hasn't changed, doUpdate=false" << endl; - } - - if (!update) - return; - - if (doUpdate) - doModeChange(); // tell buttons what happened - - // ugly hack to force a TQMainWindow::triggerLayout( true ) - TQMainWindow *mw = mainWindow(); - if ( mw ) { - mw->setUpdatesEnabled( false ); -// mw->setToolBarsMovable( !mw->toolBarsMovable() ); // Old way -// mw->setToolBarsMovable( !mw->toolBarsMovable() ); - mw->setCentralWidget(mw->centralWidget()); // This is a faster hack - mw->setUpdatesEnabled( true ); - } -} - - -TDEToolBar::IconText TDEToolBar::iconText() const -{ - return d->m_iconText; -} - - -void TDEToolBar::setIconSize(int size) -{ - setIconSize( size, true ); -} - -void TDEToolBar::setIconSize(int size, bool update) -{ - bool doUpdate=false; - - if ( size != d->m_iconSize ) { - d->m_iconSize = size; - doUpdate=true; - } - - if (!update) - return; - - if (doUpdate) - doModeChange(); // tell buttons what happened - - // ugly hack to force a TQMainWindow::triggerLayout( true ) - if ( mainWindow() ) { - TQMainWindow *mw = mainWindow(); - mw->setUpdatesEnabled( false ); -// mw->setToolBarsMovable( !mw->toolBarsMovable() ); // Old way -// mw->setToolBarsMovable( !mw->toolBarsMovable() ); - mw->setCentralWidget(mw->centralWidget()); // This is a faster hack - mw->setUpdatesEnabled( true ); - } -} - -int TDEToolBar::iconSize() const -{ - if ( !d->m_iconSize ) // default value? - return iconSizeDefault(); - - return d->m_iconSize; -} - -int TDEToolBar::iconSizeDefault() const -{ - if (!::qstrcmp(name(), "mainToolBar")) - return TDEGlobal::iconLoader()->currentSize(KIcon::MainToolbar); - - return TDEGlobal::iconLoader()->currentSize(KIcon::Toolbar); -} - -void TDEToolBar::setEnableContextMenu(bool enable ) -{ - d->m_enableContext = enable; -} - - -bool TDEToolBar::contextMenuEnabled() const -{ - return d->m_enableContext; -} - - -void TDEToolBar::setItemNoStyle(int id, bool no_style ) -{ - TDEToolBarButton * button = getButton( id ); - if (button) - button->setNoStyle( no_style ); -} - - -void TDEToolBar::setFlat (bool flag) -{ - if ( !mainWindow() ) - return; - if ( flag ) - mainWindow()->moveDockWindow( this, DockMinimized ); - else - mainWindow()->moveDockWindow( this, DockTop ); - // And remember to save the new look later - TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); - if ( kmw ) - kmw->setSettingsDirty(); -} - - -int TDEToolBar::count() const -{ - return id2widget.count(); -} - - -void TDEToolBar::saveState() -{ - // first, try to save to the xml file - if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() ) { - //kdDebug(220) << name() << " saveState: saving to " << d->m_xmlguiClient->xmlFile() << endl; - TQString barname(!::qstrcmp(name(), "unnamed") ? "mainToolBar" : name()); - // try to find our toolbar - d->modified = false; - // go down one level to get to the right tags - TQDomElement current; - for( TQDomNode n = d->m_xmlguiClient->domDocument().documentElement().firstChild(); - !n.isNull(); n = n.nextSibling()) { - current = n.toElement(); - - if ( current.tagName().lower() != "toolbar" ) - continue; - - TQString curname(current.attribute( "name" )); - - if ( curname == barname ) { - saveState( current ); - break; - } - } - // if we didn't make changes, then just return - if ( !d->modified ) - return; - - // now we load in the (non-merged) local file - TQString local_xml(KXMLGUIFactory::readConfigFile(d->m_xmlguiClient->xmlFile(), true, d->m_xmlguiClient->instance())); - TQDomDocument local; - local.setContent(local_xml); - - // make sure we don't append if this toolbar already exists locally - bool just_append = true; - - for( TQDomNode n = local.documentElement().firstChild(); - !n.isNull(); n = n.nextSibling()) { - TQDomElement elem = n.toElement(); - - if ( elem.tagName().lower() != "toolbar" ) - continue; - - TQString curname(elem.attribute( "name" )); - - if ( curname == barname ) { - just_append = false; - local.documentElement().replaceChild( current, elem ); - break; - } - } - - if (just_append) - local.documentElement().appendChild( current ); - - KXMLGUIFactory::saveConfigFile(local, d->m_xmlguiClient->localXMLFile(), d->m_xmlguiClient->instance() ); - - return; - } - - // if that didn't work, we save to the config file - TDEConfig *config = TDEGlobal::config(); - saveSettings(config, TQString::null); - config->sync(); -} - -TQString TDEToolBar::settingsGroup() const -{ - TQString configGroup; - if (!::qstrcmp(name(), "unnamed") || !::qstrcmp(name(), "mainToolBar")) - configGroup = "Toolbar style"; - else - configGroup = TQString(name()) + " Toolbar style"; - if ( this->mainWindow() ) - { - configGroup.prepend(" "); - configGroup.prepend( this->mainWindow()->name() ); - } - return configGroup; -} - -void TDEToolBar::saveSettings(TDEConfig *config, const TQString &_configGroup) -{ - TQString configGroup = _configGroup; - if (configGroup.isEmpty()) - configGroup = settingsGroup(); - //kdDebug(220) << name() << " saveSettings() group=" << _configGroup << " -> " << configGroup << endl; - - TQString position, icontext; - int index; - getAttributes( position, icontext, index ); - - //kdDebug(220) << name() << " position=" << position << " index=" << index << " offset=" << offset() << " newLine=" << newLine() << endl; - - TDEConfigGroupSaver saver(config, configGroup); - - if(!config->hasDefault("Position") && position == d->PositionDefault ) - config->revertToDefault("Position"); - else - config->writeEntry("Position", position); - - //kdDebug(220) << name() << " icontext=" << icontext << " hasDefault:" << config->hasDefault( "IconText" ) << " d->IconTextDefault=" << d->IconTextDefault << endl; - - if(d->m_honorStyle && icontext == d->IconTextDefault && !config->hasDefault("IconText") ) - { - //kdDebug(220) << name() << " reverting icontext to default" << endl; - config->revertToDefault("IconText"); - } - else - { - //kdDebug(220) << name() << " writing icontext " << icontext << endl; - config->writeEntry("IconText", icontext); - } - - if(!config->hasDefault("IconSize") && iconSize() == iconSizeDefault() ) - config->revertToDefault("IconSize"); - else - config->writeEntry("IconSize", iconSize()); - - if(!config->hasDefault("Hidden") && isHidden() == d->HiddenDefault ) - config->revertToDefault("Hidden"); - else - config->writeEntry("Hidden", isHidden()); - - // Note that index, unlike the other settings, depends on the other toolbars - // So on the first run with a clean local config file, even the usual - // hasDefault/==IndexDefault test would save the toolbar indexes - // (IndexDefault was 0, whereas index is the real index in the GUI) - // - // Saving the whole set of indexes is necessary though. When moving only - // one toolbar, if we only saved the changed indexes, the toolbars wouldn't - // reappear at the same position the next time. - // The whole set of indexes has to be saved. - //kdDebug(220) << name() << " writing index " << index << endl; - TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); - // don't save if there's only one toolbar - - // Don't use kmw->toolBarIterator() because you might - // mess up someone else's iterator. Make the list on your own - TQPtrList toolbarList; - TQPtrList lst; - for ( int i = (int)TQMainWindow::DockUnmanaged; i <= (int)DockMinimized; ++i ) { - lst = kmw->toolBars( (ToolBarDock)i ); - for ( TQToolBar *tb = lst.first(); tb; tb = lst.next() ) { - if ( !tb->inherits( "TDEToolBar" ) ) - continue; - toolbarList.append( (TDEToolBar*)tb ); - } - } - TQPtrListIterator toolbarIterator( toolbarList ); - if ( !kmw || toolbarIterator.count() > 1 ) - config->writeEntry("Index", index); - else - config->revertToDefault("Index"); - - if(!config->hasDefault("Offset") && offset() == d->OffsetDefault ) - config->revertToDefault("Offset"); - else - config->writeEntry("Offset", offset()); - - if(!config->hasDefault("NewLine") && newLine() == d->NewLineDefault ) - config->revertToDefault("NewLine"); - else - config->writeEntry("NewLine", newLine()); -} - - -void TDEToolBar::setXMLGUIClient( KXMLGUIClient *client ) -{ - d->m_xmlguiClient = client; -} - -void TDEToolBar::setText( const TQString & txt ) -{ - setLabel( txt + " (" + kapp->caption() + ") " ); -} - - -TQString TDEToolBar::text() const -{ - return label(); -} - - -void TDEToolBar::doConnections( TDEToolBarButton *button ) -{ - connect(button, TQT_SIGNAL(clicked(int)), this, TQT_SIGNAL( clicked( int ) ) ); - connect(button, TQT_SIGNAL(doubleClicked(int)), this, TQT_SIGNAL( doubleClicked( int ) ) ); - connect(button, TQT_SIGNAL(released(int)), this, TQT_SIGNAL( released( int ) ) ); - connect(button, TQT_SIGNAL(pressed(int)), this, TQT_SIGNAL( pressed( int ) ) ); - connect(button, TQT_SIGNAL(toggled(int)), this, TQT_SIGNAL( toggled( int ) ) ); - connect(button, TQT_SIGNAL(highlighted(int, bool)), this, TQT_SIGNAL( highlighted( int, bool ) ) ); -} - -void TDEToolBar::mousePressEvent ( TQMouseEvent *m ) -{ - if ( !mainWindow() ) - return; - TQMainWindow *mw = mainWindow(); - if ( mw->toolBarsMovable() && d->m_enableContext ) { - if ( m->button() == Qt::RightButton ) { - TQGuardedPtr guard( this ); - int i = contextMenu()->exec( m->globalPos(), 0 ); - // "Configure Toolbars" recreates toolbars, so we might not exist anymore. - if ( guard ) - slotContextAboutToHide(); - switch ( i ) { - case -1: - return; // popup canceled - case CONTEXT_LEFT: - mw->moveDockWindow( this, DockLeft ); - break; - case CONTEXT_RIGHT: - mw->moveDockWindow( this, DockRight ); - break; - case CONTEXT_TOP: - mw->moveDockWindow( this, DockTop ); - break; - case CONTEXT_BOTTOM: - mw->moveDockWindow( this, DockBottom ); - break; - case CONTEXT_FLOAT: - mw->moveDockWindow( this, DockTornOff ); - break; - case CONTEXT_FLAT: - mw->moveDockWindow( this, DockMinimized ); - break; - case CONTEXT_ICONS: - setIconText( IconOnly ); - break; - case CONTEXT_TEXTRIGHT: - setIconText( IconTextRight ); - break; - case CONTEXT_TEXT: - setIconText( TextOnly ); - break; - case CONTEXT_TEXTUNDER: - setIconText( IconTextBottom ); - break; - default: - if ( i >= CONTEXT_ICONSIZES ) - setIconSize( i - CONTEXT_ICONSIZES ); - else - return; // assume this was an action handled elsewhere, no need for setSettingsDirty() - } - TDEMainWindow *kmw = tqt_dynamic_cast(mw); - if ( kmw ) - kmw->setSettingsDirty(); - } - } -} - -void TDEToolBar::doModeChange() -{ - for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next()) - w->blockSignals(false); - d->idleButtons.clear(); - - emit modechange(); -} - -void TDEToolBar::rebuildLayout() -{ - for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next()) - w->blockSignals(false); - d->idleButtons.clear(); - - layoutTimer->stop(); - TQApplication::sendPostedEvents( this, TQEvent::ChildInserted ); - TQBoxLayout *l = boxLayout(); - - // clear the old layout - TQLayoutIterator it = l->iterator(); - while ( it.current() ) - it.deleteCurrent(); - - for ( TQWidget *w = widgets.first(); w; w = widgets.next() ) { - if ( w == rightAligned ) - continue; - TDEToolBarSeparator *ktbs = tqt_dynamic_cast(w); - if ( ktbs && !ktbs->showLine() ) { - l->addSpacing( orientation() == Qt::Vertical ? w->sizeHint().height() : w->sizeHint().width() ); - w->hide(); - continue; - } - if ( tqt_dynamic_cast(w) ) // w is a QPopupMenu? - continue; - l->addWidget( w ); - w->show(); - if ((orientation() == Qt::Horizontal) && tqt_dynamic_cast(w)) // w is TQLineEdit ? - l->addSpacing(2); // A little bit extra spacing behind it. - } - if ( rightAligned ) { - l->addStretch(); - l->addWidget( rightAligned ); - rightAligned->show(); - } - - if ( fullSize() ) { - if ( !rightAligned ) - l->addStretch(); - if ( stretchableWidget ) - l->setStretchFactor( stretchableWidget, 10 ); - } - l->invalidate(); - TQApplication::postEvent( this, new TQEvent( TQEvent::LayoutHint ) ); -} - -void TDEToolBar::childEvent( TQChildEvent *e ) -{ - if ( e->child()->isWidgetType() ) { - TQWidget * w = tqt_dynamic_cast(e->child()); - if (!w || !(::qstrcmp( "qt_dockwidget_internal", w->name()))) - { - TQToolBar::childEvent( e ); - return; - } - if ( e->type() == TQEvent::ChildInserted ) { - if ( !tqt_dynamic_cast(w)) { // e->child() is not a QPopupMenu - // prevent items that have been explicitly inserted by insert*() from - // being inserted again - if ( !widget2id.contains( w ) ) - { - int dummy = -1; - insertWidgetInternal( w, dummy, -1 ); - } - } - } else { - removeWidgetInternal( w ); - } - if ( isVisibleTo( 0 ) ) - { - layoutTimer->start( 50, true ); - TQBoxLayout *l = boxLayout(); - - // clear the old layout so that we don't get unnecessary layout - // changes until we have rebuilt the thing - TQLayoutIterator it = l->iterator(); - while ( it.current() ) - it.deleteCurrent(); - } - } - TQToolBar::childEvent( e ); -} - -void TDEToolBar::insertWidgetInternal( TQWidget *w, int &index, int id ) -{ - // we can't have it in widgets, or something is really wrong - //widgets.removeRef( w ); - - connect( w, TQT_SIGNAL( destroyed() ), - this, TQT_SLOT( widgetDestroyed() ) ); - if ( index == -1 || index > (int)widgets.count() ) { - index = (int)widgets.count(); - widgets.append( w ); - } - else - widgets.insert( index, w ); - if ( id == -1 ) - id = id2widget.count(); - id2widget.insert( id, w ); - widget2id.insert( w, id ); -} - -void TDEToolBar::showEvent( TQShowEvent *e ) -{ - TQToolBar::showEvent( e ); - rebuildLayout(); -} - -void TDEToolBar::setStretchableWidget( TQWidget *w ) -{ - TQToolBar::setStretchableWidget( w ); - stretchableWidget = w; -} - -TQSizePolicy TDEToolBar::sizePolicy() const -{ - if ( orientation() == Qt::Horizontal ) - return TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ); - else - return TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Expanding ); -} - -TQSize TDEToolBar::sizeHint() const -{ - TQSize minSize(0,0); - TDEToolBar *ncThis = const_cast(this); - - ncThis->polish(); - - int margin = static_cast(ncThis)->layout()->margin() + frameWidth(); - switch( barPos() ) - { - case TDEToolBar::Top: - case TDEToolBar::Bottom: - for ( TQWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() ) - { - TQSize sh = w->sizeHint(); - if ( w->sizePolicy().horData() == TQSizePolicy::Ignored ) - sh.setWidth( 1 ); - if ( w->sizePolicy().verData() == TQSizePolicy::Ignored ) - sh.setHeight( 1 ); - sh = sh.boundedTo( w->maximumSize() ) - .expandedTo( w->minimumSize() ).expandedTo( TQSize(1, 1) ); - - minSize = minSize.expandedTo(TQSize(0, sh.height())); - minSize += TQSize(sh.width()+1, 0); - if (tqt_dynamic_cast(w)) // w is a TQLineEdit ? - minSize += TQSize(2, 0); // A little bit extra spacing behind it. - } - - minSize += TQSize(TQApplication::style().pixelMetric( TQStyle::PM_DockWindowHandleExtent ), 0); - minSize += TQSize(margin*2, margin*2); - break; - - case TDEToolBar::Left: - case TDEToolBar::Right: - for ( TQWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() ) - { - TQSize sh = w->sizeHint(); - if ( w->sizePolicy().horData() == TQSizePolicy::Ignored ) - sh.setWidth( 1 ); - if ( w->sizePolicy().verData() == TQSizePolicy::Ignored ) - sh.setHeight( 1 ); - sh = sh.boundedTo( w->maximumSize() ) - .expandedTo( w->minimumSize() ).expandedTo( TQSize(1, 1) ); - - minSize = minSize.expandedTo(TQSize(sh.width(), 0)); - minSize += TQSize(0, sh.height()+1); - } - minSize += TQSize(0, TQApplication::style().pixelMetric( TQStyle::PM_DockWindowHandleExtent )); - minSize += TQSize(margin*2, margin*2); - break; - - default: - minSize = TQToolBar::sizeHint(); - break; - } - return minSize; -} - -TQSize TDEToolBar::minimumSize() const -{ - return minimumSizeHint(); -} - -TQSize TDEToolBar::minimumSizeHint() const -{ - return sizeHint(); -} - -bool TDEToolBar::highlight() const -{ - return d->m_highlight; -} - -void TDEToolBar::hide() -{ - TQToolBar::hide(); -} - -void TDEToolBar::show() -{ - TQToolBar::show(); -} - -void TDEToolBar::resizeEvent( TQResizeEvent *e ) -{ - bool b = isUpdatesEnabled(); - setUpdatesEnabled( false ); - TQToolBar::resizeEvent( e ); - if (b) - { - if (layoutTimer->isActive()) - { - // Wait with repainting till layout is complete. - d->repaintTimer.start( 100, true ); - } - else - { - // Repaint now - slotRepaint(); - } - } -// else { -// printf("[WARNING] In TDEToolBar::resizeEvent, but this code block should not be executing. Preventing toolbar lockup. [Code 0045]\n\r"); -// setUpdatesEnabled( true ); -// } -} - -void TDEToolBar::slotIconChanged(int group) -{ - if ((group != KIcon::Toolbar) && (group != KIcon::MainToolbar)) - return; - if ((group == KIcon::MainToolbar) != !::qstrcmp(name(), "mainToolBar")) - return; - - doModeChange(); - - if (isVisible()) - updateGeometry(); -} - -void TDEToolBar::slotReadConfig() -{ - //kdDebug(220) << name() << " slotReadConfig" << endl; - // Read appearance settings (hmm, we used to do both here, - // but a well behaved application will call applyMainWindowSettings - // anyway, right ?) - applyAppearanceSettings(TDEGlobal::config(), TQString::null ); -} - -void TDEToolBar::slotAppearanceChanged() -{ - // Read appearance settings from global file. - applyAppearanceSettings(TDEGlobal::config(), TQString::null, true /* lose local settings */ ); - - // And remember to save the new look later - TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); - if ( kmw ) - kmw->setSettingsDirty(); -} - -//static -bool TDEToolBar::highlightSetting() -{ - TQString grpToolbar(TQString::fromLatin1("Toolbar style")); - TDEConfigGroupSaver saver(TDEGlobal::config(), grpToolbar); - return TDEGlobal::config()->readBoolEntry(TQString::fromLatin1("Highlighting"),true); -} - -//static -bool TDEToolBar::transparentSetting() -{ - TQString grpToolbar(TQString::fromLatin1("Toolbar style")); - TDEConfigGroupSaver saver(TDEGlobal::config(), grpToolbar); - return TDEGlobal::config()->readBoolEntry(TQString::fromLatin1("TransparentMoving"),true); -} - -//static -TDEToolBar::IconText TDEToolBar::iconTextSetting() -{ - TQString grpToolbar(TQString::fromLatin1("Toolbar style")); - TDEConfigGroupSaver saver(TDEGlobal::config(), grpToolbar); - TQString icontext = TDEGlobal::config()->readEntry(TQString::fromLatin1("IconText"),TQString::fromLatin1("IconOnly")); - if ( icontext == "IconTextRight" ) - return IconTextRight; - else if ( icontext == "IconTextBottom" ) - return IconTextBottom; - else if ( icontext == "TextOnly" ) - return TextOnly; - else - return IconOnly; -} - -void TDEToolBar::applyAppearanceSettings(TDEConfig *config, const TQString &_configGroup, bool forceGlobal) -{ - TQString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup; - //kdDebug(220) << name() << " applyAppearanceSettings: configGroup=" << configGroup << " forceGlobal=" << forceGlobal << endl; - - // If we have application-specific settings in the XML file, - // and nothing in the application's config file, then - // we don't apply the global defaults, the XML ones are preferred - // (see applySettings for a full explanation) - // This is the reason for the xmlgui tests below. - bool xmlgui = d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty(); - - TDEConfig *gconfig = TDEGlobal::config(); - - static const TQString &attrIconText = TDEGlobal::staticQString("IconText"); - static const TQString &attrHighlight = TDEGlobal::staticQString("Highlighting"); - static const TQString &attrTrans = TDEGlobal::staticQString("TransparentMoving"); - static const TQString &attrIconSize = TDEGlobal::staticQString("IconSize"); - - // we actually do this in two steps. - // First, we read in the global styles [Toolbar style] (from the KControl module). - // Then, if the toolbar is NOT 'mainToolBar', we will also try to read in [barname Toolbar style] - bool highlight; - int transparent; - bool applyIconText = !xmlgui; // if xmlgui is used, global defaults won't apply - bool applyIconSize = !xmlgui; - - int iconSize = d->IconSizeDefault; - TQString iconText = d->IconTextDefault; - - // this is the first iteration - TQString grpToolbar(TQString::fromLatin1("Toolbar style")); - { // start block for TDEConfigGroupSaver - TDEConfigGroupSaver saver(gconfig, grpToolbar); - - // first, get the generic settings - highlight = gconfig->readBoolEntry(attrHighlight, true); - transparent = gconfig->readBoolEntry(attrTrans, true); - - // we read in the IconText property *only* if we intend on actually - // honoring it - if (d->m_honorStyle) - d->IconTextDefault = gconfig->readEntry(attrIconText, d->IconTextDefault); - else - d->IconTextDefault = "IconOnly"; - - // Use the default icon size for toolbar icons. - d->IconSizeDefault = gconfig->readNumEntry(attrIconSize, d->IconSizeDefault); - - iconSize = d->IconSizeDefault; - iconText = d->IconTextDefault; - - if ( !forceGlobal && config->hasGroup(configGroup) ) - { - config->setGroup(configGroup); - - // first, get the generic settings - highlight = config->readBoolEntry(attrHighlight, highlight); - transparent = config->readBoolEntry(attrTrans, transparent); - - // read in the IconText property - if ( config->hasKey( attrIconText ) ) { - iconText = config->readEntry(attrIconText); - applyIconText = true; - //kdDebug(220) << name() << " read icontext=" << d->IconTextDefault << ", that will be the default" << endl; - } - - // now get the size - if ( config->hasKey( attrIconSize ) ) { - iconSize = config->readNumEntry(attrIconSize); - applyIconSize = true; - } - } - - // revert back to the old group - } // end block for TDEConfigGroupSaver - - bool doUpdate = false; - - IconText icon_text; - if ( iconText == "IconTextRight" ) - icon_text = IconTextRight; - else if ( iconText == "IconTextBottom" ) - icon_text = IconTextBottom; - else if ( iconText == "TextOnly" ) - icon_text = TextOnly; - else - icon_text = IconOnly; - - // check if the icon/text has changed - if (icon_text != d->m_iconText && applyIconText) { - //kdDebug(220) << name() << " applyAppearanceSettings setIconText " << icon_text << endl; - setIconText(icon_text, false); - doUpdate = true; - } - - // ...and check if the icon size has changed - if (iconSize != d->m_iconSize && applyIconSize) { - setIconSize(iconSize, false); - doUpdate = true; - } - - TQMainWindow *mw = mainWindow(); - - // ...and if we should highlight - if ( highlight != d->m_highlight ) { - d->m_highlight = highlight; - doUpdate = true; - } - - // ...and if we should move transparently - if ( mw && transparent != (!mw->opaqueMoving()) ) { - mw->setOpaqueMoving( !transparent ); - } - - if (doUpdate) - doModeChange(); // tell buttons what happened - - if (isVisible ()) - updateGeometry(); -} - -void TDEToolBar::applySettings(TDEConfig *config, const TQString &_configGroup) -{ - return applySettings(config,_configGroup,false); -} - -void TDEToolBar::applySettings(TDEConfig *config, const TQString &_configGroup, bool force) -{ - //kdDebug(220) << name() << " applySettings group=" << _configGroup << endl; - - TQString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup; - - /* - Let's explain this a bit more in details. - The order in which we apply settings is : - Global config / user settings if no XMLGUI is used - Global config / App-XML attributes / user settings if XMLGUI is used - - So in the first case, we simply read everything from TDEConfig as below, - but in the second case we don't do anything here if there is no app-specific config, - and the XMLGUI-related code (loadState()) uses the static methods of this class - to get the global defaults. - - Global config doesn't include position (index, offset, newline and hidden/shown). - */ - - // First the appearance stuff - the one which has a global config - applyAppearanceSettings( config, configGroup ); - - // ...and now the position stuff - if ( config->hasGroup(configGroup) || force ) - { - TDEConfigGroupSaver cgs(config, configGroup); - - static const TQString &attrPosition = TDEGlobal::staticQString("Position"); - static const TQString &attrIndex = TDEGlobal::staticQString("Index"); - static const TQString &attrOffset = TDEGlobal::staticQString("Offset"); - static const TQString &attrNewLine = TDEGlobal::staticQString("NewLine"); - static const TQString &attrHidden = TDEGlobal::staticQString("Hidden"); - - TQString position = config->readEntry(attrPosition, d->PositionDefault); - int index = config->readNumEntry(attrIndex, -1); - int offset = config->readNumEntry(attrOffset, d->OffsetDefault); - bool newLine = config->readBoolEntry(attrNewLine, d->NewLineDefault); - bool hidden = config->readBoolEntry(attrHidden, d->HiddenDefault); - - Dock pos(DockTop); - if ( position == "Top" ) - pos = DockTop; - else if ( position == "Bottom" ) - pos = DockBottom; - else if ( position == "Left" ) - pos = DockLeft; - else if ( position == "Right" ) - pos = DockRight; - else if ( position == "Floating" ) - pos = DockTornOff; - else if ( position == "Flat" ) - pos = DockMinimized; - - //kdDebug(220) << name() << " applySettings hidden=" << hidden << endl; - if (hidden) - hide(); - else - show(); - - if ( mainWindow() ) - { - //kdDebug(220) << name() << " applySettings updating ToolbarInfo" << endl; - d->toolBarInfo = TDEToolBarPrivate::ToolBarInfo( pos, index, newLine, offset ); - positionYourself( true ); - } - if (isVisible ()) - updateGeometry(); - } -} - -bool TDEToolBar::event( TQEvent *e ) -{ - if ( (e->type() == TQEvent::LayoutHint) && isUpdatesEnabled() ) - d->repaintTimer.start( 100, true ); - - if (e->type() == TQEvent::ChildInserted ) - { - // Bypass TQToolBar::event, - // it will show() the inserted child and we don't want to - // do that until we have rebuilt the layout. - childEvent((TQChildEvent *)e); - return true; - } - - return TQToolBar::event( e ); -} - -void TDEToolBar::slotRepaint() -{ - setUpdatesEnabled( false ); - // Send a resizeEvent to update the "toolbar extension arrow" - // (The button you get when your toolbar-items don't fit in - // the available space) - TQResizeEvent ev(size(), size()); - resizeEvent(&ev); - TQApplication::sendPostedEvents( this, TQEvent::LayoutHint ); - setUpdatesEnabled( true ); - repaint( true ); -} - -void TDEToolBar::toolBarPosChanged( TQToolBar *tb ) -{ - if ( tb != this ) - return; - if ( d->oldPos == DockMinimized ) - rebuildLayout(); - d->oldPos = (TQMainWindow::ToolBarDock)barPos(); - TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); - if ( kmw ) - kmw->setSettingsDirty(); -} - -static TDEToolBar::Dock stringToDock( const TQString& attrPosition ) -{ - TDEToolBar::Dock dock = TDEToolBar::DockTop; - if ( !attrPosition.isEmpty() ) { - if ( attrPosition == "top" ) - dock = TDEToolBar::DockTop; - else if ( attrPosition == "left" ) - dock = TDEToolBar::DockLeft; - else if ( attrPosition == "right" ) - dock = TDEToolBar::DockRight; - else if ( attrPosition == "bottom" ) - dock = TDEToolBar::DockBottom; - else if ( attrPosition == "floating" ) - dock = TDEToolBar::DockTornOff; - else if ( attrPosition == "flat" ) - dock = TDEToolBar::DockMinimized; - } - return dock; -} - - -void TDEToolBar::loadState( const TQDomElement &element ) -{ - TQMainWindow *mw = mainWindow(); - - if ( !mw ) - return; - - { - TQCString text = element.namedItem( "text" ).toElement().text().utf8(); - if ( text.isEmpty() ) - text = element.namedItem( "Text" ).toElement().text().utf8(); - if ( !text.isEmpty() ) - setText( i18n( text ) ); - } - - { - TQCString attrFullWidth = element.attribute( "fullWidth" ).lower().latin1(); - if ( !attrFullWidth.isEmpty() ) - setFullSize( attrFullWidth == "true" ); - } - - /* - This method is called in order to load toolbar settings from XML. - However this can be used in two rather different cases: - - for the initial loading of the app's XML. In that case the settings - are only the defaults, the user's TDEConfig settings will override them - (KDE4 TODO: how about saving those user settings into the local XML file instead? - Then this whole thing would be simpler, no TDEConfig settings to apply afterwards. - OTOH we'd have to migrate those settings when the .rc version increases, - like we do for shortcuts) - - - for later re-loading when switching between parts in KXMLGUIFactory. - In that case the XML contains the final settings, not the defaults. - We do need the defaults, and the toolbar might have been completely - deleted and recreated meanwhile. So we store the app-default settings - into the XML. - */ - bool loadingAppDefaults = true; - if ( element.hasAttribute( "offsetDefault" ) ) - { - // this isn't the first time, so the defaults have been saved into the (in-memory) XML - loadingAppDefaults = false; - d->OffsetDefault = element.attribute( "offsetDefault" ).toInt(); - d->NewLineDefault = element.attribute( "newlineDefault" ) == "true"; - d->HiddenDefault = element.attribute( "hiddenDefault" ) == "true"; - d->IconSizeDefault = element.attribute( "iconSizeDefault" ).toInt(); - d->PositionDefault = element.attribute( "positionDefault" ); - d->IconTextDefault = element.attribute( "iconTextDefault" ); - } - //kdDebug(220) << name() << " loadState loadingAppDefaults=" << loadingAppDefaults << endl; - - Dock dock = stringToDock( element.attribute( "position" ).lower() ); - - { - TQCString attrIconText = element.attribute( "iconText" ).lower().latin1(); - if ( !attrIconText.isEmpty() ) { - //kdDebug(220) << name() << " loadState attrIconText=" << attrIconText << endl; - if ( attrIconText == "icontextright" ) - setIconText( TDEToolBar::IconTextRight ); - else if ( attrIconText == "textonly" ) - setIconText( TDEToolBar::TextOnly ); - else if ( attrIconText == "icontextbottom" ) - setIconText( TDEToolBar::IconTextBottom ); - else if ( attrIconText == "icononly" ) - setIconText( TDEToolBar::IconOnly ); - } else - { - //kdDebug(220) << name() << " loadState no iconText attribute in XML, using iconTextSetting=" << iconTextSetting() << endl; - // Use global setting - if (d->m_honorStyle) - setIconText( iconTextSetting() ); - else - setIconText( d->IconTextDefault ); - } - } - - TQString attrIconSize = element.attribute( "iconSize" ).lower(); - int iconSize = d->IconSizeDefault; - if ( !attrIconSize.isEmpty() ) - iconSize = attrIconSize.toInt(); - setIconSize( iconSize ); - - int index = -1; // append by default. This is very important, otherwise - // with all 0 indexes, we keep reversing the toolbars. - { - TQString attrIndex = element.attribute( "index" ).lower(); - if ( !attrIndex.isEmpty() ) - index = attrIndex.toInt(); - } - - int offset = d->OffsetDefault; - bool newLine = d->NewLineDefault; - bool hidden = d->HiddenDefault; - - { - TQString attrOffset = element.attribute( "offset" ); - if ( !attrOffset.isEmpty() ) - offset = attrOffset.toInt(); - } - - { - TQString attrNewLine = element.attribute( "newline" ).lower(); - if ( !attrNewLine.isEmpty() ) - newLine = attrNewLine == "true"; - } - - { - TQString attrHidden = element.attribute( "hidden" ).lower(); - if ( !attrHidden.isEmpty() ) { - hidden = attrHidden == "true"; - } - } - - d->toolBarInfo = TDEToolBarPrivate::ToolBarInfo( dock, index, newLine, offset ); - mw->addDockWindow( this, dock, newLine ); - mw->moveDockWindow( this, dock, newLine, index, offset ); - - // Apply the highlight button setting - d->m_highlight = highlightSetting(); - - if ( hidden ) - hide(); - else - show(); - - if ( loadingAppDefaults ) - { - getAttributes( d->PositionDefault, d->IconTextDefault, index ); - //kdDebug(220) << name() << " loadState IconTextDefault=" << d->IconTextDefault << endl; - d->OffsetDefault = offset; - d->NewLineDefault = newLine; - d->HiddenDefault = hidden; - d->IconSizeDefault = iconSize; - } - //kdDebug(220) << name() << " loadState hidden=" << hidden << endl; - - // Apply transparent-toolbar-moving setting (ok, this is global to the mainwindow, - // but we do it only if there are toolbars...) - // KDE4: move to TDEMainWindow - if ( transparentSetting() != !mw->opaqueMoving() ) - mw->setOpaqueMoving( !transparentSetting() ); -} - -int TDEToolBar::dockWindowIndex() -{ - int index = 0; - Q_ASSERT( mainWindow() ); - if ( mainWindow() ) { - TQMainWindow::ToolBarDock dock; - bool newLine; - int offset; - mainWindow()->getLocation( this, dock, index, newLine, offset ); - } - return index; -} - -void TDEToolBar::getAttributes( TQString &position, TQString &icontext, int &index ) -{ - // get all of the stuff to save - switch ( barPos() ) { - case TDEToolBar::Flat: - position = "Flat"; - break; - case TDEToolBar::Bottom: - position = "Bottom"; - break; - case TDEToolBar::Left: - position = "Left"; - break; - case TDEToolBar::Right: - position = "Right"; - break; - case TDEToolBar::Floating: - position = "Floating"; - break; - case TDEToolBar::Top: - default: - position = "Top"; - break; - } - - index = dockWindowIndex(); - - switch (d->m_iconText) { - case TDEToolBar::IconTextRight: - icontext = "IconTextRight"; - break; - case TDEToolBar::IconTextBottom: - icontext = "IconTextBottom"; - break; - case TDEToolBar::TextOnly: - icontext = "TextOnly"; - break; - case TDEToolBar::IconOnly: - default: - icontext = "IconOnly"; - break; - } - //kdDebug(220) << name() << " getAttributes: icontext=" << icontext << endl; -} - -void TDEToolBar::saveState( TQDomElement ¤t ) -{ - Q_ASSERT( !current.isNull() ); - TQString position, icontext; - int index = -1; - getAttributes( position, icontext, index ); - - current.setAttribute( "noMerge", "1" ); - current.setAttribute( "position", position ); - current.setAttribute( "iconText", icontext ); - current.setAttribute( "index", index ); - current.setAttribute( "offset", offset() ); - current.setAttribute( "newline", newLine() ); - if ( isHidden() ) - current.setAttribute( "hidden", "true" ); - d->modified = true; - - // TODO if this method is used by more than KXMLGUIBuilder, e.g. to save XML settings to *disk*, - // then the stuff below shouldn't always be done. - current.setAttribute( "offsetDefault", d->OffsetDefault ); - current.setAttribute( "newlineDefault", d->NewLineDefault ); - current.setAttribute( "hiddenDefault", d->HiddenDefault ? "true" : "false" ); - current.setAttribute( "iconSizeDefault", d->IconSizeDefault ); - current.setAttribute( "positionDefault", d->PositionDefault ); - current.setAttribute( "iconTextDefault", d->IconTextDefault ); - - //kdDebug(220) << name() << " saveState: saving index=" << index << " iconText=" << icontext << " hidden=" << isHidden() << endl; -} - -// Called by TDEMainWindow::finalizeGUI -void TDEToolBar::positionYourself( bool force ) -{ - if (force) - d->positioned = false; - - if ( d->positioned || !mainWindow() ) - { - //kdDebug(220) << name() << " positionYourself d->positioned=true ALREADY DONE" << endl; - return; - } - // we can't test for ForceHide after moveDockWindow because QDockArea - // does a reparent() with showIt == true - bool hidden = isHidden(); - //kdDebug(220) << name() << " positionYourself dock=" << d->toolBarInfo.dock << " newLine=" << d->toolBarInfo.newline << " index=" << d->toolBarInfo.index << " offset=" << d->toolBarInfo.offset << endl; - mainWindow()->moveDockWindow( this, d->toolBarInfo.dock, - d->toolBarInfo.newline, - d->toolBarInfo.index, - d->toolBarInfo.offset ); - - //kdDebug(220) << name() << " positionYourself dockWindowIndex=" << dockWindowIndex() << endl; - if ( hidden ) - hide(); - else - show(); - // This method can only have an effect once - unless force is set - d->positioned = true; -} - -TDEPopupMenu *TDEToolBar::contextMenu() -{ - if ( context ) - return context; - // Construct our context popup menu. Name it qt_dockwidget_internal so it - // won't be deleted by TQToolBar::clear(). - context = new TDEPopupMenu( this, "qt_dockwidget_internal" ); - context->insertTitle(i18n("Toolbar Menu")); - - TDEPopupMenu *orient = new TDEPopupMenu( context, "orient" ); - orient->insertItem( i18n("toolbar position string","Top"), CONTEXT_TOP ); - orient->insertItem( i18n("toolbar position string","Left"), CONTEXT_LEFT ); - orient->insertItem( i18n("toolbar position string","Right"), CONTEXT_RIGHT ); - orient->insertItem( i18n("toolbar position string","Bottom"), CONTEXT_BOTTOM ); - orient->insertSeparator(-1); - orient->insertItem( i18n("toolbar position string","Floating"), CONTEXT_FLOAT ); - orient->insertItem( i18n("min toolbar", "Flat"), CONTEXT_FLAT ); - - TDEPopupMenu *mode = new TDEPopupMenu( context, "mode" ); - mode->insertItem( i18n("Icons Only"), CONTEXT_ICONS ); - mode->insertItem( i18n("Text Only"), CONTEXT_TEXT ); - mode->insertItem( i18n("Text Alongside Icons"), CONTEXT_TEXTRIGHT ); - mode->insertItem( i18n("Text Under Icons"), CONTEXT_TEXTUNDER ); - - TDEPopupMenu *size = new TDEPopupMenu( context, "size" ); - size->insertItem( i18n("Default"), CONTEXT_ICONSIZES ); - // Query the current theme for available sizes - KIconTheme *theme = TDEGlobal::instance()->iconLoader()->theme(); - TQValueList avSizes; - if (theme) - { - if (!::qstrcmp(name(), "mainToolBar")) - avSizes = theme->querySizes( KIcon::MainToolbar); - else - avSizes = theme->querySizes( KIcon::Toolbar); - } - - d->iconSizes = avSizes; - qHeapSort(avSizes); - - TQValueList::Iterator it; - if (avSizes.count() < 10) { - // Fixed or threshold type icons - TQValueList::Iterator end(avSizes.end()); - for (it=avSizes.begin(); it!=end; ++it) { - TQString text; - if ( *it < 19 ) - text = i18n("Small (%1x%2)").arg(*it).arg(*it); - else if (*it < 25) - text = i18n("Medium (%1x%2)").arg(*it).arg(*it); - else if (*it < 35) - text = i18n("Large (%1x%2)").arg(*it).arg(*it); - else - text = i18n("Huge (%1x%2)").arg(*it).arg(*it); - //we use the size as an id, with an offset - size->insertItem( text, CONTEXT_ICONSIZES + *it ); - } - } - else { - // Scalable icons. - const int progression[] = {16, 22, 32, 48, 64, 96, 128, 192, 256}; - - it = avSizes.begin(); - for (uint i = 0; i < 9; i++) { - while (it++ != avSizes.end()) { - if (*it >= progression[i]) { - TQString text; - if ( *it < 19 ) - text = i18n("Small (%1x%2)").arg(*it).arg(*it); - else if (*it < 25) - text = i18n("Medium (%1x%2)").arg(*it).arg(*it); - else if (*it < 35) - text = i18n("Large (%1x%2)").arg(*it).arg(*it); - else - text = i18n("Huge (%1x%2)").arg(*it).arg(*it); - //we use the size as an id, with an offset - size->insertItem( text, CONTEXT_ICONSIZES + *it ); - break; - } - } - } - } - - context->insertItem( i18n("Orientation"), orient ); - orient->setItemChecked(CONTEXT_TOP, true); - context->insertItem( i18n("Text Position"), mode ); - context->setItemChecked(CONTEXT_ICONS, true); - context->insertItem( i18n("Icon Size"), size ); - - connect( context, TQT_SIGNAL( aboutToShow() ), this, TQT_SLOT( slotContextAboutToShow() ) ); - // Unplugging a submenu from abouttohide leads to the popupmenu floating around - // So better simply call that code from after exec() returns (DF) - //connect( context, TQT_SIGNAL( aboutToHide() ), this, TQT_SLOT( slotContextAboutToHide() ) ); - return context; -} - -void TDEToolBar::slotContextAboutToShow() -{ - // The idea here is to reuse the "static" part of the menu to save time. - // But the "Toolbars" action is dynamic (can be a single action or a submenu) - // and ToolBarHandler::setupActions() deletes it, so better not keep it around. - // So we currently plug/unplug the last two actions of the menu. - // Another way would be to keep around the actions and plug them all into a (new each time) popupmenu. - TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); - if ( kmw ) { - kmw->setupToolbarMenuActions(); - // Only allow hiding a toolbar if the action is also plugged somewhere else (e.g. menubar) - TDEAction *tbAction = kmw->toolBarMenuAction(); - if ( tbAction && tbAction->containerCount() > 0 ) - tbAction->plug(context); - } - - // try to find "configure toolbars" action - TDEAction *configureAction = 0; - const char* actionName = KStdAction::name(KStdAction::ConfigureToolbars); - if ( d->m_xmlguiClient ) - configureAction = d->m_xmlguiClient->actionCollection()->action(actionName); - if ( !configureAction && kmw ) - configureAction = kmw->actionCollection()->action(actionName); - if ( configureAction ) - configureAction->plug(context); - KEditToolbar::setDefaultToolbar(name()); - - for(int i = CONTEXT_ICONS; i <= CONTEXT_TEXTUNDER; ++i) - context->setItemChecked(i, false); - - switch( d->m_iconText ) - { - case IconOnly: - default: - context->setItemChecked(CONTEXT_ICONS, true); - break; - case IconTextRight: - context->setItemChecked(CONTEXT_TEXTRIGHT, true); - break; - case TextOnly: - context->setItemChecked(CONTEXT_TEXT, true); - break; - case IconTextBottom: - context->setItemChecked(CONTEXT_TEXTUNDER, true); - break; - } - - TQValueList::ConstIterator iIt = d->iconSizes.begin(); - TQValueList::ConstIterator iEnd = d->iconSizes.end(); - for (; iIt != iEnd; ++iIt ) - context->setItemChecked( CONTEXT_ICONSIZES + *iIt, false ); - - context->setItemChecked( CONTEXT_ICONSIZES, false ); - - context->setItemChecked( CONTEXT_ICONSIZES + d->m_iconSize, true ); - - for ( int i = CONTEXT_TOP; i <= CONTEXT_FLAT; ++i ) - context->setItemChecked( i, false ); - - switch ( barPos() ) - { - case TDEToolBar::Flat: - context->setItemChecked( CONTEXT_FLAT, true ); - break; - case TDEToolBar::Bottom: - context->setItemChecked( CONTEXT_BOTTOM, true ); - break; - case TDEToolBar::Left: - context->setItemChecked( CONTEXT_LEFT, true ); - break; - case TDEToolBar::Right: - context->setItemChecked( CONTEXT_RIGHT, true ); - break; - case TDEToolBar::Floating: - context->setItemChecked( CONTEXT_FLOAT, true ); - break; - case TDEToolBar::Top: - context->setItemChecked( CONTEXT_TOP, true ); - break; - default: break; - } -} - -void TDEToolBar::slotContextAboutToHide() -{ - // We have to unplug whatever slotContextAboutToShow plugged into the menu. - // Unplug the toolbar menu action - TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); - if ( kmw && kmw->toolBarMenuAction() ) - if ( kmw->toolBarMenuAction()->containerCount() > 1 ) - kmw->toolBarMenuAction()->unplug(context); - - // Unplug the configure toolbars action too, since it's afterwards anyway - TDEAction *configureAction = 0; - const char* actionName = KStdAction::name(KStdAction::ConfigureToolbars); - if ( d->m_xmlguiClient ) - configureAction = d->m_xmlguiClient->actionCollection()->action(actionName); - if ( !configureAction && kmw ) - configureAction = kmw->actionCollection()->action(actionName); - if ( configureAction ) - configureAction->unplug(context); - - TQPtrListIterator it( widgets ); - TQWidget *wdg; - while ( ( wdg = it.current() ) != 0 ) { - if ( wdg->inherits( TQTOOLBUTTON_OBJECT_NAME_STRING ) ) - static_cast( wdg )->setDown( false ); - ++it; - } -} - -void TDEToolBar::widgetDestroyed() -{ - removeWidgetInternal( (TQWidget*)sender() ); -} - -void TDEToolBar::removeWidgetInternal( TQWidget * w ) -{ - widgets.removeRef( w ); - TQMap< TQWidget*, int >::Iterator it = widget2id.find( w ); - if ( it == widget2id.end() ) - return; - id2widget.remove( *it ); - widget2id.remove( it ); -} - -void TDEToolBar::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -#include "ktoolbar.moc" - diff --git a/tdeui/ktoolbar.h b/tdeui/ktoolbar.h deleted file mode 100644 index 43362f512..000000000 --- a/tdeui/ktoolbar.h +++ /dev/null @@ -1,1130 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2000 Reginald Stadlbauer (reggie@kde.org) - (C) 1997, 1998 Stephan Kulow (coolo@kde.org) - (C) 1997, 1998 Sven Radej (radej@kde.org) - (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) - (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) - (C) 1999, 2000 Kurt Granroth (granroth@kde.org) - - 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 KTOOLBAR_H -#define KTOOLBAR_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -class TQDomElement; -class TQSize; -class TQPixmap; -class TQPopupMenu; -class TQStringList; -class TQDomDocument; -class TQTimer; - -class KLineEdit; -class TDEToolBar; -class TDEToolBarButton; -class TDEToolBoxManager; -class KAnimWidget; -class TDEPopupMenu; -class TDEInstance; -class KComboBox; -class KXMLGUIClient; - -class TDEToolBarPrivate; - -class TDEUI_EXPORT TDEToolBarSeparator : public TQFrame -{ - Q_OBJECT - -public: - TDEToolBarSeparator( Orientation, bool l, TQToolBar *parent, const char* name=0 ); - - TQSize sizeHint() const; - Orientation orientation() const { return orient; } - TQSizePolicy sizePolicy() const; - bool showLine() const { return line; } -public slots: - void setOrientation( Orientation ); -protected: - void styleChange( TQStyle& ); - void drawContents( TQPainter* ); -private: - Orientation orient; - bool line; -}; - - - /** - * @short Floatable toolbar with auto resize. - * - * A KDE-style toolbar. - * - * TDEToolBar can be dragged around in and between different docks. - * - * A TDEToolBar can contain all sorts of widgets. - * - * TDEToolBar can be used as a standalone widget, but TDEMainWindow - * provides easy factories and management of one or more toolbars. - * Once you have a TDEToolBar object, you can insert items into it with the - * insert... methods, or remove them with the removeItem() method. This - * can be done at any time; the toolbar will be automatically updated. - * There are also many methods to set per-child properties like alignment - * and toggle behavior. - * - * TDEToolBar uses a global config group to load toolbar settings on - * construction. It will reread this config group on a - * TDEApplication::appearanceChanged() signal. - * - * @author Reginald Stadlbauer , Stephan Kulow , Sven Radej . - */ - -class TDEUI_EXPORT TDEToolBar : public TQToolBar -{ - Q_OBJECT - - TQ_ENUMS( IconText BarPosition ) - TQ_PROPERTY( IconText iconText READ iconText WRITE setIconText ) - TQ_PROPERTY( BarPosition barPos READ barPos WRITE setBarPos ) - TQ_PROPERTY( bool fullSize READ fullSize WRITE setFullSize ) - TQ_PROPERTY( int iconSize READ iconSize WRITE setIconSize ) - TQ_PROPERTY( TQString text READ text WRITE setText ) - -public: - enum IconText{IconOnly = 0, IconTextRight, TextOnly, IconTextBottom}; - /** - * The state of the status bar. - * @deprecated - */ - enum BarStatus{Toggle, Show, Hide}; - /** - * Possible bar positions. - */ - enum BarPosition{ Unmanaged, Floating, Top, Bottom, Right, Left, Flat}; - - /** - * Normal constructor. - * This constructor is used by the XML-GUI. If you use it, you need - * to call TQMainWindow::addToolBar to specify the position of the toolbar. - * So it's simpler to use the other constructor. - * - * The toolbar will read in various global config settings for - * things like icon size and text position, etc. However, some of - * the settings will be honored only if @p honorStyle is set to - * true. All other toolbars will be IconOnly and use Medium icons. - * - * @param parent The standard toolbar parent (usually a - * TDEMainWindow) - * @param name The standard internal name - * @param honorStyle If true, then global settings for IconSize and IconText will be honored - * @param readConfig whether to apply the configuration (global and application-specific) - */ - TDEToolBar( TQWidget *parent, const char *name = 0, bool honorStyle = false, bool readConfig = true ); - - /** - * Constructor for non-XML-GUI applications. - * - * The toolbar will read in various global config settings for - * things like icon size and text position, etc. However, some of - * the settings will be honored only if @p honorStyle is set to - * true. All other toolbars will be IconOnly and use Medium icons. - * - * @param parentWindow The window that should be the parent of this toolbar - * @param dock The position of the toolbar. Usually TQMainWindow::Top. - * @param newLine If true, start a new line in the dock for this toolbar. - * @param name The standard internal name - * @param honorStyle If true, then global settings for IconSize and IconText will be honored - * @param readConfig whether to apply the configuration (global and application-specific) - */ - TDEToolBar( TQMainWindow *parentWindow, TQMainWindow::ToolBarDock dock /*= TQMainWindow::Top*/, bool newLine = false, - const char *name = 0, bool honorStyle = false, bool readConfig = true ); - - /** - * Constructor for non-XML-GUI applications. - * - * The toolbar will read in various global config settings for - * things like icon size and text position, etc. However, some of - * the settings will be honored only if @p honorStyle is set to - * true. All other toolbars will be IconOnly and use Medium icons. - * - * @param parentWindow The window that should be the parent of this toolbar - * @param dock Another widget than the mainwindow to dock toolbar to. - * @param newLine If true, start a new line in the dock for this toolbar. - * @param name The standard internal name - * @param honorStyle If true, then global settings for IconSize and IconText will be honored - * @param readConfig whether to apply the configuration (global and application-specific) - */ - TDEToolBar( TQMainWindow *parentWindow, TQWidget *dock, bool newLine = false, - const char *name = 0, bool honorStyle = false, bool readConfig = true ); - - /** - * Destructor - */ - virtual ~TDEToolBar(); - - /** - * Insert a button (a TDEToolBarButton) with a pixmap. The - * pixmap is loaded by the button itself based on the global icon - * settings. - * - * You should connect to one or more signals in TDEToolBar: - * clicked() , pressed() , released() , or - * highlighted() and if the button is a toggle button - * ( setToggle() ) toggled() . Those signals have @p id - * of a button that caused the signal. If you want to bind a popup - * to button, see setButton(). - * - * @param icon The name of the icon to use as the active pixmap - * @param id The id of this button - * @param enabled Enable or disable the button at startup - * @param text The tooltip or toolbar text (depending on state) - * @param index The position of the button. (-1 = at end). - * @param _instance instance this button will belong to - * - * @return The item index. - */ - int insertButton(const TQString& icon, int id, bool enabled = true, - const TQString& text = TQString::null, int index=-1, - TDEInstance *_instance = TDEGlobal::instance()); - - /** - * This is the same as above, but with specified signals and - * slots to which this button will be connected. - * - * You can add more signals with addConnection(). - * - * @param icon The name of the icon to use as the active pixmap - * @param id The id of this button - * @param signal The signal to connect to - * @param receiver The slot's parent - * @param slot The slot to receive the signal specified in that argument. - * @param enabled Enable or disable the button at startup - * @param text The tooltip or toolbar text (depending on state) - * @param index The position of the button. (-1 = at end). - * @param _instance instance this button will belong to - * - * @return The item index. - */ - int insertButton(const TQString& icon, int id, const char *signal, - const TQObject *receiver, const char *slot, - bool enabled = true, const TQString& text = TQString::null, - int index=-1, TDEInstance *_instance = TDEGlobal::instance() ); - - /** - * Inserts a button (a TDEToolBarButton) with the specified - * pixmap. This pixmap will be used as the "active" one and the - * disabled and default ones will be autogenerated. - * - * It is recommended that you use the insertButton function that - * allows you to specify the icon name rather then the pixmap - * itself. Specifying the icon name is much more flexible. - * - * You should connect to one or more signals in TDEToolBar: - * clicked() , pressed() , released() , or - * highlighted() and if the button is a toggle button - * ( setToggle() ) toggled() . Those signals have @p id - * of a button that caused the signal. If you want to bind a popup - * to button, see setButton(). - * - * @param pixmap The active pixmap - * @param id The id of this button - * @param enabled Enable or disable the button at startup - * @param text The tooltip or toolbar text (depending on state) - * @param index The position of the button. (-1 = at end). - * - * @return The item index. - */ - int insertButton(const TQPixmap& pixmap, int id, bool enabled = true, - const TQString& text = TQString::null, int index=-1 ); - - /** - * This is the same as above, but with specified signals and - * slots to which this button will be connected. - * - * You can add more signals with addConnection(). - * - * @param pixmap The name of the icon to use as the active pixmap - * @param id The id of this button - * @param signal The signal to connect to - * @param receiver The slot's parent - * @param slot The slot to receive the signal specified in that argument. - * @param enabled Enable or disable the button at startup - * @param text The tooltip or toolbar text (depending on state) - * @param index The position of the button. (-1 = at end). - * - * @return The item index. - */ - int insertButton(const TQPixmap& pixmap, int id, const char *signal, - const TQObject *receiver, const char *slot, - bool enabled = true, const TQString& text = TQString::null, - int index=-1 ); - - /** - * Inserts a button with popupmenu. - * - * Button will have small - * triangle. You have to connect to popup's signals. The - * signals KButton::pressed(), KButton::released(), - * KButton::clicked() or KButton::doubleClicked() are @p not - * emmited by - * this button (see setDelayedPopup() for that). - * You can add custom popups which inherit TQPopupMenu to get popups - * with tables, drawings etc. Just don't fiddle with events there. - */ - int insertButton(const TQString& icon, int id, TQPopupMenu *popup, - bool enabled, const TQString&_text, int index=-1); - - /** - * Inserts a button with popupmenu. - * - * Button will have small - * triangle. You have to connect to popup's signals. The - * signals KButton::pressed(), KButton::released(), - * KButton::clicked() or KButton::doubleClicked() are @p not - * emmited by - * this button (see setDelayedPopup() for that). - * You can add custom popups which inherit TQPopupMenu to get popups - * with tables, drawings etc. Just don't fiddle with events there. - */ - int insertButton(const TQPixmap& pixmap, int id, TQPopupMenu *popup, - bool enabled, const TQString&_text, int index=-1); - - /** - * Inserts a KLineEdit. You have to specify signals and slots to - * which KLineEdit will be connected. KLineEdit has all slots QLineEdit - * has, plus signals KLineEdit::completion and KLineEdit::textRotation - * KLineEdit can be set to autoresize itself to full free width - * in toolbar, that is to last right aligned item. For that, - * toolbar must be set to full width (which it is by default). - * @see setFullWidth() - * @see setItemAutoSized() - * @see KLineEdit - * @return Item index. - */ - int insertLined (const TQString& text, int id, - const char *signal, - const TQObject *receiver, const char *slot, - bool enabled = true, - const TQString& toolTipText = TQString::null, - int size = 70, int index =-1); - - /** - * Inserts a KComboBox with list. - * - * Can be writable, but cannot contain - * pixmaps. By default inserting policy is AtBottom, i.e. typed items - * are placed at the bottom of the list. Can be autosized. If the size - * argument is specified as -1, the width of the combobox is automatically - * computed. - * - * @see setFullWidth() - * @see setItemAutoSized() - * @see KComboBox - * @return Item index. - */ - int insertCombo (const TQStringList &list, int id, bool writable, - const char *signal, const TQObject *receiver, - const char *slot, bool enabled=true, - const TQString& tooltiptext=TQString::null, - int size=70, int index=-1, - TQComboBox::Policy policy = TQComboBox::AtBottom); - - /** - * Insert a KComboBox with text. - * - * The rest is the same as above. - * @see setItemAutoSized() - * - * @see KComboBox - * @return Item index. - */ - int insertCombo (const TQString& text, int id, bool writable, - const char *signal, TQObject *receiver, - const char *slot, bool enabled=true, - const TQString& tooltiptext=TQString::null, - int size=70, int index=-1, - TQComboBox::Policy policy = TQComboBox::AtBottom); - - /** - * Inserts a separator into the toolbar with the given @p id. - * @return the separator's index - */ - int insertSeparator( int index = -1, int id = -1 ); - - /** - * Inserts a line separator into the toolbar with the given @p id. - * @return the separator's index - */ - int insertLineSeparator( int index = -1, int id = -1 ); - - /** - * Inserts a user-defined widget. The widget @p must have this - * toolbar as its parent. - * - * Widget must have a TQWidget for base class. Widget can be - * autosized to full width. If you forget about it, you can get a - * pointer to this widget with getWidget(). - * @see setItemAutoSized() - * @return Item index. - */ - int insertWidget(int id, int width, TQWidget *_widget, int index=-1); - - /** - * Inserts an animated widget. A KAnimWidget will be created - * internally using the icon name you provide. - * This will emit a signal (clicked()) whenever the - * animation widget is clicked. - * - * @see animatedWidget() - * - * @param id The id for this toolbar item - * @param receiver The parent of your slot - * @param slot The slot to receive the clicked() signal - * @param icons The name of the animation icon group to use - * @param index The item index - * - * @return The item index - */ - int insertAnimatedWidget(int id, TQObject *receiver, const char *slot, - const TQString& icons, int index = -1); - - /** - * This will return a pointer to the animated widget with the - * given @p id, if it exists. - * - * @see insertAnimatedWidget - * @param id The id for the widget you want to get a pointer to - * @return A pointer to the current animated widget or 0L - */ - KAnimWidget *animatedWidget( int id ); - - /** - * Adds connections to items. - * - * It is important that you - * know the @p id of particular item. Nothing happens if you forget @p id. - */ - void addConnection (int id, const char *signal, - const TQObject *receiver, const char *slot); - /** - * Enables/disables item. - */ - void setItemEnabled( int id, bool enabled ); - - /** - * Sets the icon for a button. - * - * Can be used while button is visible. - */ - void setButtonIcon( int id, const TQString& _icon ); - - /** - * Sets button pixmap. - * - * Can be used while button is visible. - */ - void setButtonPixmap( int id, const TQPixmap& _pixmap ); - - /** - * Sets a button icon from a TQIconSet. - * - * Can be used while button is visible. - */ - void setButtonIconSet( int id, const TQIconSet& iconset ); - - /** - * Sets a delayed popup for a button. - * - * Delayed popup is what you see in - * Netscape Navigator's Previous and Next buttons: If you click them you - * go back - * or forth. If you press them long enough, you get a history-menu. - * This is exactly what we do here. - * - * You will insert a normal button with connection (or use signals from - * toolbar): - * \code - * bar->insertButton(icon, id, TQT_SIGNAL(clicked ()), this, - * TQT_SLOT (slotClick()), true, "click or wait for popup"); - * \endcode - * And then add a delayed popup: - * \code - * bar->setDelayedPopup (id, historyPopup); - * \endcode - * - * Don't add delayed popups to buttons which have normal popups. - * - * You may add popups which are derived from TQPopupMenu. You may - * add popups that are already in the menu bar or are submenus of - * other popups. - */ - void setDelayedPopup (int id , TQPopupMenu *_popup, bool toggle = false); - - /** - * Turns a button into an autorepeat button. - * - * Toggle buttons, buttons with menus, or - * buttons with delayed menus cannot be made into autorepeat buttons. - * Moreover, you can and will receive - * only the signal clicked(), but not pressed() or released(). - * When the user presses this button, you will receive the signal clicked(), - * and if the button is still pressed after some time, - * you will receive more clicked() signals separated by regular - * intervals. Since this uses TQButton::setAutoRepeat() , - * I can't quantify 'some'. - */ - void setAutoRepeat (int id, bool flag=true); - - - /** - * Turns button into a toggle button if @p flag is true. - */ - void setToggle (int id, bool flag = true); - - /** - * Toggles a togglebutton. - * - * If the button is a toggle button (see setToggle()) - * the button state will be toggled. This will also cause the toolbar to - * emit the signal KButton::toggled() with parameter @p id. You must connect to - * this signal, or use addConnection() to connect directly to the - * button signal KButton::toggled(). - */ - void toggleButton (int id); - - /** - * Sets a toggle button state. - * - * If the button is a toggle button (see setToggle()) - * this will set its state flag. This will also emit the signal - * KButton::toggled(). - * - * @see setToggle() - */ - void setButton (int id, bool flag); - - /** - * Returns @p true if button is on and is a toggle button - * @return @p true if button is on and is a toggle button - * @see setToggle() - */ - bool isButtonOn (int id) const; - - /** - * Sets the text of a line editor. - * - * Cursor is set at end of text. - */ - void setLinedText (int id, const TQString& text); - - /** - * Returns the line editor text. - * @return the line editor text. - */ - TQString getLinedText (int id) const; - - /** - * Inserts @p text in combobox @p id at position @p index. - */ - void insertComboItem (int id, const TQString& text, int index); - - /** - * Inserts @p list in combobox @p id at position @p index. - */ - void insertComboList (int id, const TQStringList &list, int index); - - /** - * Removes item @p index from combobox @p id. - */ - void removeComboItem (int id, int index); - - /** - * Sets item @p index to be current item in combobox @p id. - */ - void setCurrentComboItem (int id, int index); - - /** - * Changes item @p index in combobox @p id to text. - * - * @p index = -1 refers current item (one displayed in the button). - */ - void changeComboItem (int id, const TQString& text, int index=-1); - - /** - * Clears the combobox @p id. - * - * Does not delete it or hide it. - */ - void clearCombo (int id); - - /** - * Returns text of item @p index from combobox @p id. - * @return text of item @p index from combobox @p id. - * - * @p index = -1 refers to current item. - */ - - TQString getComboItem (int id, int index=-1) const; - - /** - * Returns a pointer to the combobox with @p id. - * @return a pointer to the combobox with @p id. - * - * Example: - * \code - * KComboBox *combo = toolbar->getCombo(combo_id); - * \endcode - * That way you can get access to other public methods - * that KComboBox provides. - */ - KComboBox * getCombo(int id); - - /** - * Returns a pointer to TDEToolBarLined with @p id. - * @return a pointer to TDEToolBarLined with @p id. - * - * Example: - * \code - * KLineEdit * lined = toolbar->getTDEToolBarLined(lined_id); - * \endcode - * That way you can get access to other public methods - * that KLineEdit provides. KLineEdit is the same thing - * as TQLineEdit plus completion signals. - */ - KLineEdit * getLined (int id); - - /** - * Returns a pointer to TDEToolBarButton. - * - * Example: - * \code - * TDEToolBarButton * button = toolbar->getButton(button_id); - * \endcode - * That way you can get access to other public methods - * that TDEToolBarButton provides. - * - * Using this method is not recommended. - */ - TDEToolBarButton * getButton (int id); - - /** - * Align item to the right. - * - * This works only if toolbar is set to full width. - * @see setFullWidth() - */ - void alignItemRight (int id, bool right = true); - - /** - * Returns a pointer to the widget corresponding to @p id. - * @return a pointer to the widget corresponding to @p id. - * - * Wrong ids are not tested. - * You can do with this whatever you want, - * except change its height (hardcoded). If you change its width - * you will probably have to call TQToolBar::updateRects(true) - * @see QWidget - * @see updateRects() - */ - TQWidget *getWidget (int id); // ### KDE4: make this const! - - /** - * Set item autosized. - * - * This works only if the toolbar is set to full width. - * Only @p one item can be autosized, and it has to be - * the last left-aligned item. Items that come after this must be right - * aligned. Items that can be right aligned are Lineds, Frames, Widgets and - * Combos. An autosized item will resize itself whenever the toolbar geometry - * changes to the last right-aligned item (or to end of toolbar if there - * are no right-aligned items.) - * @see setFullWidth() - * @see alignItemRight() - */ - void setItemAutoSized (int id, bool yes = true); - - /** - * Remove all items. - * - * The toolbar is redrawn after it. - */ - void clear (); - - /** - * Remove item @p id. - * - * Item is deleted. Toolbar is redrawn after it. - */ - void removeItem (int id); - - /** - * Remove item @p id. - * - * Item is deleted when toolbar is redrawn. - */ - void removeItemDelayed (int id); - - /** - * Hide item @p id. - */ - void hideItem (int id); - - /** - * Show item @p id. - */ - void showItem (int id); - - /** - * Returns the index of the item @p id. - * @return the index of the item @p id. - * @since 3.2 - */ - int itemIndex (int id); // ### KDE4: make this const! - - /** - * Returns the id of the item at the given index. - * @since 3.2 - */ - int idAt(int index); // ### KDE4: make this const! - - /** - * Set toolbar to full parent size (default). - * - * In full size mode the bar extends over the parent's full width or height. - * If the mode is disabled the toolbar tries to take as much space as it - * needs without wrapping, but it does not exceed the parent box. You can - * force a certain width or height with setMaxWidth() or - * setMaxHeight(). - * - * If you want to use right-aligned items or auto-sized items you must use - * full size mode. - */ - void setFullSize(bool flag = true); - - /** - * Returns the full-size mode enabled flag. - * @return @p true if the full-size mode is enabled. - */ - bool fullSize() const; - - /** - * Enable or disable moving of toolbar. - * @deprecated use setMovingEnabled(bool) instead. - */ - void enableMoving(bool flag = true) KDE_DEPRECATED; - - /** - * Set position of toolbar. - * @see BarPosition() - */ - void setBarPos (BarPosition bpos); - - /** - * Returns the toolbar position. - * @return position of toolbar. - */ - BarPosition barPos() const; - - /** - * Show, hide, or toggle toolbar. - * - * This method is provided for compatibility only, - * please use show() and/or hide() instead. - * @see BarStatus - * @deprecated - */ - bool enable(BarStatus stat) KDE_DEPRECATED; - - /** - * Use setMaximumHeight() instead. - * @deprecated - */ - void setMaxHeight (int h) KDE_DEPRECATED; // Set max height for vertical toolbars - - /** - * Returns the value set with setMaxHeight(). - * @deprecated - * Use maximumHeight() instead. - * @return the value set with setMaxHeight(). - */ - int maxHeight() KDE_DEPRECATED; - - /** - * Use setMaximumWidth() instead. - * Set maximal width of horizontal (top or bottom) toolbar. - * @deprecated - */ - void setMaxWidth (int dw) KDE_DEPRECATED; - - /** - * Returns the value set with setMaxWidth(). - * Use maximumWidth() instead. - * @return the value set with setMaxWidth(). - * @deprecated - */ - int maxWidth() KDE_DEPRECATED; - - /** - * Set title for toolbar when it floats. - * - * Titles are however not (yet) - * visible. You can't change toolbar's title while it's floating. - */ - void setTitle (const TQString& _title); - - /** - * Use setMovingEnabled(bool) instead. - * @deprecated - */ - void enableFloating (bool flag) KDE_DEPRECATED; - - /** - * Set the kind of painting for buttons. - * - * Choose from: - * @li IconOnly (only icons), - * @li IconTextRight (icon and text, text is left from icons), - * @li TextOnly (only text), - * @li IconTextBottom (icons and text, text is under icons). - * @see IconText - * - */ - void setIconText(IconText it); - // Note: don't merge with the next one, it breaks Qt properties - - /** - * Similar to setIconText(IconText it) but allows you to - * disable or enable updating. If @p update is false, then the - * buttons will not be updated. This is useful only if you know - * that you will be forcing an update later. - */ - void setIconText(IconText it, bool update); - - /** - * Returns the current text style for buttons. - * @return the current text style for buttons. - */ - IconText iconText() const; - - /** - * Set the icon size to load. Usually you should not call - * this, the icon size is taken care of by KIconLoader - * and globally configured. - * By default, the toolbar will load icons of size 32 for main - * toolbars and 22 for other toolbars - * @see KIconLoader. - * - * @param size The size to use - */ - void setIconSize(int size); - // Note: don't merge with the next one, it breaks Qt properties - - /** - * Same as setIconText(int size) but allows you - * to disable the toolbar update. - * - * @param size The size to use - * @param update If true, then the toolbar will be updated after - * this - */ - void setIconSize(int size, bool update); - - /** - * Returns the current icon size for buttons. - * @return the current icon size for buttons. - */ - int iconSize() const; - - /** - * Returns the default size for this type of toolbar. - * @return the default size for this type of toolbar. - */ - int iconSizeDefault() const; - - /** - * This allows you to enable or disable the context menu. - * - * @param enable If false, then the context menu will be disabled - */ - void setEnableContextMenu(bool enable = true); - - /** - * Returns the context menu enabled flag - * @return true if the context menu is disabled - */ - bool contextMenuEnabled() const; - - /** - * This will inform a toolbar button to ignore certain style - * changes. Specifically, it will ignore IconText (always IconOnly) - * and will not allow image effects to apply. - * - * @param id The button to exclude from styles - * @param no_style If true, then it is excluded (default: true). - */ - void setItemNoStyle(int id, bool no_style = true); - - void setFlat (bool flag); - - /** - * Returns the total number of items in the toolbar - * @return the total number of items in the toolbar - */ - int count() const; - - /** - * Instruct the toolbar to save it's current state to either the app - * config file or to the XML-GUI resource file (whichever has - * precedence). - */ - void saveState(); // BIC: remove for KDE4? This doesn't appear to be used internally, - // and apps use saveMainWindowSettings in TDEMainWindow anyway. - - /** - * Save the toolbar settings to group @p configGroup in @p config. - */ - void saveSettings(TDEConfig *config, const TQString &configGroup); - - /** - * Read the toolbar settings from group @p configGroup in @p config - * and apply them. Even default settings are re-applied if @p force is set. - */ - void applySettings(TDEConfig *config, const TQString &configGroup,bool force); - // KDE4 merge with force=false - void applySettings(TDEConfig *config, const TQString &configGroup); - - /* - * Tell the toolbar what XML-GUI resource file it should use to save - * it's state. The state of the toolbar (position, size, etc) is - * saved in TDEConfig files if the application does not use XML-GUI - * but if the app does, then it's saved the XML file. This function - * allows this to happen. - * - * @param xmlfile The XML-GUI resource file to write to - * @param xml The DOM document for the XML-GUI building - * @internal - */ - // void setXML(const TQString& xmlfile, const TQDomDocument& xml); - - void setXMLGUIClient( KXMLGUIClient *client ); - - /** - * Assign a (translated) text to this toolbar. This is used - * for the tooltip on the handle, and when listing the toolbars. - */ - void setText( const TQString & txt ); - - /** - * Returns the toolbar's text. - * @return the toolbar's text. - */ - TQString text() const; - - void setStretchableWidget( TQWidget *w ); - TQSizePolicy sizePolicy() const; - bool highlight() const; - TQSize sizeHint() const; - TQSize minimumSizeHint() const; - TQSize minimumSize() const; - - void hide(); - void show(); - - void updateRects( bool = false ) {} - - /** - * Load state from an XML element, called by KXMLGUIBuilder - */ - void loadState( const TQDomElement &e ); - /* - * Save state into an XML element, called by KXMLGUIBuilder - */ - void saveState( TQDomElement &e ); - - /** - * @internal - */ - void positionYourself( bool force = false); - -signals: - /** - * Emitted when button @p id is clicked. - */ - void clicked(int id); - - /** - * Emitted when button @p id is double-clicked. - * - * Note: you will always - * recive two clicked() , pressed() and released() signals. - * There is no way to avoid it - at least no easy way. - * If you need to resolve this all you can do is set up timers - * which wait for TQApplication::doubleClickInterval() to expire. - * If in that time you don't get this signal, you may belive that - * button was only clicked and not double-clicked. - * And please note that butons with popup menus do not emit this signal, - * but those with delayed popup do. - */ - void doubleClicked (int id); - - /** - * Emitted when button @p id is pressed. - */ - void pressed(int); - - /** - * Emits when button @p id is released. - */ - void released(int); - - /** - * Emitted when a toggle button changes state. - * - * Emitted also if you change state - * with setButton() or toggleButton() - * If you make a button normal again, with - * setToggle(false), this signal won't - * be emitted. - */ - void toggled(int); - - /** - * This signal is emitted when item @p id gets highlighted/unhighlighted - * (i.e when mouse enters/exits). - * - * Note that this signal is emitted from - * all buttons (normal, disabled and toggle) even when there is no visible - * change in buttons (i.e., buttons do not raise when mouse enters). - * The parameter @p isHighlighted is @p true when mouse enters and @p false when - * mouse exits. - */ - void highlighted(int id, bool isHighlighted); - - /** - * This signal is emitted when item @p id gets highlighted/unhighlighted - * (i.e when mouse enters/exits). - * - * Note that this signal is emitted from - * all buttons (normal, disabled and toggle) even when there is no visible - * change in buttons (i.e., buttons do not raise when mouse enters). - */ - void highlighted(int id ); - - /** - * Emitted when toolbar changes position, or when - * an item is removed from toolbar. - * - * If you subclass TDEMainWindow and reimplement - * TDEMainWindow::resizeEvent() be sure to connect to - * this signal. Note: You can connect this signal to a slot that - * doesn't take parameter. - */ - void moved( BarPosition ); - - /** - * This signal is emitted when toolbar detects changing of - * following parameters: - * highlighting, button-size, button-mode. This signal is - * internal, aimed to buttons. - * @internal - */ - void modechange (); - - /** - * This signal is emitted when the toolbar is getting deleted, - * and before ~TDEToolbar finishes (so it's still time to remove - * widgets from the toolbar). - * Used by KWidgetAction. - * @since 3.2 - */ - void toolbarDestroyed(); - -public: - /** - * Returns the global setting for "Highlight buttons under mouse" - * @return global setting for "Highlight buttons under mouse" - */ - static bool highlightSetting(); - - /** - * Returns the global setting for "Toolbars transparent when moving" - * @return global setting for "Toolbars transparent when moving" - */ - static bool transparentSetting(); - - /** - * Returns the global setting for "Icon Text" - * @return global setting for "Icon Text" - */ - static IconText iconTextSetting(); - -public slots: - virtual void setIconText( const TQString &txt ) - { TQToolBar::setIconText( txt ); } - -protected: - void mousePressEvent( TQMouseEvent * ); - void childEvent( TQChildEvent *e ); - void showEvent( TQShowEvent *e ); - void resizeEvent( TQResizeEvent *e ); - bool event( TQEvent *e ); - void applyAppearanceSettings(TDEConfig *config, const TQString &_configGroup, bool forceGlobal = false); - TQString settingsGroup() const; - -private slots: - void rebuildLayout(); - void slotReadConfig (); - void slotAppearanceChanged(); - void slotIconChanged(int); - void slotRepaint(); - void toolBarPosChanged( TQToolBar *tb ); - void slotContextAboutToShow(); - void slotContextAboutToHide(); - void widgetDestroyed(); - -private: - void init( bool readConfig = true, bool honorStyle = false ); - void doConnections( TDEToolBarButton *button ); - void insertWidgetInternal( TQWidget *w, int &index, int id ); - void removeWidgetInternal( TQWidget *w ); - void getAttributes( TQString &position, TQString &icontext, int &index ); - int dockWindowIndex(); - TDEPopupMenu *contextMenu(); - void doModeChange(); - - TQMap widget2id; - typedef TQMap Id2WidgetMap; - Id2WidgetMap id2widget; - TDEPopupMenu *context; - TQPtrList widgets; - TQTimer *layoutTimer; - TQGuardedPtr stretchableWidget, rightAligned; -protected: - virtual void virtual_hook( int id, void* data ); -private: - TDEToolBarPrivate *d; -}; - -#endif diff --git a/tdeui/ktoolbarbutton.cpp b/tdeui/ktoolbarbutton.cpp deleted file mode 100644 index 49ceb57fa..000000000 --- a/tdeui/ktoolbarbutton.cpp +++ /dev/null @@ -1,781 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) - (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) - (C) 1997, 1998 Sven Radej (radej@kde.org) - (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) - (C) 1999 Chris Schlaeger (cs@kde.org) - (C) 1999 Kurt Granroth (granroth@kde.org) - - 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. -*/ - -#include -#include - -#include "ktoolbarbutton.h" -#include "ktoolbar.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -// needed to get our instance -#include - -template class TQIntDict; - -class TDEToolBarButtonPrivate -{ -public: - TDEToolBarButtonPrivate() - { - m_buttonDown = false; - - m_noStyle = false; - m_isSeparator = false; - m_isRadio = false; - m_highlight = false; - m_isRaised = false; - m_isActive = false; - - m_iconName = TQString::null; - m_iconText = TDEToolBar::IconOnly; - m_iconSize = 0; - - m_parent = 0; - m_instance = TDEGlobal::instance(); - } - ~TDEToolBarButtonPrivate() - { - } - - int m_id; - bool m_buttonDown : 1; - bool m_noStyle: 1; - bool m_isSeparator: 1; - bool m_isRadio: 1; - bool m_highlight: 1; - bool m_isRaised: 1; - bool m_isActive: 1; - - TQString m_iconName; - - TDEToolBar *m_parent; - TDEToolBar::IconText m_iconText; - int m_iconSize; - TQSize size; - - TQPoint m_mousePressPos; - - TDEInstance *m_instance; -}; - -// This will construct a separator -TDEToolBarButton::TDEToolBarButton( TQWidget *_parent, const char *_name ) - : TQToolButton( _parent , _name) -{ - d = new TDEToolBarButtonPrivate; - - resize(6,6); - hide(); - d->m_isSeparator = true; -} - -TDEToolBarButton::TDEToolBarButton( const TQString& _icon, int _id, - TQWidget *_parent, const char *_name, - const TQString &_txt, TDEInstance *_instance ) - : TQToolButton( _parent, _name ), d( 0 ) -{ - d = new TDEToolBarButtonPrivate; - - d->m_id = _id; - TQToolButton::setTextLabel(_txt); - d->m_instance = _instance; - - d->m_parent = tqt_dynamic_cast(_parent); - if (d->m_parent) { - connect(d->m_parent, TQT_SIGNAL( modechange() ), - this, TQT_SLOT( modeChange() )); - } - - setFocusPolicy( TQ_NoFocus ); - - // connect all of our slots and start trapping events - connect(this, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( slotClicked() ) ); - connect(this, TQT_SIGNAL( pressed() ), - this, TQT_SLOT( slotPressed() ) ); - connect(this, TQT_SIGNAL( released() ), - this, TQT_SLOT( slotReleased() ) ); - installEventFilter(this); - - d->m_iconName = _icon; - - // do our initial setup - modeChange(); -} - -TDEToolBarButton::TDEToolBarButton( const TQPixmap& pixmap, int _id, - TQWidget *_parent, const char *name, - const TQString& txt) - : TQToolButton( _parent, name ), d( 0 ) -{ - d = new TDEToolBarButtonPrivate; - - d->m_id = _id; - TQToolButton::setTextLabel(txt); - - d->m_parent = tqt_dynamic_cast(_parent); - if (d->m_parent) { - connect(d->m_parent, TQT_SIGNAL( modechange() ), - this, TQT_SLOT( modeChange() )); - } - - setFocusPolicy( TQ_NoFocus ); - - // connect all of our slots and start trapping events - connect(this, TQT_SIGNAL( clicked() ), - this, TQT_SLOT( slotClicked() )); - connect(this, TQT_SIGNAL( pressed() ), - this, TQT_SLOT( slotPressed() )); - connect(this, TQT_SIGNAL( released() ), - this, TQT_SLOT( slotReleased() )); - installEventFilter(this); - - // set our pixmap and do our initial setup - setIconSet( TQIconSet( pixmap )); - modeChange(); -} - -TDEToolBarButton::~TDEToolBarButton() -{ - delete d; d = 0; -} - -void TDEToolBarButton::modeChange() -{ - TQSize mysize; - - // grab a few global variables for use in this function and others - if (d->m_parent) { - d->m_highlight = d->m_parent->highlight(); - d->m_iconText = d->m_parent->iconText(); - - d->m_iconSize = d->m_parent->iconSize(); - } - if (!d->m_iconName.isNull()) - setIcon(d->m_iconName); - - // we'll start with the size of our pixmap - int pix_width = d->m_iconSize; - if ( d->m_iconSize == 0 ) { - if (d->m_parent && !strcmp(d->m_parent->name(), "mainToolBar")) - pix_width = IconSize( KIcon::MainToolbar ); - else - pix_width = IconSize( KIcon::Toolbar ); - } - int pix_height = pix_width; - - int text_height = 0; - int text_width = 0; - - TQToolTip::remove(this); - if (d->m_iconText != TDEToolBar::IconOnly) - { - // okay, we have to deal with fonts. let's get our information now - TQFont tmp_font = TDEGlobalSettings::toolBarFont(); - - // now parse out our font sizes from our chosen font - TQFontMetrics fm(tmp_font); - - text_height = fm.lineSpacing(); - text_width = fm.width(textLabel()); - - // none of the other modes want tooltips - } - else - { - TQToolTip::add(this, textLabel()); - } - - switch (d->m_iconText) - { - case TDEToolBar::IconOnly: - mysize = TQSize(pix_width, pix_height); - break; - - case TDEToolBar::IconTextRight: - mysize = TQSize(pix_width + text_width + 4, pix_height); - break; - - case TDEToolBar::TextOnly: - mysize = TQSize(text_width + 4, text_height); - break; - - case TDEToolBar::IconTextBottom: - mysize = TQSize((text_width + 4 > pix_width) ? text_width + 4 : pix_width, pix_height + text_height); - break; - - default: - break; - } - - mysize = style().tqsizeFromContents(TQStyle::CT_ToolButton, this, mysize). - expandedTo(TQApplication::globalStrut()); - - // make sure that this isn't taller then it is wide - if (mysize.height() > mysize.width()) - mysize.setWidth(mysize.height()); - - d->size = mysize; - updateGeometry(); -} - -void TDEToolBarButton::setTextLabel( const TQString& text, bool tipToo) -{ - if (text.isNull()) - return; - - TQString txt(text); - if (txt.endsWith(TQString::fromLatin1("..."))) - txt.truncate(txt.length() - 3); - - TQToolButton::setTextLabel(txt, tipToo); - update(); -} - -void TDEToolBarButton::setText( const TQString& text) -{ - setTextLabel(text, true); - modeChange(); -} - -void TDEToolBarButton::setIcon( const TQString &icon ) -{ - d->m_iconName = icon; - if (d->m_parent) - d->m_iconSize = d->m_parent->iconSize(); - // TQObject::name() return "const char *" instead of TQString. - if (d->m_parent && !strcmp(d->m_parent->name(), "mainToolBar")) - TQToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet( - d->m_iconName, KIcon::MainToolbar, d->m_iconSize )); - else - TQToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet( - d->m_iconName, KIcon::Toolbar, d->m_iconSize )); -} - -void TDEToolBarButton::setIconSet( const TQIconSet &iconset ) -{ - TQToolButton::setIconSet( iconset ); -} - -// remove? -void TDEToolBarButton::setPixmap( const TQPixmap &pixmap ) -{ - if( pixmap.isNull()) // called by TQToolButton - { - TQToolButton::setPixmap( pixmap ); - return; - } - TQIconSet set = iconSet(); - set.setPixmap( pixmap, TQIconSet::Automatic, TQIconSet::Active ); - TQToolButton::setIconSet( set ); -} - -void TDEToolBarButton::setDefaultPixmap( const TQPixmap &pixmap ) -{ - TQIconSet set = iconSet(); - set.setPixmap( pixmap, TQIconSet::Automatic, TQIconSet::Normal ); - TQToolButton::setIconSet( set ); -} - -void TDEToolBarButton::setDisabledPixmap( const TQPixmap &pixmap ) -{ - TQIconSet set = iconSet(); - set.setPixmap( pixmap, TQIconSet::Automatic, TQIconSet::Disabled ); - TQToolButton::setIconSet( set ); -} - -void TDEToolBarButton::setDefaultIcon( const TQString& icon ) -{ - TQIconSet set = iconSet(); - TQPixmap pm; - if (d->m_parent && !strcmp(d->m_parent->name(), "mainToolBar")) - pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::MainToolbar, - d->m_iconSize ); - else - pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::Toolbar, - d->m_iconSize ); - set.setPixmap( pm, TQIconSet::Automatic, TQIconSet::Normal ); - TQToolButton::setIconSet( set ); -} - -void TDEToolBarButton::setDisabledIcon( const TQString& icon ) -{ - TQIconSet set = iconSet(); - TQPixmap pm; - if (d->m_parent && !strcmp(d->m_parent->name(), "mainToolBar")) - pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::MainToolbar, - d->m_iconSize ); - else - pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::Toolbar, - d->m_iconSize ); - set.setPixmap( pm, TQIconSet::Automatic, TQIconSet::Disabled ); - TQToolButton::setIconSet( set ); -} - -TQPopupMenu *TDEToolBarButton::popup() -{ - // obsolete - // KDE4: remove me - return TQToolButton::popup(); -} - -void TDEToolBarButton::setPopup(TQPopupMenu *p, bool) -{ - TQToolButton::setPopup(p); - TQToolButton::setPopupDelay(-1); -} - - -void TDEToolBarButton::setDelayedPopup (TQPopupMenu *p, bool) -{ - TQToolButton::setPopup(p); - TQToolButton::setPopupDelay(TQApplication::startDragTime()); -} - -void TDEToolBarButton::leaveEvent(TQEvent *) -{ - if( d->m_isRaised || d->m_isActive ) - { - d->m_isRaised = false; - d->m_isActive = false; - repaint(false); - } - - emit highlighted(d->m_id, false); -} - -void TDEToolBarButton::enterEvent(TQEvent *) -{ - if (d->m_highlight) - { - if (isEnabled()) - { - d->m_isActive = true; - if (!isToggleButton()) - d->m_isRaised = true; - } - else - { - d->m_isRaised = false; - d->m_isActive = false; - } - - repaint(false); - } - emit highlighted(d->m_id, true); -} - -bool TDEToolBarButton::eventFilter(TQObject *o, TQEvent *ev) -{ - if (TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(this)) - { - - // Popup the menu when the left mousebutton is pressed and the mouse - // is moved by a small distance. - if (TQToolButton::popup()) - { - if (ev->type() == TQEvent::MouseButtonPress) - { - TQMouseEvent* mev = TQT_TQMOUSEEVENT(ev); - d->m_mousePressPos = mev->pos(); - } - else if (ev->type() == TQEvent::MouseMove) - { - TQMouseEvent* mev = TQT_TQMOUSEEVENT(ev); - if ((mev->pos() - d->m_mousePressPos).manhattanLength() - > TDEGlobalSettings::dndEventDelay()) - { - openPopup(); - return true; - } - } - } - - if (d->m_isRadio && - (ev->type() == TQEvent::MouseButtonPress || - ev->type() == TQEvent::MouseButtonRelease || - ev->type() == TQEvent::MouseButtonDblClick) && isOn()) - return true; - - // From Kai-Uwe Sattler - if (ev->type() == TQEvent::MouseButtonDblClick) - { - emit doubleClicked(d->m_id); - return false; - } - } - - return TQToolButton::eventFilter(o, ev); -} - -void TDEToolBarButton::mousePressEvent( TQMouseEvent * e ) -{ - d->m_buttonDown = true; - - if ( e->button() == Qt::MidButton ) - { - // Get TQToolButton to show the button being down while pressed - TQMouseEvent ev( TQEvent::MouseButtonPress, e->pos(), e->globalPos(), Qt::LeftButton, e->state() ); - TQToolButton::mousePressEvent(&ev); - return; - } - TQToolButton::mousePressEvent(e); -} - -void TDEToolBarButton::mouseReleaseEvent( TQMouseEvent * e ) -{ - TQt::ButtonState state = TQt::ButtonState(e->button() | (e->state() & KeyButtonMask)); - if ( e->button() == Qt::MidButton ) - { - TQMouseEvent ev( TQEvent::MouseButtonRelease, e->pos(), e->globalPos(), Qt::LeftButton, e->state() ); - TQToolButton::mouseReleaseEvent(&ev); - } - else - TQToolButton::mouseReleaseEvent(e); - - if ( !d->m_buttonDown ) - return; - d->m_buttonDown = false; - - if ( hitButton( e->pos() ) ) - emit buttonClicked( d->m_id, state ); -} - -void TDEToolBarButton::drawButton( TQPainter *_painter ) -{ - TQStyle::SFlags flags = TQStyle::Style_Default; - TQStyle::SCFlags active = TQStyle::SC_None; - - if (isDown()) { - flags |= TQStyle::Style_Down; - active |= TQStyle::SC_ToolButton; - } - if (isEnabled()) flags |= TQStyle::Style_Enabled; - if (isOn()) flags |= TQStyle::Style_On; - if (isEnabled() && hasMouse()) flags |= TQStyle::Style_Raised; - if (hasFocus()) flags |= TQStyle::Style_HasFocus; - - // Draw a styled toolbutton - style().drawComplexControl(TQStyle::CC_ToolButton, _painter, this, rect(), - colorGroup(), flags, TQStyle::SC_ToolButton, active, TQStyleOption()); - - int dx, dy; - TQFont tmp_font(TDEGlobalSettings::toolBarFont()); - TQFontMetrics fm(tmp_font); - TQRect textRect; - int textFlags = 0; - - if (d->m_iconText == TDEToolBar::IconOnly) // icon only - { - TQPixmap pixmap = iconSet().pixmap( TQIconSet::Automatic, - isEnabled() ? (d->m_isActive ? TQIconSet::Active : TQIconSet::Normal) : - TQIconSet::Disabled, - isOn() ? TQIconSet::On : TQIconSet::Off ); - if( !pixmap.isNull()) - { - dx = ( width() - pixmap.width() ) / 2; - dy = ( height() - pixmap.height() ) / 2; - if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) - { - ++dx; - ++dy; - } - _painter->drawPixmap( dx, dy, pixmap ); - } - } - else if (d->m_iconText == TDEToolBar::IconTextRight) // icon and text (if any) - { - TQPixmap pixmap = iconSet().pixmap( TQIconSet::Automatic, - isEnabled() ? (d->m_isActive ? TQIconSet::Active : TQIconSet::Normal) : - TQIconSet::Disabled, - isOn() ? TQIconSet::On : TQIconSet::Off ); - if( !pixmap.isNull()) - { - dx = 4; - dy = ( height() - pixmap.height() ) / 2; - if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) - { - ++dx; - ++dy; - } - _painter->drawPixmap( dx, dy, pixmap ); - } - - if (!textLabel().isNull()) - { - textFlags = AlignVCenter|AlignLeft; - if (!pixmap.isNull()) - dx = 4 + pixmap.width() + 2; - else - dx = 4; - dy = 0; - if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) - { - ++dx; - ++dy; - } - textRect = TQRect(dx, dy, width()-dx, height()); - } - } - else if (d->m_iconText == TDEToolBar::TextOnly) - { - if (!textLabel().isNull()) - { - textFlags = AlignVCenter|AlignLeft; - dx = (width() - fm.width(textLabel())) / 2; - dy = (height() - fm.lineSpacing()) / 2; - if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) - { - ++dx; - ++dy; - } - textRect = TQRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() ); - } - } - else if (d->m_iconText == TDEToolBar::IconTextBottom) - { - TQPixmap pixmap = iconSet().pixmap( TQIconSet::Automatic, - isEnabled() ? (d->m_isActive ? TQIconSet::Active : TQIconSet::Normal) : - TQIconSet::Disabled, - isOn() ? TQIconSet::On : TQIconSet::Off ); - if( !pixmap.isNull()) - { - dx = (width() - pixmap.width()) / 2; - dy = (height() - fm.lineSpacing() - pixmap.height()) / 2; - if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) - { - ++dx; - ++dy; - } - _painter->drawPixmap( dx, dy, pixmap ); - } - - if (!textLabel().isNull()) - { - textFlags = AlignBottom|AlignHCenter; - dx = (width() - fm.width(textLabel())) / 2; - dy = height() - fm.lineSpacing() - 4; - - if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) - { - ++dx; - ++dy; - } - textRect = TQRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() ); - } - } - - // Draw the text at the position given by textRect, and using textFlags - if (!textLabel().isNull() && !textRect.isNull()) - { - _painter->setFont(TDEGlobalSettings::toolBarFont()); - if (!isEnabled()) - _painter->setPen(palette().disabled().dark()); - else if(d->m_isRaised) - _painter->setPen(TDEGlobalSettings::toolBarHighlightColor()); - else - _painter->setPen( colorGroup().buttonText() ); - _painter->drawText(textRect, textFlags, textLabel()); - } - - if (TQToolButton::popup()) - { - TQStyle::SFlags arrowFlags = TQStyle::Style_Default; - - if (isDown()) arrowFlags |= TQStyle::Style_Down; - if (isEnabled()) arrowFlags |= TQStyle::Style_Enabled; - - style().tqdrawPrimitive(TQStyle::PE_ArrowDown, _painter, - TQRect(width()-7, height()-7, 7, 7), colorGroup(), - arrowFlags, TQStyleOption() ); - } -} - -void TDEToolBarButton::paletteChange(const TQPalette &) -{ - if(!d->m_isSeparator) - { - modeChange(); - repaint(false); // no need to delete it first therefore only false - } -} - -bool TDEToolBarButton::event(TQEvent *e) -{ - if (e->type() == TQEvent::ParentFontChange || e->type() == TQEvent::ApplicationFontChange) - { - //If we use toolbar text, apply the settings again, to relayout... - if (d->m_iconText != TDEToolBar::IconOnly) - modeChange(); - return true; - } - - return TQToolButton::event(e); -} - - -void TDEToolBarButton::showMenu() -{ - // obsolete - // KDE4: remove me -} - -void TDEToolBarButton::slotDelayTimeout() -{ - // obsolete - // KDE4: remove me -} - -void TDEToolBarButton::slotClicked() -{ - emit clicked( d->m_id ); - - // emit buttonClicked when the button was clicked while being in an extension popupmenu - if ( d->m_parent && !d->m_parent->rect().contains( geometry().center() ) ) { - ButtonState state = TDEApplication::keyboardMouseState(); - if ( ( state & Qt::MouseButtonMask ) == Qt::NoButton ) - state = ButtonState( Qt::LeftButton | state ); - emit buttonClicked( d->m_id, state ); // Doesn't work with MidButton - } -} - -void TDEToolBarButton::slotPressed() -{ - emit pressed( d->m_id ); -} - -void TDEToolBarButton::slotReleased() -{ - emit released( d->m_id ); -} - -void TDEToolBarButton::slotToggled() -{ - emit toggled( d->m_id ); -} - -void TDEToolBarButton::setNoStyle(bool no_style) -{ - d->m_noStyle = no_style; - - modeChange(); - d->m_iconText = TDEToolBar::IconTextRight; - repaint(false); -} - -void TDEToolBarButton::setRadio (bool f) -{ - if ( d ) - d->m_isRadio = f; -} - -void TDEToolBarButton::on(bool flag) -{ - if(isToggleButton()) - setOn(flag); - else - { - setDown(flag); - leaveEvent((TQEvent *) 0); - } - repaint(); -} - -void TDEToolBarButton::toggle() -{ - setOn(!isOn()); - repaint(); -} - -void TDEToolBarButton::setToggle(bool flag) -{ - setToggleButton(flag); - if (flag) - connect(this, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggled())); - else - disconnect(this, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggled())); -} - -TQSize TDEToolBarButton::sizeHint() const -{ - return d->size; -} - -TQSize TDEToolBarButton::minimumSizeHint() const -{ - return d->size; -} - -TQSize TDEToolBarButton::minimumSize() const -{ - return d->size; -} - -bool TDEToolBarButton::isRaised() const -{ - return d->m_isRaised; -} - -bool TDEToolBarButton::isActive() const -{ - return d->m_isActive; -} - -int TDEToolBarButton::iconTextMode() const -{ - return static_cast( d->m_iconText ); -} - -int TDEToolBarButton::id() const -{ - return d->m_id; -} - -// TDEToolBarButtonList -TDEToolBarButtonList::TDEToolBarButtonList() -{ - setAutoDelete(false); -} - -void TDEToolBarButton::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -#include "ktoolbarbutton.moc" diff --git a/tdeui/ktoolbarbutton.h b/tdeui/ktoolbarbutton.h deleted file mode 100644 index 49e906e6e..000000000 --- a/tdeui/ktoolbarbutton.h +++ /dev/null @@ -1,331 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) - (C) 1997, 1998 Sven Radej (radej@kde.org) - (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) - (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) - (C) 2000 Kurt Granroth (granroth@kde.org) - - 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 _KTOOLBARBUTTON_H -#define _KTOOLBARBUTTON_H - -#include -#include -#include -#include -#include - -class TDEToolBar; -class TDEToolBarButtonPrivate; -class TDEInstance; -class TQEvent; -class TQPopupMenu; -class TQPainter; - -/** - * A toolbar button. This is used internally by TDEToolBar, use the - * TDEToolBar methods instead. - * @internal - */ -class TDEUI_EXPORT TDEToolBarButton : public TQToolButton -{ - Q_OBJECT - - -public: - /** - * Construct a button with an icon loaded by the button itself. - * This will trust the button to load the correct icon with the - * correct size. - * - * @param icon Name of icon to load (may be absolute or relative) - * @param id Id of this button - * @param parent This button's parent - * @param name This button's internal name - * @param txt This button's text (in a tooltip or otherwise) - * @param _instance the instance to use for this button - */ - TDEToolBarButton(const TQString& icon, int id, TQWidget *parent, - const char *name=0L, const TQString &txt=TQString::null, - TDEInstance *_instance = TDEGlobal::instance()); - - /** - * Construct a button with an existing pixmap. It is not - * recommended that you use this as the internal icon loading code - * will almost always get it "right". - * - * @param pixmap Name of icon to load (may be absolute or relative) - * @param id Id of this button - * @param parent This button's parent - * @param name This button's internal name - * @param txt This button's text (in a tooltip or otherwise) - */ - TDEToolBarButton(const TQPixmap& pixmap, int id, TQWidget *parent, - const char *name=0L, const TQString &txt=TQString::null); - - /** - * Construct a separator button - * - * @param parent This button's parent - * @param name This button's internal name - */ - TDEToolBarButton(TQWidget *parent=0L, const char *name=0L); - - /** - * Standard destructor - */ - ~TDEToolBarButton(); - -#ifndef KDE_NO_COMPAT - /** - * @deprecated - * Set the pixmap directly for this button. This pixmap should be - * the active one... the dimmed and disabled pixmaps are constructed - * based on this one. However, don't use this function unless you - * are positive that you don't want to use setIcon. - * - * @param pixmap The active pixmap - */ - // this one is from TQButton, so #ifdef-ing it out doesn't break BC - virtual void setPixmap(const TQPixmap &pixmap) KDE_DEPRECATED; - - /** - * @deprecated - * Force the button to use this pixmap as the default one rather - * then generating it using effects. - * - * @param pixmap The pixmap to use as the default (normal) one - */ - void setDefaultPixmap(const TQPixmap& pixmap) KDE_DEPRECATED; - - /** - * @deprecated - * Force the button to use this pixmap when disabled one rather then - * generating it using effects. - * - * @param pixmap The pixmap to use when disabled - */ - void setDisabledPixmap(const TQPixmap& pixmap) KDE_DEPRECATED; -#endif - - /** - * Set the text for this button. The text will be either used as a - * tooltip (IconOnly) or will be along side the icon - * - * @param text The button (or tooltip) text - */ - virtual void setText(const TQString &text); - - /** - * Set the icon for this button. The icon will be loaded internally - * with the correct size. This function is preferred over setIconSet - * - * @param icon The name of the icon - */ - virtual void setIcon(const TQString &icon); - - /// @since 3.1 - virtual void setIcon( const TQPixmap &pixmap ) - { TQToolButton::setIcon( pixmap ); } - - /** - * Set the pixmaps for this toolbar button from a TQIconSet. - * If you call this you don't need to call any of the other methods - * that set icons or pixmaps. - * @param iconset The iconset to use - */ - virtual void setIconSet( const TQIconSet &iconset ); - -#ifndef KDE_NO_COMPAT - /** - * @deprecated - * Set the active icon for this button. The pixmap itself is loaded - * internally based on the icon size... .. the disabled and default - * pixmaps, however will only be constructed if generate is - * true. This function is preferred over setPixmap - * - * @param icon The name of the active icon - * @param generate If true, then the other icons are automagically - * generated from this one - */ - KDE_DEPRECATED void setIcon(const TQString &icon, bool generate ) { Q_UNUSED(generate); setIcon( icon ); } - - /** - * @deprecated - * Force the button to use this icon as the default one rather - * then generating it using effects. - * - * @param icon The icon to use as the default (normal) one - */ - void setDefaultIcon(const TQString& icon) KDE_DEPRECATED; - - /** - * @deprecated - * Force the button to use this icon when disabled one rather then - * generating it using effects. - * - * @param icon The icon to use when disabled - */ - void setDisabledIcon(const TQString& icon) KDE_DEPRECATED; -#endif - - /** - * Turn this button on or off - * - * @param flag true or false - */ - void on(bool flag = true); - - /** - * Toggle this button - */ - void toggle(); - - /** - * Turn this button into a toggle button or disable the toggle - * aspects of it. This does not toggle the button itself. - * Use toggle() for that. - * - * @param toggle true or false - */ - void setToggle(bool toggle = true); - - /** - * Return a pointer to this button's popup menu (if it exists) - */ - TQPopupMenu *popup(); - - /** - * Returns the button's id. - * @since 3.2 - */ - int id() const; - - /** - * Give this button a popup menu. There will not be a delay when - * you press the button. Use setDelayedPopup if you want that - * behavior. - * - * @param p The new popup menu - * @param unused Has no effect - ignore it. - */ - void setPopup (TQPopupMenu *p, bool unused = false); - - /** - * Gives this button a delayed popup menu. - * - * This function allows you to add a delayed popup menu to the button. - * The popup menu is then only displayed when the button is pressed and - * held down for about half a second. - * - * @param p the new popup menu - * @param unused Has no effect - ignore it. - */ - void setDelayedPopup(TQPopupMenu *p, bool unused = false); - - /** - * Turn this button into a radio button - * - * @param f true or false - */ - void setRadio(bool f = true); - - /** - * Toolbar buttons naturally will assume the global styles - * concerning icons, icons sizes, etc. You can use this function to - * explicitly turn this off, if you like. - * - * @param no_style Will disable styles if true - */ - void setNoStyle(bool no_style = true); - -signals: - /** - * Emitted when the toolbar button is clicked (with LMB or MMB) - */ - void clicked(int); - /** - * Emitted when the toolbar button is clicked (with any mouse button) - * @param state makes it possible to find out which button was pressed, - * and whether any keyboard modifiers were held. - * @since 3.4 - */ - void buttonClicked(int, TQt::ButtonState state); - void doubleClicked(int); - void pressed(int); - void released(int); - void toggled(int); - void highlighted(int, bool); - -public slots: - /** - * This slot should be called whenever the toolbar mode has - * potentially changed. This includes such events as text changing, - * orientation changing, etc. - */ - void modeChange(); - virtual void setTextLabel(const TQString&, bool tipToo); - -protected: - bool event(TQEvent *e); - void paletteChange(const TQPalette &); - void leaveEvent(TQEvent *e); - void enterEvent(TQEvent *e); - void drawButton(TQPainter *p); - bool eventFilter (TQObject *o, TQEvent *e); - /// @since 3.4 - void mousePressEvent( TQMouseEvent * ); - /// @since 3.4 - void mouseReleaseEvent( TQMouseEvent * ); - void showMenu(); - TQSize sizeHint() const; - TQSize minimumSizeHint() const; - TQSize minimumSize() const; - - /// @since 3.1 - bool isRaised() const; - /// @since 3.1 - bool isActive() const; - /// @since 3.1 - int iconTextMode() const; - -protected slots: - void slotClicked(); - void slotPressed(); - void slotReleased(); - void slotToggled(); - void slotDelayTimeout(); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - TDEToolBarButtonPrivate *d; -}; - -/** -* List of TDEToolBarButton objects. -* @internal -* @version $Id$ -*/ -class TDEUI_EXPORT TDEToolBarButtonList : public TQIntDict -{ -public: - TDEToolBarButtonList(); - ~TDEToolBarButtonList() {} -}; - -#endif diff --git a/tdeui/ktoolbarhandler.cpp b/tdeui/ktoolbarhandler.cpp deleted file mode 100644 index 1d08565d7..000000000 --- a/tdeui/ktoolbarhandler.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2002 Simon Hausmann - - 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. -*/ - -#include "ktoolbarhandler.h" - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - const char *actionListName = "show_menu_and_toolbar_actionlist"; - - const char *guiDescription = "" - "" - "" - "

" - " " - " " - "" - ""; - - const char *resourceFileName = "barhandler.rc"; - - class BarActionBuilder - { - public: - BarActionBuilder( TDEActionCollection *actionCollection, TDEMainWindow *mainWindow, TQPtrList &oldToolBarList ) - : m_actionCollection( actionCollection ), m_mainWindow( mainWindow ), m_needsRebuild( false ) - { - TQPtrList dockWindows = m_mainWindow->dockWindows(); - TQPtrListIterator dockWindowIt( dockWindows ); - for ( ; dockWindowIt.current(); ++dockWindowIt ) { - - TDEToolBar *toolBar = tqt_dynamic_cast( dockWindowIt.current() ); - if ( !toolBar ) - continue; - - if ( oldToolBarList.findRef( toolBar ) == -1 ) - m_needsRebuild = true; - - m_toolBars.append( toolBar ); - } - - if ( !m_needsRebuild ) - m_needsRebuild = ( oldToolBarList.count() != m_toolBars.count() ); - } - - bool needsRebuild() const { return m_needsRebuild; } - - TQPtrList create() - { - if ( !m_needsRebuild ) - return TQPtrList(); - - TQPtrListIterator toolBarIt( m_toolBars ); - for ( ; toolBarIt.current(); ++toolBarIt ) - handleToolBar( toolBarIt.current() ); - - TQPtrList actions; - - if ( m_toolBarActions.count() == 0 ) - return actions; - - if ( m_toolBarActions.count() == 1 ) { - TDEToggleToolBarAction* action = static_cast( m_toolBarActions.getFirst() ); - action->setText( i18n( "Show Toolbar" ) ); - action->setCheckedState( i18n( "Hide Toolbar" ) ); - return m_toolBarActions; - } - - TDEActionMenu *menuAction = new TDEActionMenu( i18n( "Toolbars" ), m_actionCollection, "toolbars_submenu_action" ); - - TQPtrListIterator actionIt( m_toolBarActions ); - for ( ; actionIt.current(); ++actionIt ) - menuAction->insert( actionIt.current() ); - - actions.append( menuAction ); - return actions; - } - - const TQPtrList &toolBars() const { return m_toolBars; } - - private: - void handleToolBar( TDEToolBar *toolBar ) - { - TDEToggleToolBarAction *action = new TDEToggleToolBarAction( - toolBar, - toolBar->label(), - m_actionCollection, - toolBar->name() ); - // ## tooltips, whatsthis? - m_toolBarActions.append( action ); - } - - TDEActionCollection *m_actionCollection; - TDEMainWindow *m_mainWindow; - - TQPtrList m_toolBars; - TQPtrList m_toolBarActions; - - bool m_needsRebuild : 1; - }; -} - -using namespace KDEPrivate; - -ToolBarHandler::ToolBarHandler( TDEMainWindow *mainWindow, const char *name ) - : TQObject( mainWindow, name ), KXMLGUIClient( mainWindow ) -{ - init( mainWindow ); -} - -ToolBarHandler::ToolBarHandler( TDEMainWindow *mainWindow, TQObject *parent, const char *name ) - : TQObject( parent, name ), KXMLGUIClient( mainWindow ) -{ - init( mainWindow ); -} - -ToolBarHandler::~ToolBarHandler() -{ - m_actions.setAutoDelete( true ); - m_actions.clear(); -} - -TDEAction *ToolBarHandler::toolBarMenuAction() -{ - assert( m_actions.count() == 1 ); - return m_actions.getFirst(); -} - -void ToolBarHandler::setupActions() -{ - if ( !factory() || !m_mainWindow ) - return; - - BarActionBuilder builder( actionCollection(), m_mainWindow, m_toolBars ); - - if ( !builder.needsRebuild() ) - return; - - unplugActionList( actionListName ); - - m_actions.setAutoDelete( true ); - m_actions.clear(); - m_actions.setAutoDelete( false ); - - m_actions = builder.create(); - - /* - for ( TQPtrListIterator toolBarIt( m_toolBars ); - toolBarIt.current(); ++toolBarIt ) - toolBarIt.current()->disconnect( this ); - */ - - m_toolBars = builder.toolBars(); - - /* - for ( TQPtrListIterator toolBarIt( m_toolBars ); - toolBarIt.current(); ++toolBarIt ) - connect( toolBarIt.current(), TQT_SIGNAL( destroyed() ), - this, TQT_SLOT( setupActions() ) ); - */ - - if (kapp && kapp->authorizeTDEAction("options_show_toolbar")) - plugActionList( actionListName, m_actions ); - - connectToActionContainers(); -} - -void ToolBarHandler::clientAdded( KXMLGUIClient *client ) -{ - if ( client == this ) - setupActions(); -} - -void ToolBarHandler::init( TDEMainWindow *mainWindow ) -{ - d = 0; - m_mainWindow = mainWindow; - - connect( m_mainWindow->guiFactory(), TQT_SIGNAL( clientAdded( KXMLGUIClient * ) ), - this, TQT_SLOT( clientAdded( KXMLGUIClient * ) ) ); - - /* re-use an existing resource file if it exists. can happen if the user launches the - * toolbar editor */ - /* - setXMLFile( resourceFileName ); - */ - - if ( domDocument().documentElement().isNull() ) { - - TQString completeDescription = TQString::fromLatin1( guiDescription ) - .arg( actionListName ); - - setXML( completeDescription, false /*merge*/ ); - } -} - -void ToolBarHandler::connectToActionContainers() -{ - TQPtrListIterator actionIt( m_actions ); - for ( ; actionIt.current(); ++actionIt ) - connectToActionContainer( actionIt.current() ); -} - -void ToolBarHandler::connectToActionContainer( TDEAction *action ) -{ - uint containerCount = action->containerCount(); - for ( uint i = 0; i < containerCount; ++i ) - connectToActionContainer( action->container( i ) ); -} - -void ToolBarHandler::connectToActionContainer( TQWidget *container ) -{ - TQPopupMenu *popupMenu = tqt_dynamic_cast( container ); - if ( !popupMenu ) - return; - - connect( popupMenu, TQT_SIGNAL( aboutToShow() ), - this, TQT_SLOT( setupActions() ) ); -} - -#include "ktoolbarhandler.moc" - -/* vim: et sw=4 ts=4 - */ diff --git a/tdeui/ktoolbarhandler.h b/tdeui/ktoolbarhandler.h deleted file mode 100644 index 729129a67..000000000 --- a/tdeui/ktoolbarhandler.h +++ /dev/null @@ -1,69 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2002 Simon Hausmann - - 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 KBARHANDLER_H -#define KBARHANDLER_H - -#include -#include -#include - -class TDEMainWindow; -class TDEToolBar; - -namespace KDEPrivate -{ - -/// @since 3.1 -class ToolBarHandler : public TQObject, - public KXMLGUIClient -{ - Q_OBJECT -public: - ToolBarHandler( TDEMainWindow *mainWindow, const char *name = 0 ); - ToolBarHandler( TDEMainWindow *mainWindow, TQObject *parent, const char *name = 0 ); - virtual ~ToolBarHandler(); - - TDEAction *toolBarMenuAction(); - -public slots: - void setupActions(); - -private slots: - void clientAdded( KXMLGUIClient *client ); - -private: - void init( TDEMainWindow *mainWindow ); - void connectToActionContainers(); - void connectToActionContainer( TDEAction *action ); - void connectToActionContainer( TQWidget *container ); - - struct Data; - Data *d; - - TQGuardedPtr m_mainWindow; - TQPtrList m_actions; - TQPtrList m_toolBars; -}; - -} // namespace KDEPrivate - -#endif // KBARHANDLER_H - -/* vim: et sw=4 ts=4 - */ diff --git a/tdeui/ktoolbarlabelaction.cpp b/tdeui/ktoolbarlabelaction.cpp deleted file mode 100644 index 1716a64e8..000000000 --- a/tdeui/ktoolbarlabelaction.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2004 Felix Berger - - 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. -*/ - -#include "ktoolbarlabelaction.h" - -#include -#include - -class TDEToolBarLabelAction::TDEToolBarLabelActionPrivate -{ -public: - TDEToolBarLabelActionPrivate() - : m_label(0) - { - } - TQLabel* m_label; -}; - - -TDEToolBarLabelAction::TDEToolBarLabelAction(const TQString &text, - const TDEShortcut &cut, - const TQObject *receiver, - const char *slot, - TDEActionCollection *parent, - const char *name) - : KWidgetAction(new TQLabel(text, 0, "kde toolbar widget"), text, cut, - receiver, slot, parent, name), - d(new TDEToolBarLabelActionPrivate) -{ - init(); -} - -TDEToolBarLabelAction::TDEToolBarLabelAction(TQWidget* buddy, - const TQString &text, - const TDEShortcut &cut, - const TQObject *receiver, - const char *slot, - TDEActionCollection *parent, - const char *name) - : KWidgetAction(new TQLabel(buddy, text, 0, "kde toolbar widget"), text, - cut, receiver, slot, parent, name), - d(new TDEToolBarLabelActionPrivate) -{ - init(); -} - -TDEToolBarLabelAction::TDEToolBarLabelAction(TQLabel* label, - const TDEShortcut &cut, - const TQObject *receiver, - const char *slot, - TDEActionCollection* parent, - const char *name) - : KWidgetAction(label, label->text(), cut, receiver, slot, parent, name), - d(new TDEToolBarLabelActionPrivate) -{ - Q_ASSERT(TQString::fromLatin1("kde toolbar widget") == label->name()); - init(); -} - -TDEToolBarLabelAction::~TDEToolBarLabelAction() -{ - delete d; - d = 0; -} - -void TDEToolBarLabelAction::init() -{ - d->m_label = static_cast(widget()); - /* these lines were copied from Konqueror's KonqDraggableLabel class in - konq_misc.cc */ - d->m_label->setBackgroundMode(TQt::PaletteButton); - d->m_label->setAlignment((TQApplication::reverseLayout() - ? Qt::AlignRight : Qt::AlignLeft) | - Qt::AlignVCenter | TQt::ShowPrefix ); - d->m_label->adjustSize(); -} - -void TDEToolBarLabelAction::setText(const TQString& text) -{ - KWidgetAction::setText(text); - d->m_label->setText(text); -} - -void TDEToolBarLabelAction::setBuddy(TQWidget* buddy) -{ - d->m_label->setBuddy(buddy); -} - -TQWidget* TDEToolBarLabelAction::buddy() const -{ - return d->m_label->buddy(); -} - -TQLabel* TDEToolBarLabelAction::label() const -{ - return d->m_label; -} - -void TDEToolBarLabelAction::virtual_hook(int, void*) -{ - -} diff --git a/tdeui/ktoolbarlabelaction.h b/tdeui/ktoolbarlabelaction.h deleted file mode 100644 index 02b1cd28c..000000000 --- a/tdeui/ktoolbarlabelaction.h +++ /dev/null @@ -1,137 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2004 Felix Berger - - 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 KTOOLBARLABELACTION_H -#define KTOOLBARLABELACTION_H - -#include - -class TQLabel; - -/** - * @short Class to display a label in a toolbar. - * - * TDEToolBarLabelAction is a convenience class for displaying a label in a - * toolbar. - * - * It provides easy access to the label's #setBuddy(TQWidget*) and #buddy() - * methods and can be used as follows: - * - * \code - * - * KHistoryCombo* findCombo = new KHistoryCombo(true, this); - * KWidgetAction* action - * = new KWidgetAction(findCombo, i18n("F&ind Combo"), Qt::Key_F6, this, - * TQT_SLOT(slotFocus()), actionCollection(), "find_combo"); - * - * new TDEToolBarLabelAction(findCombo, i18n("F&ind "), 0, this, - * TQT_SLOT(slotFocus()), actionCollection(), - * "find_label"); - * - * \endcode - * - * @author Felix Berger - */ -class TDEUI_EXPORT TDEToolBarLabelAction : public KWidgetAction -{ -public: - /** - * Constructs a toolbar label. - * - * @param text The label's and the action's text. - * @param cut The action's shortcut. - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToolBarLabelAction(const TQString &text, - const TDEShortcut &cut, - const TQObject *receiver, const char *slot, - TDEActionCollection *parent, const char *name); - /** - * Constructs a toolbar label setting a buddy for the label. - * - * @param buddy The widget which is focused when the label's accelerator is - * typed. - * @param text The label's and the action's text. - * @param cut The action's shortcut. - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToolBarLabelAction(TQWidget* buddy, const TQString &text, - const TDEShortcut &cut, - const TQObject *receiver, const char *slot, - TDEActionCollection *parent, const char *name); - /** - * Constructs a toolbar label for a label. - * - * You can use this constructor if you want to display a class which is - * derived from TQLabel in the toolbar. Note that ownership of the label is - * transferred to the action and the label is deleted when the action is - * deleted. So you shouldn't hold any pointers to the label. - * - * It's important that the label's name is set to "kde toolbar widget" in - * its constructor, otherwise it is not correctly rendered in some kde - * styles. - * - * @param label the label which is displayed in the toolbar. - * @param cut The action's shortcut. - * @param receiver The SLOT's parent. - * @param slot The TQT_SLOT to invoke to execute this action. - * @param parent This action's parent. - * @param name An internal name for this action. - */ - TDEToolBarLabelAction(TQLabel* label, const TDEShortcut &cut, - const TQObject *receiver, const char *slot, - TDEActionCollection* parent, const char *name); - - virtual ~TDEToolBarLabelAction(); - /** - * Reimplemented to update both the action's text and the label's text. - */ - virtual void setText(const TQString& text); - /** - * Sets the label's buddy to buddy. - * - * See QLabel#setBuddy() for details. - */ - virtual void setBuddy(TQWidget* buddy); - /** - * Returns the label's buddy or 0 if no buddy is currently set. - * - * See QLabel#buddy() and QLabel#setBuddy() for more information. - */ - TQWidget* buddy() const; - /** - * Returns the label which is used internally. - */ - TQLabel* label() const; - -protected: - virtual void virtual_hook(int id, void* data); - -private: - class TDEToolBarLabelActionPrivate; - TDEToolBarLabelActionPrivate *d; - void init(); -}; - - -#endif diff --git a/tdeui/ktoolbarradiogroup.cpp b/tdeui/ktoolbarradiogroup.cpp deleted file mode 100644 index 7526158b9..000000000 --- a/tdeui/ktoolbarradiogroup.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) - (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) - (C) 1997, 1998 Sven Radej (radej@kde.org) - (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) - (C) 1999 Chris Schlaeger (cs@kde.org) - - 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. -*/ - -#include - -#include "ktoolbarradiogroup.h" -#include "ktoolbar.h" -#include "ktoolbarbutton.h" - -/************************************************************************* - * TDEToolBarRadioGroup * - *************************************************************************/ - - -TDEToolBarRadioGroup::TDEToolBarRadioGroup (TDEToolBar *_parent, const char *_name) -: TQObject(_parent, _name) -{ - buttons = new TDEToolBarButtonList(); - tb = _parent; - connect (tb, TQT_SIGNAL(toggled(int)), this, TQT_SLOT(slotToggled(int))); -} - -TDEToolBarRadioGroup::~TDEToolBarRadioGroup() -{ - delete buttons; -} - -void TDEToolBarRadioGroup::addButton (int id) -{ - TDEToolBarButton *b = tb->getButton( id ); - b->setRadio( true ); - buttons->insert( id, b ); -} - -void TDEToolBarRadioGroup::removeButton (int id) -{ - if (!buttons->find(id)) - return; - buttons->find(id)->setRadio(false); - buttons->remove(id); -} - -void TDEToolBarRadioGroup::slotToggled(int id) -{ - if (buttons->find(id) && buttons->find(id)->isOn()) - { - TQIntDictIterator it(*buttons); - while (it.current()) - { - if (it.currentKey() != id) - it.current()->on(false); - ++it; - } - } -} - -#include "ktoolbarradiogroup.moc" - diff --git a/tdeui/ktoolbarradiogroup.h b/tdeui/ktoolbarradiogroup.h deleted file mode 100644 index de567ae62..000000000 --- a/tdeui/ktoolbarradiogroup.h +++ /dev/null @@ -1,88 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) - (C) 1997, 1998 Sven Radej (radej@kde.org) - (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) - (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) - - 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 _KTOOLBARRADIOGROUP_H -#define _KTOOLBARRADIOGROUP_H - -#include - -#include - -class TDEToolBar; -class TDEToolBarButtonList; -class TDEToolBarRadioGroupPrivate; - -/************************************************************************* - * TDEToolBarRadioGroup * - *************************************************************************/ - /** - * @short Class for group of radio butons in toolbar. - * - * TDEToolBarRadioGroup is class for group of radio butons in toolbar. - * Take toggle buttons which you already inserted into toolbar, - * create TDEToolBarRadioGroup instance and add them here. - * All buttons will emit signals toggled (bool) (or you can - * use sitgnal toggled (int id) from toolbar). When one button is set - * down, all others are unset. All buttons emit signals - those who - * "go down" and those who "go up". - * - * @author Sven Radej - */ -class TDEUI_EXPORT TDEToolBarRadioGroup : public TQObject -{ - Q_OBJECT - -public: - /** - * Constructor. Parent must be TDEToolBar . - */ - TDEToolBarRadioGroup (TDEToolBar *_parent, const char *_name=0); - /** - * Destructor. - */ - ~TDEToolBarRadioGroup (); - - /** - * Adds button to group. Button cannot be unset by mouse clicks (you - * must press some other button tounset this one) - */ - void addButton (int id); - - /** - * Removes button from group, making it again toggle button (i.e. - * You can unset it with mouse). - */ - void removeButton (int id); - -public slots: - /** - * Internal - nothing for you here. - */ - void slotToggled (int); - -private: - TDEToolBarButtonList *buttons; - TDEToolBar *tb; - - TDEToolBarRadioGroupPrivate *d; -}; - -#endif diff --git a/tdeui/tdeaccelgen.h b/tdeui/tdeaccelgen.h new file mode 100644 index 000000000..d1e761876 --- /dev/null +++ b/tdeui/tdeaccelgen.h @@ -0,0 +1,280 @@ +/* This file is part of the KDE project + Copyright (C) 2000 Keunwoo Lee + + 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. + + This program 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 KACCELGEN_H +#define KACCELGEN_H + +#include +#include +#include + +#include + +/** + * Provides functions that, given a collection of QStrings, will + * automatically and intelligently assign menu accelerators to the + * QStrings in the collection. + * + * NOTE: When this file speaks of "accelerators", we really mean + * accelerators as defined by the KDE User Interface Guidelines. We + * do NOT mean "shortcuts", which are what's handled by most other KDE + * libraries with "accel" in the name. + * + * In the Qt library, the mechanism for adding a keyboard accelerator + * to a menu item is to insert an '&' before the letter. Since we + * usually don't want to disturb the original collection, the idiom in + * these functions is to populate a "target" TQStringList parameter + * with the input collectin's QStrings, plus possibly some added '&' + * characters. + * + * That is the mechanism. Here is the policy, in order of decreasing + * importance (it may seem like these are implementation details, but + * IMHO the policy is an important part of the interface): + * + * 1. If the string already contains an '&' character, skip this + * string, because we consider such strings to be "user-specified" + * accelerators. + * + * 2. No accelerator may clash with a previously defined accelerator, + * including any legal (alphanumeric) user-specified accelerator + * anywhere in the collection + * + * 3. Prefer alphanumerics at the start of the string. + * + * 4. Otherwise, prefer alphanumerics at the start of a word. + * + * 5. Otherwise, choose any alphanumeric character not already + * taken. If no such character is available, give up & skip this + * string. + * + * A typical use of these functions would be to automatically assign + * accelerators to a dynamically populated popup menu. For example, + * the core code was written to automatically set accelerators for the + * "Load View Profile" popup menu for Konqueror. We quickly realized + * that it would be useful to make this facility more generally + * available, so I abstracted it out into a set of templates. + * + * TODO: + * + * + Add sugar functions for more collections. + * + * + Add more Deref classes so that we can access a wider variety of + * collections. + * */ +namespace TDEAccelGen +{ + +// HELPERS + +/** + * Static dereference class, for use as a template parameter. + */ +template +class Deref +{ +public: + static TQString deref(Iter i) { return *i; } +}; + +/** + * Static dereference class that calls the key() method on its + * target; for use as a template parameter. + */ +template +class Deref_Key +{ +public: + static TQString deref(Iter i) { return i.key(); } +}; + +/** + * Helper to determine if the given offset in the string could be a + * legal alphanumeric accelerator. + * + * @param str base string + * @param index offset to check + */ +inline bool +isLegalAccelerator(const TQString& str, uint index) +{ + return index < str.length() + && str[index].isLetterOrNumber(); +} + +/** + * Loads all legal predefined accelerators in the (implicitly + * specified) collection into the given TQMap. + * + * @param begin start iterator + * @param end (last+1) iterator + * @param keys map to store output + */ +template +inline void +loadPredefined(Iter begin, Iter end, TQMap& keys) +{ + for (Iter i = begin; i != end; ++i) { + TQString item = Deref::deref(i); + int user_ampersand = item.find(TQChar('&')); + if( user_ampersand >= 0 ) { + // Sanity check. Note that we don't try to find an + // accelerator if the user shoots him/herself in the foot + // by adding a bad '&'. + if( isLegalAccelerator(item, user_ampersand+1) ) { + keys.insert(item[user_ampersand+1], true); + } + } + } +} + + +// /////////////////////////////////////////////////////////////////// +// MAIN USER FUNCTIONS + + +/** + * Main, maximally flexible template function that assigns + * accelerators to the elements of a collection of QStrings. Clients + * will seldom use this directly, as it's usually easier to use one of + * the wrapper functions that simply takes a collection (see below). + * + * The Deref template parameter is a class containing a static + * dereferencing function, modeled after the comparison class C in + * Stroustrup 13.4. + * + * @param begin (you know) + * @param end (you know) + * @param target collection to store generated strings + */ +template +void +generate(Iter begin, Iter end, TQStringList& target) +{ + // Will keep track of used accelerator chars + TQMap used_accels; + + // Prepass to detect manually user-coded accelerators + loadPredefined(begin, end, used_accels); + + // Main pass + for (Iter i = begin; i != end; ++i) { + TQString item = Iter_Deref::deref(i); + + // Attempt to find a good accelerator, but only if the user + // has not manually hardcoded one. + int user_ampersand = item.find(TQChar('&')); + if( user_ampersand < 0 || item[user_ampersand+1] == '&') { + bool found = false; + uint found_idx; + uint j; + + // Check word-starting letters first. + for( j=0; j < item.length(); ++j ) { + if( isLegalAccelerator(item, j) + && !used_accels.contains(item[j]) + && (0 == j || (j > 0 && item[j-1].isSpace())) ) { + found = true; + found_idx = j; + break; + } + } + + if( !found ) { + // No word-starting letter; search for any letter. + for( j=0; j < item.length(); ++j ) { + if( isLegalAccelerator(item, j) + && !used_accels.contains(item[j]) ) { + found = true; + found_idx = j; + break; + } + } + } + + if( found ) { + // Both upper and lower case marked as used + used_accels.insert(item[j].upper(),true); + used_accels.insert(item[j].lower(),true); + item.insert(j,TQChar('&')); + } + } + + target.append( item ); + } +} + +/** + * Another convenience function; looks up the key instead of + * dereferencing directly for the given iterator. + * + * @param begin + * @param end + * @param target + */ +template +inline void +generateFromKeys(Iter begin, Iter end, TQStringList& target) +{ + generate< Iter, Deref_Key >(begin, end, target); +} + + +/** + * Convenience function; generates accelerators for all the items in + * a TQStringList. + * + * @param source Strings for which to generate accelerators + * @param target Output for accelerator-added strings */ +inline void +generate(const TQStringList& source, TQStringList& target) +{ + generate >(source.begin(), source.end(), target); +} + +/** + * Convenience function; generates accelerators for all the values in + * a TQMap. + * + * @param source Map with input strings as VALUES. + * @param target Output for accelerator-added strings */ +template +inline void +generateFromValues(const TQMap& source, TQStringList& target) +{ + generate, Deref_Key > >(source.begin(), source.end(), target); +} + +/** + * Convenience function; generates an accelerator mapping from all the + * keys in a TQMap + * + * @param source Map with input strings as KEYS. + * @param target Output for accelerator-added strings */ +template +inline void +generateFromKeys(const TQMap& source, TQStringList& target) +{ + generateFromKeys(source.begin(), source.end(), target); +} + + +} // end namespace TDEAccelGen + +#endif + diff --git a/tdeui/tdeaction.cpp b/tdeui/tdeaction.cpp new file mode 100644 index 000000000..24a940c2f --- /dev/null +++ b/tdeui/tdeaction.cpp @@ -0,0 +1,1288 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999 Reginald Stadlbauer + (C) 1999 Simon Hausmann + (C) 2000 Nicolas Hadacek + (C) 2000 Kurt Granroth + (C) 2000 Michael Koch + (C) 2001 Holger Freyther + (C) 2002 Ellis Whitehead + (C) 2002 Joseph Wenninger + + 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. +*/ + +#include "kaction.h" + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +/** +* How it works. +* TDEActionCollection is an organizing container for TDEActions. +* TDEActionCollection keeps track of the information necessary to handle +* configuration and shortcuts. +* +* Focus Widget pointer: +* This is the widget which is the focus for action shortcuts. +* It is set either by passing a TQWidget* to the TDEActionCollection constructor +* or by calling setWidget() if the widget wasn't known when the object was +* initially constructed (as in KXMLGUIClient and KParts::PartBase) +* +* Shortcuts: +* An action's shortcut will not not be connected unless a focus widget has +* been specified in TDEActionCollection. +* +* XML Filename: +* This is used to save user-modified settings back to the *ui.rc file. +* It is set by KXMLGUIFactory. +*/ + +int TDEAction::getToolButtonID() +{ + static int toolbutton_no = -2; + return toolbutton_no--; +} + +//--------------------------------------------------------------------- +// TDEAction::TDEActionPrivate +//--------------------------------------------------------------------- + +class TDEAction::TDEActionPrivate : public KGuiItem +{ +public: + TDEActionPrivate() : KGuiItem() + { + m_kaccel = 0; + m_configurable = true; + } + + TDEAccel *m_kaccel; + TQValueList m_kaccelList; + + TQString m_groupText; + TQString m_group; + + TDEShortcut m_cut; + TDEShortcut m_cutDefault; + + bool m_configurable; + + struct Container + { + Container() { m_container = 0; m_representative = 0; m_id = 0; } + Container( const Container& s ) { m_container = s.m_container; + m_id = s.m_id; m_representative = s.m_representative; } + TQWidget* m_container; + int m_id; + TQWidget* m_representative; + }; + + TQValueList m_containers; +}; + +//--------------------------------------------------------------------- +// TDEAction +//--------------------------------------------------------------------- + +TDEAction::TDEAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TDEActionCollection* parent, const char* name ) +: TQObject( parent, name ), d(new TDEActionPrivate) +{ + initPrivate( text, cut, receiver, slot ); +} + +TDEAction::TDEAction( const TQString& text, const TQString& sIconName, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TDEActionCollection* parent, const char* name ) +: TQObject( parent, name ), d(new TDEActionPrivate) +{ + initPrivate( text, cut, receiver, slot ); + d->setIconName( sIconName ); +} + +TDEAction::TDEAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TDEActionCollection* parent, const char* name ) +: TQObject( parent, name ), d(new TDEActionPrivate) +{ + initPrivate( text, cut, receiver, slot ); + d->setIconSet( pix ); +} + +TDEAction::TDEAction( const KGuiItem& item, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TDEActionCollection* parent, const char* name ) +: TQObject( parent, name ), d(new TDEActionPrivate) +{ + initPrivate( item.text(), cut, receiver, slot ); + if( item.hasIcon() ) + setIcon( item.iconName() ); + setToolTip( item.toolTip() ); + setWhatsThis( item.whatsThis() ); +} + +#ifndef KDE_NO_COMPAT // KDE 4: remove +TDEAction::TDEAction( const TQString& text, const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TQObject( parent, name ), d(new TDEActionPrivate) +{ + initPrivate( text, cut, 0, 0 ); +} + +TDEAction::TDEAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, TQObject* parent, const char* name ) + : TQObject( parent, name ), d(new TDEActionPrivate) +{ + initPrivate( text, cut, receiver, slot ); +} + +TDEAction::TDEAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TQObject( parent, name ), d(new TDEActionPrivate) +{ + initPrivate( text, cut, 0, 0 ); + setIconSet( pix ); +} + +TDEAction::TDEAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) +: TQObject( parent, name ), d(new TDEActionPrivate) +{ + initPrivate( text, cut, 0, 0 ); + d->setIconName( pix ); +} + +TDEAction::TDEAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, + const char* name ) + : TQObject( parent, name ), d(new TDEActionPrivate) +{ + initPrivate( text, cut, receiver, slot ); + setIconSet( pix ); +} + +TDEAction::TDEAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, + const char* name ) + : TQObject( parent, name ), d(new TDEActionPrivate) +{ + initPrivate( text, cut, receiver, slot ); + d->setIconName(pix); +} + +TDEAction::TDEAction( TQObject* parent, const char* name ) + : TQObject( parent, name ), d(new TDEActionPrivate) +{ + initPrivate( TQString::null, TDEShortcut(), 0, 0 ); +} +#endif // KDE 4: remove end + +TDEAction::~TDEAction() +{ + kdDebug(129) << "TDEAction::~TDEAction( this = \"" << name() << "\" )" << endl; // -- ellis +#ifndef KDE_NO_COMPAT + if (d->m_kaccel) + unplugAccel(); +#endif + + // If actionCollection hasn't already been destructed, + if ( m_parentCollection ) { + m_parentCollection->take( this ); + + const TQValueList & accelList = d->m_kaccelList; + TQValueList::const_iterator itr = accelList.constBegin(); + const TQValueList::const_iterator itrEnd = accelList.constEnd(); + + const char * const namePtr = name(); + for (; itr != itrEnd; ++itr ) + (*itr)->remove(namePtr); + + } + + // Do not call unplugAll from here, as tempting as it sounds. + // TDEAction is designed around the idea that you need to plug + // _and_ to unplug it "manually". Unplugging leads to an important + // slowdown when e.g. closing the window, in which case we simply + // want to destroy everything asap, not to remove actions one by one + // from the GUI. + + delete d; +} + +void TDEAction::initPrivate( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot ) +{ + d->m_cutDefault = cut; + + m_parentCollection = tqt_dynamic_cast( parent() ); + kdDebug(129) << "TDEAction::initPrivate(): this = " << this << " name = \"" << name() << "\" cut = " << cut.toStringInternal() << " m_parentCollection = " << m_parentCollection << endl; + if ( m_parentCollection ) + m_parentCollection->insert( this ); + + if ( receiver && slot ) + connect( this, TQT_SIGNAL( activated() ), receiver, slot ); + + if( !cut.isNull() && !qstrcmp( name(), "unnamed" ) ) + kdWarning(129) << "TDEAction::initPrivate(): trying to assign a shortcut (" << cut.toStringInternal() << ") to an unnamed action." << endl; + d->setText( text ); + initShortcut( cut ); +} + +bool TDEAction::isPlugged() const +{ + return (!d->m_containers.empty()) || d->m_kaccel; +} + +bool TDEAction::isPlugged( const TQWidget *container ) const +{ + return findContainer( container ) > -1; +} + +bool TDEAction::isPlugged( const TQWidget *container, int id ) const +{ + int i = findContainer( container ); + return ( i > -1 && itemId( i ) == id ); +} + +bool TDEAction::isPlugged( const TQWidget *container, const TQWidget *_representative ) const +{ + int i = findContainer( container ); + return ( i > -1 && representative( i ) == _representative ); +} + + +/* +Three actionCollection conditions: + 1) Scope is known on creation and TDEAccel object is created (e.g. TDEMainWindow) + 2) Scope is unknown and no TDEAccel object is available (e.g. KXMLGUIClient) + a) addClient() will be called on object + b) we just want to add the actions to another KXMLGUIClient object + +The question is how to do we incorporate #2b into the XMLGUI framework? + + +We have a KCommandHistory object with undo and redo actions in a passed actionCollection +We have a KoDoc object which holds a KCommandHistory object and the actionCollection +We have two KoView objects which both point to the same KoDoc object +Undo and Redo should be available in both KoView objects, and + calling the undo->setEnabled() should affect both KoViews + +When addClient is called, it needs to be able to find the undo and redo actions +When it calls plug() on them, they need to be inserted into the TDEAccel object of the appropriate KoView + +In this case, the actionCollection belongs to KoDoc and we need to let it know that its shortcuts +have the same scope as the KoView actionCollection + +KXMLGUIClient::addSubActionCollection + +Document: + create document actions + +View + create view actions + add document actionCollection as sub-collection + +A parentCollection is created +Scenario 1: parentCollection has a focus widget set (e.g. via TDEMainWindow) + A TDEAccel object is created in the parentCollection + A TDEAction is created with parent=parentCollection + The shortcut is inserted into this actionCollection + Scenario 1a: xml isn't used + done + Scenario 1b: KXMLGUIBuilder::addClient() called + setWidget is called -- ignore + shortcuts are set +Scenario 2: parentCollection has no focus widget (e.g., KParts) + A TDEAction is created with parent=parentCollection + Scenario 2a: xml isn't used + no shortcuts + Scenario 2b: KXMLGUIBuilder::addClient() called + setWidget is called + shortcuts are inserted into current TDEAccel + shortcuts are set in all other TDEAccels, if the action is present in the other TDEAccels +*/ + +/* +shortcut may be set: + - on construction + - on plug + - on reading XML + - on plugAccel (deprecated) + +On Construction: [via initShortcut()] + insert into TDEAccel of m_parentCollection, + if kaccel() && isAutoConnectShortcuts() exists + +On Plug: [via plug() -> plugShortcut()] + insert into TDEAccel of m_parentCollection, if exists and not already inserted into + +On Read XML: [via setShortcut()] + set in all current TDEAccels + insert into TDEAccel of m_parentCollection, if exists and not already inserted into +*/ + +TDEAccel* TDEAction::kaccelCurrent() +{ + if( m_parentCollection && m_parentCollection->builderTDEAccel() ) + return m_parentCollection->builderTDEAccel(); + else if( m_parentCollection && m_parentCollection->kaccel() ) + return m_parentCollection->kaccel(); + else + return 0L; +} + +// Only to be called from initPrivate() +bool TDEAction::initShortcut( const TDEShortcut& cut ) +{ + d->m_cut = cut; + + // Only insert action into TDEAccel if it has a valid name, + if( qstrcmp( name(), "unnamed" ) && + m_parentCollection && + m_parentCollection->isAutoConnectShortcuts() && + m_parentCollection->kaccel() ) + { + insertTDEAccel( m_parentCollection->kaccel() ); + return true; + } + return false; + } + +// Only to be called from plug() +void TDEAction::plugShortcut() +{ + TDEAccel* const kaccel = kaccelCurrent(); + + //kdDebug(129) << "TDEAction::plugShortcut(): this = " << this << " kaccel() = " << (m_parentCollection ? m_parentCollection->kaccel() : 0) << endl; + if( kaccel && qstrcmp( name(), "unnamed" ) ) { + // Check if already plugged into current TDEAccel object + const TQValueList & accelList = d->m_kaccelList; + TQValueList::const_iterator itr = accelList.constBegin(); + const TQValueList::const_iterator itrEnd = accelList.constEnd(); + + for( ; itr != itrEnd; ++itr) { + if( (*itr) == kaccel ) + return; + } + + insertTDEAccel( kaccel ); + } +} + +bool TDEAction::setShortcut( const TDEShortcut& cut ) +{ + bool bChanged = (d->m_cut != cut); + d->m_cut = cut; + + TDEAccel* const kaccel = kaccelCurrent(); + bool bInsertRequired = true; + // Apply new shortcut to all existing TDEAccel objects + + const TQValueList & accelList = d->m_kaccelList; + TQValueList::const_iterator itr = accelList.constBegin(); + const TQValueList::const_iterator itrEnd = accelList.constEnd(); + + for( ; itr != itrEnd; ++itr) { + // Check whether shortcut has already been plugged into + // the current kaccel object. + if( (*itr) == kaccel ) + bInsertRequired = false; + if( bChanged ) + updateTDEAccelShortcut( *itr ); + } + + // Only insert action into TDEAccel if it has a valid name, + if( kaccel && bInsertRequired && qstrcmp( name(), "unnamed" ) ) + insertTDEAccel( kaccel ); + + if( bChanged ) { +#ifndef KDE_NO_COMPAT // KDE 4: remove + if ( d->m_kaccel ) + d->m_kaccel->setShortcut( name(), cut ); +#endif // KDE 4: remove end + int len = containerCount(); + for( int i = 0; i < len; ++i ) + updateShortcut( i ); + } + return true; +} + +bool TDEAction::updateTDEAccelShortcut( TDEAccel* kaccel ) +{ + // Check if action is permitted + if (kapp && !kapp->authorizeTDEAction(name())) + return false; + + bool b = true; + + if ( !kaccel->actions().actionPtr( name() ) ) { + if(!d->m_cut.isNull() ) { + kdDebug(129) << "Inserting " << name() << ", " << d->text() << ", " << d->plainText() << endl; + b = kaccel->insert( name(), d->plainText(), TQString::null, + d->m_cut, + this, TQT_SLOT(slotActivated()), + isShortcutConfigurable(), isEnabled() ); + } + } + else + b = kaccel->setShortcut( name(), d->m_cut ); + + return b; +} + +void TDEAction::insertTDEAccel( TDEAccel* kaccel ) +{ + //kdDebug(129) << "TDEAction::insertTDEAccel( " << kaccel << " ): this = " << this << endl; + if ( !kaccel->actions().actionPtr( name() ) ) { + if( updateTDEAccelShortcut( kaccel ) ) { + d->m_kaccelList.append( kaccel ); + connect( kaccel, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotDestroyed()) ); + } + } + else + kdWarning(129) << "TDEAction::insertTDEAccel( kaccel = " << kaccel << " ): TDEAccel object already contains an action name \"" << name() << "\"" << endl; // -- ellis +} + +void TDEAction::removeTDEAccel( TDEAccel* kaccel ) +{ + //kdDebug(129) << "TDEAction::removeTDEAccel( " << i << " ): this = " << this << endl; + TQValueList & accelList = d->m_kaccelList; + TQValueList::iterator itr = accelList.begin(); + const TQValueList::iterator itrEnd = accelList.end(); + + for( ; itr != itrEnd; ++itr) { + if( (*itr) == kaccel ) { + kaccel->remove( name() ); + accelList.remove( itr ); + disconnect( kaccel, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotDestroyed()) ); + break; + } + } +} + +#ifndef KDE_NO_COMPAT +// KDE 4: remove +void TDEAction::setAccel( int keyQt ) +{ + setShortcut( TDEShortcut(keyQt) ); +} +#endif // KDE 4: remove end + +void TDEAction::updateShortcut( int i ) +{ + int id = itemId( i ); + + TQWidget* w = container( i ); + if ( ::tqqt_cast( w ) ) { + TQPopupMenu* menu = static_cast(w); + updateShortcut( menu, id ); + } + else if ( ::tqqt_cast( w ) ) + static_cast(w)->setAccel( d->m_cut.keyCodeQt(), id ); +} + +void TDEAction::updateShortcut( TQPopupMenu* menu, int id ) +{ + //kdDebug(129) << "TDEAction::updateShortcut(): this = " << this << " d->m_kaccelList.count() = " << d->m_kaccelList.count() << endl; + // If the action has a TDEAccel object, + // show the string representation of its shortcut. + if ( d->m_kaccel || d->m_kaccelList.count() ) { + TQString s = menu->text( id ); + int i = s.find( '\t' ); + if ( i >= 0 ) + s.replace( i+1, s.length()-i, d->m_cut.seq(0).toString() ); + else + s += "\t" + d->m_cut.seq(0).toString(); + + menu->changeItem( id, s ); + } + // Otherwise insert the shortcut itself into the popup menu. + else { + // This is a fall-hack in case the TDEAction is missing a proper parent collection. + // It should be removed eventually. --ellis + menu->setAccel( d->m_cut.keyCodeQt(), id ); + kdDebug(129) << "TDEAction::updateShortcut(): name = \"" << name() << "\", cut = " << d->m_cut.toStringInternal() << "; No TDEAccel, probably missing a parent collection." << endl; + } +} + +const TDEShortcut& TDEAction::shortcut() const +{ + return d->m_cut; +} + +const TDEShortcut& TDEAction::shortcutDefault() const +{ + return d->m_cutDefault; +} + +TQString TDEAction::shortcutText() const +{ + return d->m_cut.toStringInternal(); +} + +void TDEAction::setShortcutText( const TQString& s ) +{ + setShortcut( TDEShortcut(s) ); +} + +#ifndef KDE_NO_COMPAT // Remove in KDE 4 +int TDEAction::accel() const +{ + return d->m_cut.keyCodeQt(); +} +#endif + +void TDEAction::setGroup( const TQString& grp ) +{ + d->m_group = grp; + + int len = containerCount(); + for( int i = 0; i < len; ++i ) + updateGroup( i ); +} + +void TDEAction::updateGroup( int ) +{ + // DO SOMETHING +} + +TQString TDEAction::group() const +{ + return d->m_group; +} + +bool TDEAction::isEnabled() const +{ + return d->isEnabled(); +} + +bool TDEAction::isShortcutConfigurable() const +{ + return d->m_configurable; +} + +void TDEAction::setToolTip( const TQString& tt ) +{ + d->setToolTip( tt ); + + int len = containerCount(); + for( int i = 0; i < len; ++i ) + updateToolTip( i ); +} + +void TDEAction::updateToolTip( int i ) +{ + TQWidget *w = container( i ); + + if ( ::tqqt_cast( w ) ) + TQToolTip::add( static_cast(w)->getWidget( itemId( i ) ), d->toolTip() ); +} + +TQString TDEAction::toolTip() const +{ + return d->toolTip(); +} + +int TDEAction::plug( TQWidget *w, int index ) +{ + //kdDebug(129) << "TDEAction::plug( " << w << ", " << index << " )" << endl; + if (!w ) { + kdWarning(129) << "TDEAction::plug called with 0 argument\n"; + return -1; + } + + // Ellis: print warning if there is a shortcut, but no TDEAccel available (often due to no widget available in the actioncollection) + // David: Well, it doesn't matter much, things still work (e.g. Undo in koffice) via TQAccel. + // We should probably re-enable the warning for things that only TDEAccel can do, though - e.g. WIN key (mapped to Meta). +#if 0 //ndef NDEBUG + TDEAccel* kaccel = kaccelCurrent(); + if( !d->m_cut.isNull() && !kaccel ) { + kdDebug(129) << "TDEAction::plug(): has no TDEAccel object; this = " << this << " name = " << name() << " parentCollection = " << m_parentCollection << endl; // ellis + } +#endif + + // Check if action is permitted + if (kapp && !kapp->authorizeTDEAction(name())) + return -1; + + plugShortcut(); + + if ( ::tqqt_cast( w ) ) + { + TQPopupMenu* menu = static_cast( w ); + int id; + // Don't insert shortcut into menu if it's already in a TDEAccel object. + int keyQt = (d->m_kaccelList.count() || d->m_kaccel) ? 0 : d->m_cut.keyCodeQt(); + + if ( d->hasIcon() ) + { + TDEInstance *instance; + if ( m_parentCollection ) + instance = m_parentCollection->instance(); + else + instance = TDEGlobal::instance(); + id = menu->insertItem( d->iconSet( KIcon::Small, 0, instance ), d->text(), this,//dsweet + TQT_SLOT( slotPopupActivated() ), keyQt, + -1, index ); + } + else + id = menu->insertItem( d->text(), this, + TQT_SLOT( slotPopupActivated() ), + keyQt, -1, index ); + + // If the shortcut is already in a TDEAccel object, then + // we need to set the menu item's shortcut text. + if ( d->m_kaccelList.count() || d->m_kaccel ) + updateShortcut( menu, id ); + + // call setItemEnabled only if the item really should be disabled, + // because that method is slow and the item is per default enabled + if ( !d->isEnabled() ) + menu->setItemEnabled( id, false ); + + if ( !d->whatsThis().isEmpty() ) + menu->TQMenuData::setWhatsThis( id, whatsThisWithIcon() ); + + addContainer( menu, id ); + connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + if ( m_parentCollection ) + m_parentCollection->connectHighlight( menu, this ); + + return d->m_containers.count() - 1; + } + else if ( ::tqqt_cast( w ) ) + { + TDEToolBar *bar = static_cast( w ); + + int id_ = getToolButtonID(); + TDEInstance *instance; + if ( m_parentCollection ) + instance = m_parentCollection->instance(); + else + instance = TDEGlobal::instance(); + + if ( icon().isEmpty() && !iconSet().pixmap().isNull() ) // old code using TQIconSet directly + { + bar->insertButton( iconSet().pixmap(), id_, TQT_SIGNAL( buttonClicked(int, TQt::ButtonState) ), this, + TQT_SLOT( slotButtonClicked(int, TQt::ButtonState) ), + d->isEnabled(), d->plainText(), index ); + } + else + { + TQString icon = d->iconName(); + if ( icon.isEmpty() ) + icon = "unknown"; + bar->insertButton( icon, id_, TQT_SIGNAL( buttonClicked(int, TQt::ButtonState) ), this, + TQT_SLOT( slotButtonClicked(int, TQt::ButtonState) ), + d->isEnabled(), d->plainText(), index, instance ); + } + + TDEToolBarButton* ktb = bar->getButton(id_); + ktb->setName( TQCString("toolbutton_")+name() ); + + if ( !d->whatsThis().isEmpty() ) + TQWhatsThis::add( bar->getButton(id_), whatsThisWithIcon() ); + + if ( !d->toolTip().isEmpty() ) + TQToolTip::add( bar->getButton(id_), d->toolTip() ); + + addContainer( bar, id_ ); + + connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + if ( m_parentCollection ) + m_parentCollection->connectHighlight( bar, this ); + + return containerCount() - 1; + } + + return -1; +} + +void TDEAction::unplug( TQWidget *w ) +{ + int i = findContainer( w ); + if ( i == -1 ) + return; + int id = itemId( i ); + + if ( ::tqqt_cast( w ) ) + { + TQPopupMenu *menu = static_cast( w ); + menu->removeItem( id ); + } + else if ( ::tqqt_cast( w ) ) + { + TDEToolBar *bar = static_cast( w ); + bar->removeItemDelayed( id ); + } + else if ( ::tqqt_cast( w ) ) + { + TQMenuBar *bar = static_cast( w ); + bar->removeItem( id ); + } + + removeContainer( i ); + if ( m_parentCollection ) + m_parentCollection->disconnectHighlight( w, this ); +} + +void TDEAction::plugAccel(TDEAccel *kacc, bool configurable) +{ + kdWarning(129) << "TDEAction::plugAccel(): call to deprecated action." << endl; + kdDebug(129) << kdBacktrace() << endl; + //kdDebug(129) << "TDEAction::plugAccel( kacc = " << kacc << " ): name \"" << name() << "\"" << endl; + if ( d->m_kaccel ) + unplugAccel(); + + // If the parent collection's accel ptr isn't set yet + //if ( m_parentCollection && !m_parentCollection->accel() ) + // m_parentCollection->setAccel( kacc ); + + // We can only plug this action into the given TDEAccel object + // if it does not already contain an action with the same name. + if ( !kacc->actions().actionPtr(name()) ) + { + d->m_kaccel = kacc; + d->m_kaccel->insert(name(), d->plainText(), TQString::null, + TDEShortcut(d->m_cut), + this, TQT_SLOT(slotActivated()), + configurable, isEnabled()); + connect(d->m_kaccel, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotDestroyed())); + //connect(d->m_kaccel, TQT_SIGNAL(keycodeChanged()), this, TQT_SLOT(slotKeycodeChanged())); + } + else + kdWarning(129) << "TDEAction::plugAccel( kacc = " << kacc << " ): TDEAccel object already contains an action name \"" << name() << "\"" << endl; // -- ellis +} + +void TDEAction::unplugAccel() +{ + //kdDebug(129) << "TDEAction::unplugAccel() " << this << " " << name() << endl; + if ( d->m_kaccel ) + { + d->m_kaccel->remove(name()); + d->m_kaccel = 0; + } +} + +void TDEAction::plugMainWindowAccel( TQWidget *w ) +{ + // Note: topLevelWidget() stops too early, we can't use it. + TQWidget * tl = w; + TQWidget * n; + while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store + tl = n; + + TDEMainWindow * mw = tqt_dynamic_cast(tl); // try to see if it's a kmainwindow + if (mw) + plugAccel( mw->accel() ); + else + kdDebug(129) << "TDEAction::plugMainWindowAccel: Toplevel widget isn't a TDEMainWindow, can't plug accel. " << tl << endl; +} + +void TDEAction::setEnabled(bool enable) +{ + //kdDebug(129) << "TDEAction::setEnabled( " << enable << " ): this = " << this << " d->m_kaccelList.count() = " << d->m_kaccelList.count() << endl; + if ( enable == d->isEnabled() ) + return; + +#ifndef KDE_NO_COMPAT + // KDE 4: remove + if (d->m_kaccel) + d->m_kaccel->setEnabled(name(), enable); +#endif // KDE 4: remove end + + const TQValueList & accelList = d->m_kaccelList; + TQValueList::const_iterator itr = accelList.constBegin(); + const TQValueList::const_iterator itrEnd = accelList.constEnd(); + + const char * const namePtr = name(); + + for ( ; itr != itrEnd; ++itr ) + (*itr)->setEnabled( namePtr, enable ); + + d->setEnabled( enable ); + + int len = containerCount(); + for( int i = 0; i < len; ++i ) + updateEnabled( i ); + + emit enabled( d->isEnabled() ); +} + +void TDEAction::updateEnabled( int i ) +{ + TQWidget *w = container( i ); + + if ( ::tqqt_cast( w ) ) + static_cast(w)->setItemEnabled( itemId( i ), d->isEnabled() ); + else if ( ::tqqt_cast( w ) ) + static_cast(w)->setItemEnabled( itemId( i ), d->isEnabled() ); + else if ( ::tqqt_cast( w ) ) + static_cast(w)->setItemEnabled( itemId( i ), d->isEnabled() ); +} + +void TDEAction::setShortcutConfigurable( bool b ) +{ + d->m_configurable = b; +} + +void TDEAction::setText( const TQString& text ) +{ +#ifndef KDE_NO_COMPAT + // KDE 4: remove + if (d->m_kaccel) { + TDEAccelAction* pAction = d->m_kaccel->actions().actionPtr(name()); + if (pAction) + pAction->setLabel( text ); + } +#endif // KDE 4: remove end + const TQValueList & accelList = d->m_kaccelList; + TQValueList::const_iterator itr = accelList.constBegin(); + const TQValueList::const_iterator itrEnd = accelList.constEnd(); + + const char * const namePtr = name(); + + for( ; itr != itrEnd; ++itr ) { + TDEAccelAction* const pAction = (*itr)->actions().actionPtr(namePtr); + if (pAction) + pAction->setLabel( text ); + } + + d->setText( text ); + + int len = containerCount(); + for( int i = 0; i < len; ++i ) + updateText( i ); +} + +void TDEAction::updateText( int i ) +{ + TQWidget *w = container( i ); + + if ( ::tqqt_cast( w ) ) { + int id = itemId( i ); + static_cast(w)->changeItem( id, d->text() ); + if (!d->m_cut.isNull()) + updateShortcut( static_cast(w), id ); + } + else if ( ::tqqt_cast( w ) ) + static_cast(w)->changeItem( itemId( i ), d->text() ); + else if ( ::tqqt_cast( w ) ) + { + TQWidget *button = static_cast(w)->getWidget( itemId( i ) ); + if ( ::tqqt_cast( button ) ) + static_cast(button)->setText( d->plainText() ); + } +} + +TQString TDEAction::text() const +{ + return d->text(); +} + +TQString TDEAction::plainText() const +{ + return d->plainText( ); +} + +void TDEAction::setIcon( const TQString &icon ) +{ + d->setIconName( icon ); + + // now handle any toolbars + int len = containerCount(); + for ( int i = 0; i < len; ++i ) + updateIcon( i ); +} + +void TDEAction::updateIcon( int id ) +{ + TQWidget* w = container( id ); + + if ( ::tqqt_cast( w ) ) { + int itemId_ = itemId( id ); + static_cast(w)->changeItem( itemId_, d->iconSet( KIcon::Small ), d->text() ); + if (!d->m_cut.isNull()) + updateShortcut( static_cast(w), itemId_ ); + } + else if ( ::tqqt_cast( w ) ) + static_cast(w)->changeItem( itemId( id ), d->iconSet( KIcon::Small ), d->text() ); + else if ( ::tqqt_cast( w ) ) + static_cast(w)->setButtonIcon( itemId( id ), d->iconName() ); +} + +TQString TDEAction::icon() const +{ + return d->iconName( ); +} + +void TDEAction::setIconSet( const TQIconSet &iconset ) +{ + d->setIconSet( iconset ); + + int len = containerCount(); + for( int i = 0; i < len; ++i ) + updateIconSet( i ); +} + + +void TDEAction::updateIconSet( int id ) +{ + TQWidget *w = container( id ); + + if ( ::tqqt_cast( w ) ) + { + int itemId_ = itemId( id ); + static_cast(w)->changeItem( itemId_, d->iconSet(), d->text() ); + if (!d->m_cut.isNull()) + updateShortcut( static_cast(w), itemId_ ); + } + else if ( ::tqqt_cast( w ) ) + static_cast(w)->changeItem( itemId( id ), d->iconSet(), d->text() ); + else if ( ::tqqt_cast( w ) ) + { + if ( icon().isEmpty() && d->hasIcon() ) // only if there is no named icon ( scales better ) + static_cast(w)->setButtonIconSet( itemId( id ), d->iconSet() ); + else + static_cast(w)->setButtonIconSet( itemId( id ), d->iconSet( KIcon::Small ) ); + } +} + +TQIconSet TDEAction::iconSet( KIcon::Group group, int size ) const +{ + return d->iconSet( group, size ); +} + +bool TDEAction::hasIcon() const +{ + return d->hasIcon(); +} + +void TDEAction::setWhatsThis( const TQString& text ) +{ + d->setWhatsThis( text ); + + int len = containerCount(); + for( int i = 0; i < len; ++i ) + updateWhatsThis( i ); +} + +void TDEAction::updateWhatsThis( int i ) +{ + TQPopupMenu* pm = popupMenu( i ); + if ( pm ) + { + pm->TQMenuData::setWhatsThis( itemId( i ), d->whatsThis() ); + return; + } + + TDEToolBar *tb = toolBar( i ); + if ( tb ) + { + TQWidget *w = tb->getButton( itemId( i ) ); + TQWhatsThis::remove( w ); + TQWhatsThis::add( w, d->whatsThis() ); + return; + } +} + +TQString TDEAction::whatsThis() const +{ + return d->whatsThis(); +} + +TQString TDEAction::whatsThisWithIcon() const +{ + TQString text = whatsThis(); + if (!d->iconName().isEmpty()) + return TQString::fromLatin1(" %2").arg(d->iconName() ).arg(text); + return text; +} + +TQWidget* TDEAction::container( int index ) const +{ + assert( index < containerCount() ); + return d->m_containers[ index ].m_container; +} + +TDEToolBar* TDEAction::toolBar( int index ) const +{ + return tqt_dynamic_cast( d->m_containers[ index ].m_container ); +} + +TQPopupMenu* TDEAction::popupMenu( int index ) const +{ + return tqt_dynamic_cast( d->m_containers[ index ].m_container ); +} + +TQWidget* TDEAction::representative( int index ) const +{ + return d->m_containers[ index ].m_representative; +} + +int TDEAction::itemId( int index ) const +{ + return d->m_containers[ index ].m_id; +} + +int TDEAction::containerCount() const +{ + return d->m_containers.count(); +} + +uint TDEAction::kaccelCount() const +{ + return d->m_kaccelList.count(); +} + +void TDEAction::addContainer( TQWidget* c, int id ) +{ + TDEActionPrivate::Container p; + p.m_container = c; + p.m_id = id; + d->m_containers.append( p ); +} + +void TDEAction::addContainer( TQWidget* c, TQWidget* w ) +{ + TDEActionPrivate::Container p; + p.m_container = c; + p.m_representative = w; + d->m_containers.append( p ); +} + +void TDEAction::activate() +{ + emit activated( TDEAction::EmulatedActivation, Qt::NoButton ); + slotActivated(); +} + +void TDEAction::slotActivated() +{ + const TQObject *senderObj = TQT_TQOBJECT_CONST(sender()); + if ( senderObj ) + { + if ( ::tqqt_cast( senderObj ) ) + emit activated( TDEAction::AccelActivation, Qt::NoButton ); + } + emit activated(); +} + +// This catches signals emitted by TDEActions inserted into QPopupMenu +// We do crude things inside it, because we need to know which +// TQPopupMenu emitted the signal. We need to be sure that it is +// only called by QPopupMenus, we plugged us in. +void TDEAction::slotPopupActivated() +{ + if( ::tqqt_cast(sender())) + { + int id = tqt_dynamic_cast(sender())->value().toInt(); + int pos = findContainer(id); + if(pos != -1) + { + TQPopupMenu* qpm = tqt_dynamic_cast( container(pos) ); + if(qpm) + { + TDEPopupMenu* kpm = tqt_dynamic_cast( qpm ); + TQt::ButtonState state; + if ( kpm ) // TDEPopupMenu? Nice, it stores the state. + state = kpm->state(); + else { // just a QPopupMenu? We'll ask for the state now then (small race condition?) + kdDebug(129) << "TDEAction::slotPopupActivated not a TDEPopupMenu -> using keyboardMouseState()" << endl; + state = TDEApplication::keyboardMouseState(); + } + emit activated( TDEAction::PopupMenuActivation, state ); + slotActivated(); + return; + } + } + } + + kdWarning(129)<<"Don't connect TDEAction::slotPopupActivated() to anything, expect into QPopupMenus which are in containers. Use slotActivated instead."<m_kaccel->actions().actionPtr(name()); + if( pAction ) + setShortcut(pAction->shortcut()); +} + +TDEActionCollection *TDEAction::parentCollection() const +{ + return m_parentCollection; +} + +void TDEAction::unplugAll() +{ + while ( containerCount() != 0 ) + unplug( container( 0 ) ); +} + +const KGuiItem& TDEAction::guiItem() const +{ + return *d; +} + +void TDEAction::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +/* vim: et sw=2 ts=2 + */ + +#include "kaction.moc" diff --git a/tdeui/tdeaction.h b/tdeui/tdeaction.h new file mode 100644 index 000000000..b68ded272 --- /dev/null +++ b/tdeui/tdeaction.h @@ -0,0 +1,676 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999 Reginald Stadlbauer + (C) 1999 Simon Hausmann + (C) 2000 Nicolas Hadacek + (C) 2000 Kurt Granroth + (C) 2000 Michael Koch + (C) 2001 Holger Freyther + (C) 2002 Ellis Whitehead + + 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. +*/ +//$Id$ + +#ifndef __kaction_h__ +#define __kaction_h__ + +#include +#include +#include +#include +#include +#include +#include +#include + +class TQMenuBar; +class TQPopupMenu; +class TQComboBox; +class TQPoint; +class TQIconSet; +class TQString; +class TDEToolBar; + +class TDEAccel; +class TDEAccelActions; +class TDEConfig; +class TDEConfigBase; +class KURL; +class TDEInstance; +class TDEToolBar; +class TDEActionCollection; +class TDEPopupMenu; +class TDEMainWindow; + +/** + * @short Class to encapsulate user-driven action or event + * + * The TDEAction class (and derived and super classes) provides a way to + * easily encapsulate a "real" user-selected action or event in your + * program. + * + * For instance, a user may want to @p paste the contents of + * the clipboard or @p scroll @p down a document or @p quit the + * application. These are all @p actions -- events that the + * user causes to happen. The TDEAction class allows the developer to + * deal with these actions in an easy and intuitive manner. + * + * Specifically, the TDEAction class encapsulated the various attributes + * to an event/action. For instance, an action might have an icon + * that goes along with it (a clipboard for a "paste" action or + * scissors for a "cut" action). The action might have some text to + * describe the action. It will certainly have a method or function + * that actually @p executes the action! All these attributes + * are contained within the TDEAction object. + * + * The advantage of dealing with Actions is that you can manipulate + * the Action without regard to the GUI representation of it. For + * instance, in the "normal" way of dealing with actions like "cut", + * you would manually insert a item for Cut into a menu and a button + * into a toolbar. If you want to disable the cut action for a moment + * (maybe nothing is selected), you would have to hunt down the pointer + * to the menu item and the toolbar button and disable both + * individually. Setting the menu item and toolbar item up uses very + * similar code - but has to be done twice! + * + * With the Action concept, you simply "plug" the Action into whatever + * GUI element you want. The TDEAction class will then take care of + * correctly defining the menu item (with icons, accelerators, text, + * etc) or toolbar button.. or whatever. From then on, if you + * manipulate the Action at all, the effect will propogate through all + * GUI representations of it. Back to the "cut" example: if you want + * to disable the Cut Action, you would simply do + * 'cutAction->setEnabled(false)' and the menuitem and button would + * instantly be disabled! + * + * This is the biggest advantage to the Action concept -- there is a + * one-to-one relationship between the "real" action and @p all + * GUI representations of it. + * + * TDEAction emits the activated() signal if the user activated the + * corresponding GUI element ( menu item, toolbar button, etc. ) + * + * If you are in the situation of wanting to map the activated() + * signal of multiple action objects to one slot, with a special + * argument bound to each action, then you might consider using + * TQSignalMapper . A tiny example: + * + * \code + * TQSignalMapper *desktopNumberMapper = new TQSignalMapper( this ); + * connect( desktopNumberMapper, TQT_SIGNAL( mapped( int ) ), + * this, TQT_SLOT( moveWindowToDesktop( int ) ) ); + * + * for ( uint i = 0; i < numberOfDesktops; ++i ) { + * TDEAction *desktopAction = new TDEAction( i18n( "Move Window to Desktop %i" ).arg( i ), ... ); + * connect( desktopAction, TQT_SIGNAL( activated() ), desktopNumberMapper, TQT_SLOT( map() ) ); + * desktopNumberMapper->setMapping( desktopAction, i ); + * } + * \endcode + * + * General Usage:\n + * + * The steps to using actions are roughly as follows + * + * @li Decide which attributes you want to associate with a given + * action (icons, text, keyboard shortcut, etc) + * @li Create the action using TDEAction (or derived or super class). + * @li "Plug" the Action into whatever GUI element you want. Typically, + * this will be a menu or toolbar. + * + * Detailed Example:\n + * + * Here is an example of enabling a "New [document]" action + * \code + * TDEAction *newAct = new TDEAction(i18n("&New"), "filenew", + * TDEStdAccel::shortcut(TDEStdAccel::New), + * this, TQT_SLOT(fileNew()), + * actionCollection(), "new"); + * \endcode + * This line creates our action. It says that wherever this action is + * displayed, it will use "&New" as the text, the standard icon, and + * the standard shortcut. It further says that whenever this action + * is invoked, it will use the fileNew() slot to execute it. + * + * \code + * TQPopupMenu *file = new TQPopupMenu; + * newAct->plug(file); + * \endcode + * That just inserted the action into the File menu. The point is, it's not + * important in which menu it is: all manipulation of the item is + * done through the newAct object. + * + * \code + * newAct->plug(toolBar()); + * \endcode + * And this inserted the Action into the main toolbar as a button. + * + * That's it! + * + * If you want to disable that action sometime later, you can do so + * with + * \code + * newAct->setEnabled(false) + * \endcode + * and both the menuitem in File and the toolbar button will instantly + * be disabled. + * + * Do not delete a TDEAction object without unplugging it from all its + * containers. The simplest way to do that is to use the unplugAll() + * as in the following example: + * \code + * newAct->unplugAll(); + * delete newAct; + * \endcode + * Normally you will not need to do this as TDEActionCollection manages + * everything for you. + * + * Note: if you are using a "standard" action like "new", "paste", + * "quit", or any other action described in the KDE UI Standards, + * please use the methods in the KStdAction class rather than + * defining your own. + * + * Usage Within the XML Framework:\n + * + * If you are using TDEAction within the context of the XML menu and + * toolbar building framework, then there are a few tiny changes. The + * first is that you must insert your new action into an action + * collection. The action collection (a TDEActionCollection) is, + * logically enough, a central collection of all of the actions + * defined in your application. The XML UI framework code in KXMLGUI + * classes needs access to this collection in order to build up the + * GUI (it's how the builder code knows which actions are valid and + * which aren't). + * + * Also, if you use the XML builder framework, then you do not ever + * have to plug your actions into containers manually. The framework + * does that for you. + * + * @see KStdAction + */ +class TDEUI_EXPORT TDEAction : public TQObject +{ + friend class TDEActionCollection; + Q_OBJECT + TQ_PROPERTY( int containerCount READ containerCount ) + TQ_PROPERTY( TQString plainText READ plainText ) + TQ_PROPERTY( TQString text READ text WRITE setText ) + TQ_PROPERTY( TQString shortcut READ shortcutText WRITE setShortcutText ) + TQ_PROPERTY( bool enabled READ isEnabled WRITE setEnabled ) + TQ_PROPERTY( TQString group READ group WRITE setGroup ) + TQ_PROPERTY( TQString whatsThis READ whatsThis WRITE setWhatsThis ) + TQ_PROPERTY( TQString toolTip READ toolTip WRITE setToolTip ) + TQ_PROPERTY( TQString icon READ icon WRITE setIcon ) +public: + /** + * Constructs an action with text, potential keyboard + * shortcut, and a TQT_SLOT to call when this action is invoked by + * the user. + * + * If you do not want or have a keyboard shortcut, + * set the @p cut param to 0. + * + * This is the most common TDEAction used when you do not have a + * corresponding icon (note that it won't appear in the current version + * of the "Edit ToolBar" dialog, because an action needs an icon to be + * plugged in a toolbar...). + * + * @param text The text that will be displayed. + * @param cut The corresponding keyboard shortcut. + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TDEActionCollection* parent, const char* name ); + + /** + * Constructs an action with text, icon, potential keyboard + * shortcut, and a TQT_SLOT to call when this action is invoked by + * the user. + * + * If you do not want or have a keyboard shortcut, set the + * @p cut param to 0. + * + * This is the other common TDEAction used. Use it when you + * @p do have a corresponding icon. + * + * @param text The text that will be displayed. + * @param pix The icon to display. + * @param cut The corresponding keyboard shortcut. + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TDEActionCollection* parent, const char* name ); + + /** + * Constructs an action with text, icon, potential keyboard + * shortcut, and a TQT_SLOT to call when this action is invoked by + * the user. The icon is loaded on demand later based on where it + * is plugged in. + * + * If you do not want or have a keyboard shortcut, set the + * @p cut param to 0. + * + * This is the other common TDEAction used. Use it when you + * @p do have a corresponding icon. + * + * @param text The text that will be displayed. + * @param pix The icon to display. + * @param cut The corresponding keyboard shortcut (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TDEActionCollection* parent, const char* name ); + + /** + * The same as the above constructor, but with a KGuiItem providing + * the text and icon. + * + * @param item The KGuiItem with the label and (optional) icon. + * @param cut The corresponding keyboard shortcut (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEAction( const KGuiItem& item, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TDEActionCollection* parent, const char* name ); + + /** + * @obsolete + */ + TDEAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, const char* name = 0 ); + /** + * @obsolete + */ + TDEAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); + /** + * @obsolete + */ + TDEAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + /** + * @obsolete + */ + TDEAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + /** + * @obsolete + */ + TDEAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); + /** + * @obsolete + */ + TDEAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, + const char* name = 0 ); + /** + * @obsolete + */ + TDEAction( TQObject* parent = 0, const char* name = 0 ); + + /** + * Standard destructor + */ + virtual ~TDEAction(); + + /** + * "Plug" or insert this action into a given widget. + * + * This will + * typically be a menu or a toolbar. From this point on, you will + * never need to directly manipulate the item in the menu or + * toolbar. You do all enabling/disabling/manipulation directly + * with your TDEAction object. + * + * @param widget The GUI element to display this action + * @param index The position into which the action is plugged. If + * this is negative, the action is inserted at the end. + */ + virtual int plug( TQWidget *widget, int index = -1 ); + + /** + * @deprecated. Shouldn't be used. No substitute available. + * + * "Plug" or insert this action into a given TDEAccel. + * + * @param accel The TDEAccel collection which holds this accel + * @param configurable If the shortcut is configurable via + * the TDEAccel configuration dialog (this is somehow deprecated since + * there is now a TDEAction key configuration dialog). + */ + virtual void plugAccel(TDEAccel *accel, bool configurable = true) KDE_DEPRECATED; + + /** + * "Unplug" or remove this action from a given widget. + * + * This will typically be a menu or a toolbar. This is rarely + * used in "normal" application. Typically, it would be used if + * your application has several views or modes, each with a + * completely different menu structure. If you simply want to + * disable an action for a given period, use setEnabled() + * instead. + * + * @param w Remove the action from this GUI element. + */ + virtual void unplug( TQWidget *w ); + + /** + * @deprecated. Complement method to plugAccel(). + * Disconnect this action from the TDEAccel. + */ + virtual void unplugAccel() KDE_DEPRECATED; + + /** + * returns whether the action is plugged into any container widget or not. + * @since 3.1 + */ + virtual bool isPlugged() const; + + /** + * returns whether the action is plugged into the given container + */ + bool isPlugged( const TQWidget *container ) const; + + /** + * returns whether the action is plugged into the given container with the given, container specific, id (often + * menu or toolbar id ) . + */ + virtual bool isPlugged( const TQWidget *container, int id ) const; + + /** + * returns whether the action is plugged into the given container with the given, container specific, representative + * container widget item. + */ + virtual bool isPlugged( const TQWidget *container, const TQWidget *_representative ) const; + + TQWidget* container( int index ) const; + int itemId( int index ) const; + TQWidget* representative( int index ) const; + int containerCount() const; + /// @since 3.1 + uint kaccelCount() const; + + virtual bool hasIcon() const; +#ifndef KDE_NO_COMPAT + bool hasIconSet() const { return hasIcon(); } +#endif + virtual TQString plainText() const; + + /** + * Get the text associated with this action. + */ + virtual TQString text() const; + + /** + * Get the keyboard shortcut associated with this action. + */ + virtual const TDEShortcut& shortcut() const; + /** + * Get the default shortcut for this action. + */ + virtual const TDEShortcut& shortcutDefault() const; + + // These two methods are for TQ_PROPERTY + TQString shortcutText() const; + void setShortcutText( const TQString& ); + + /** + * Returns true if this action is enabled. + */ + virtual bool isEnabled() const; + + /** + * Returns true if this action's shortcut is configurable. + */ + virtual bool isShortcutConfigurable() const; + + virtual TQString group() const; + + /** + * Get the What's this text for the action. + */ + virtual TQString whatsThis() const; + + /** + * Get the tooltip text for the action. + */ + virtual TQString toolTip() const; + + /** + * Get the TQIconSet from which the icons used to display this action will + * be chosen. + * + * In KDE4 set group default to KIcon::Small while removing the other + * iconSet() function. + */ + virtual TQIconSet iconSet( KIcon::Group group, int size=0 ) const; + /** + * Remove in KDE4 + */ + TQIconSet iconSet() const { return iconSet( KIcon::Small ); } + + virtual TQString icon() const; + + TDEActionCollection *parentCollection() const; + + /** + * @internal + * Generate a toolbar button id. Made public for reimplementations. + */ + static int getToolButtonID(); + + + void unplugAll(); + + /** + * @since 3.4 + */ + enum ActivationReason { UnknownActivation, EmulatedActivation, AccelActivation, PopupMenuActivation, ToolBarActivation }; + +public slots: + /** + * Sets the text associated with this action. The text is used for menu + * and toolbar labels etc. + */ + virtual void setText(const TQString &text); + + /** + * Sets the keyboard shortcut associated with this action. + */ + virtual bool setShortcut( const TDEShortcut& ); + + virtual void setGroup( const TQString& ); + + /** + * Sets the What's this text for the action. This text will be displayed when + * a widget that has been created by plugging this action into a container + * is clicked on in What's this mode. + * + * The What's this text can include QML markup as well as raw text. + */ + virtual void setWhatsThis( const TQString& text ); + + /** + * Sets the tooltip text for the action. + * This will be used as a tooltip for a toolbar button, as a + * statusbar help-text for a menu item, and it also appears + * in the toolbar editor, to describe the action. + * + * For the tooltip to show up on the statusbar you will need to connect + * a couple of the actionclass signals to the toolbar. + * The easiest way of doing this is in your main window class, when you create + * a statusbar. See the TDEActionCollection class for more details. + * + * @see TDEActionCollection + * + */ + virtual void setToolTip( const TQString& ); + + /** + * Sets the TQIconSet from which the icons used to display this action will + * be chosen. + */ + virtual void setIconSet( const TQIconSet &iconSet ); + + virtual void setIcon( const TQString& icon ); + + /** + * Enables or disables this action. All uses of this action (eg. in menus + * or toolbars) will be updated to reflect the state of the action. + */ + virtual void setEnabled(bool enable); + + /** + * Calls setEnabled( !disable ). + * @since 3.5 + */ + void setDisabled(bool disable) { return setEnabled(!disable); } + + /** + * Indicate whether the user may configure the action's shortcut. + */ + virtual void setShortcutConfigurable( bool ); + + /** + * Emulate user's interaction programmatically, by activating the action. + * The implementation simply emits activated(). + */ + virtual void activate(); + +protected slots: + virtual void slotDestroyed(); + virtual void slotKeycodeChanged(); + virtual void slotActivated(); + /// @since 3.4 + void slotPopupActivated(); // KDE4: make virtual + /// @since 3.4 + void slotButtonClicked( int, TQt::ButtonState state ); // KDE4: make virtual + +protected: + TDEToolBar* toolBar( int index ) const; + TQPopupMenu* popupMenu( int index ) const; + void removeContainer( int index ); + int findContainer( const TQWidget* widget ) const; + int findContainer( int id ) const; + void plugMainWindowAccel( TQWidget *w ); + + void addContainer( TQWidget* parent, int id ); + void addContainer( TQWidget* parent, TQWidget* representative ); + + virtual void updateShortcut( int i ); + virtual void updateShortcut( TQPopupMenu* menu, int id ); + virtual void updateGroup( int id ); + virtual void updateText(int i ); + virtual void updateEnabled(int i); + virtual void updateIconSet(int i); + virtual void updateIcon( int i); + virtual void updateToolTip( int id ); + virtual void updateWhatsThis( int i ); + + TDEActionCollection *m_parentCollection; + TQString whatsThisWithIcon() const; + /** + * Return the underlying KGuiItem + * @since 3.3 + */ + const KGuiItem& guiItem() const; + +signals: + /** + * Emitted when this action is activated + */ + void activated(); + /** + * This signal allows to know the reason why an action was activated: + * whether it was due to a toolbar button, popupmenu, keyboard accel, or programmatically. + * In the first two cases, it also allows to know which mouse button was + * used (Left or Middle), and whether keyboard modifiers were pressed (e.g. CTRL). + * + * Note that this signal is emitted before the normal activated() signal. + * Yes, BOTH signals are always emitted, so that connecting to activated() still works. + * Applications which care about reason and state can either ignore the activated() + * signal for a given action and react to this one instead, or store the + * reason and state until the activated() signal is emitted. + * + * @since 3.4 + */ + void activated( TDEAction::ActivationReason reason, TQt::ButtonState state ); + void enabled( bool ); + +private: + void initPrivate( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot ); + TDEAccel* kaccelCurrent(); + bool initShortcut( const TDEShortcut& ); + void plugShortcut(); + bool updateTDEAccelShortcut( TDEAccel* kaccel ); + void insertTDEAccel( TDEAccel* ); + /** @internal To be used exclusively by TDEActionCollection::removeWidget(). */ + void removeTDEAccel( TDEAccel* ); + +#ifndef KDE_NO_COMPAT +public: + /** + * @deprecated. Use shortcut(). + * Get the keyboard accelerator associated with this action. + */ + int accel() const KDE_DEPRECATED; + + TQString statusText() const + { return toolTip(); } + + /** + * @deprecated. Use setShortcut(). + * Sets the keyboard accelerator associated with this action. + */ + void setAccel( int key ) KDE_DEPRECATED; + + /** + * @deprecated. Use setToolTip instead (they do the same thing now). + */ + void setStatusText( const TQString &text ) + { setToolTip( text ); } + + /** + * @deprecated. for backwards compatibility. Use itemId() + */ + int menuId( int i ) { return itemId( i ); } +#endif // !KDE_NO_COMPAT + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEActionPrivate; + TDEActionPrivate* const d; +}; + +#include +#include + +#endif diff --git a/tdeui/tdeactionclasses.cpp b/tdeui/tdeactionclasses.cpp new file mode 100644 index 000000000..87c9932a3 --- /dev/null +++ b/tdeui/tdeactionclasses.cpp @@ -0,0 +1,2421 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999 Reginald Stadlbauer + (C) 1999 Simon Hausmann + (C) 2000 Nicolas Hadacek + (C) 2000 Kurt Granroth + (C) 2000 Michael Koch + (C) 2001 Holger Freyther + (C) 2002 Ellis Whitehead + (C) 2002 Joseph Wenninger + (C) 2003 Andras Mantia + + 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. +*/ + +#include "kactionclasses.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class TDEToggleAction::TDEToggleActionPrivate +{ +public: + TDEToggleActionPrivate() + { + m_checked = false; + m_checkedGuiItem = 0; + } + + bool m_checked; + TQString m_exclusiveGroup; + KGuiItem* m_checkedGuiItem; +}; + +TDEToggleAction::TDEToggleAction( const TQString& text, const TDEShortcut& cut, + TQObject* parent, + const char* name ) + : TDEAction( text, cut, parent, name ) +{ + d = new TDEToggleActionPrivate; +} + +TDEToggleAction::TDEToggleAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name ) + : TDEAction( text, cut, receiver, slot, parent, name ) +{ + d = new TDEToggleActionPrivate; +} + +TDEToggleAction::TDEToggleAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDEAction( text, pix, cut, parent, name ) +{ + d = new TDEToggleActionPrivate; +} + +TDEToggleAction::TDEToggleAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDEAction( text, pix, cut, parent, name ) +{ + d = new TDEToggleActionPrivate; +} + +TDEToggleAction::TDEToggleAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, TQObject* parent, + const char* name ) + : TDEAction( text, pix, cut, receiver, slot, parent, name ) +{ + d = new TDEToggleActionPrivate; +} + +TDEToggleAction::TDEToggleAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, TQObject* parent, + const char* name ) + : TDEAction( text, pix, cut, receiver, slot, parent, name ) +{ + d = new TDEToggleActionPrivate; +} + +TDEToggleAction::TDEToggleAction( TQObject* parent, const char* name ) + : TDEAction( parent, name ) +{ + d = new TDEToggleActionPrivate; +} + +TDEToggleAction::~TDEToggleAction() +{ + delete d->m_checkedGuiItem; + delete d; +} + +int TDEToggleAction::plug( TQWidget* widget, int index ) +{ + if ( !::tqqt_cast( widget ) && !::tqqt_cast( widget ) ) + { + kdWarning() << "Can not plug TDEToggleAction in " << widget->className() << endl; + return -1; + } + if (kapp && !kapp->authorizeTDEAction(name())) + return -1; + + int _index = TDEAction::plug( widget, index ); + if ( _index == -1 ) + return _index; + + if ( ::tqqt_cast( widget ) ) { + TDEToolBar *bar = static_cast( widget ); + + bar->setToggle( itemId( _index ), true ); + bar->setButton( itemId( _index ), isChecked() ); + } + + if ( d->m_checked ) + updateChecked( _index ); + + return _index; +} + +void TDEToggleAction::setChecked( bool c ) +{ + if ( c == d->m_checked ) + return; + //kdDebug(129) << "TDEToggleAction::setChecked(" << c << ") " << this << " " << name() << endl; + + d->m_checked = c; + + int len = containerCount(); + + for( int i = 0; i < len; ++i ) + updateChecked( i ); + + if ( c && parent() && !exclusiveGroup().isEmpty() ) { + const TQObjectList list = parent()->childrenListObject(); + if ( !list.isEmpty() ) { + TQObjectListIt it( list ); + for( ; it.current(); ++it ) { + if ( ::tqqt_cast( it.current() ) && it.current() != this && + static_cast(it.current())->exclusiveGroup() == exclusiveGroup() ) { + TDEToggleAction *a = static_cast(it.current()); + if( a->isChecked() ) { + a->setChecked( false ); + emit a->toggled( false ); + } + } + } + } + } +} + +void TDEToggleAction::updateChecked( int id ) +{ + TQWidget *w = container( id ); + + if ( ::tqqt_cast( w ) ) { + TQPopupMenu* pm = static_cast(w); + int itemId_ = itemId( id ); + if ( !d->m_checkedGuiItem ) + pm->setItemChecked( itemId_, d->m_checked ); + else { + const KGuiItem* gui = d->m_checked ? d->m_checkedGuiItem : &guiItem(); + if ( d->m_checkedGuiItem->hasIcon() ) + pm->changeItem( itemId_, gui->iconSet( KIcon::Small ), gui->text() ); + else + pm->changeItem( itemId_, gui->text() ); + + // If the text doesn't change, then set the icon to be "pressed", otherwise + // there is too little difference between checked and unchecked. + if ( d->m_checkedGuiItem->text() == guiItem().text() ) + pm->setItemChecked( itemId_, d->m_checked ); + + if ( !d->m_checkedGuiItem->whatsThis().isEmpty() ) // if empty, we keep the initial one + pm->TQMenuData::setWhatsThis( itemId_, gui->whatsThis() ); + updateShortcut( pm, itemId_ ); + } + } + else if ( ::tqqt_cast( w ) ) // not handled in plug... + static_cast(w)->setItemChecked( itemId( id ), d->m_checked ); + else if ( ::tqqt_cast( w ) ) + { + TQWidget* r = static_cast( w )->getButton( itemId( id ) ); + if ( r && ::tqqt_cast( r ) ) { + static_cast( w )->setButton( itemId( id ), d->m_checked ); + if ( d->m_checkedGuiItem && d->m_checkedGuiItem->hasIcon() ) { + const KGuiItem* gui = d->m_checked ? d->m_checkedGuiItem : &guiItem(); + static_cast( w )->setButtonIconSet( itemId( id ), gui->iconSet( KIcon::Toolbar ) ); + } + } + } +} + +void TDEToggleAction::slotActivated() +{ + setChecked( !isChecked() ); + TDEAction::slotActivated(); + emit toggled( isChecked() ); +} + +bool TDEToggleAction::isChecked() const +{ + return d->m_checked; +} + +void TDEToggleAction::setExclusiveGroup( const TQString& name ) +{ + d->m_exclusiveGroup = name; +} + +TQString TDEToggleAction::exclusiveGroup() const +{ + return d->m_exclusiveGroup; +} + +void TDEToggleAction::setCheckedState( const KGuiItem& checkedItem ) +{ + delete d->m_checkedGuiItem; + d->m_checkedGuiItem = new KGuiItem( checkedItem ); +} + +TQString TDEToggleAction::toolTip() const +{ + if ( d->m_checkedGuiItem && d->m_checked ) + return d->m_checkedGuiItem->toolTip(); + else + return TDEAction::toolTip(); +} + +TDERadioAction::TDERadioAction( const TQString& text, const TDEShortcut& cut, + TQObject* parent, const char* name ) +: TDEToggleAction( text, cut, parent, name ) +{ +} + +TDERadioAction::TDERadioAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name ) +: TDEToggleAction( text, cut, receiver, slot, parent, name ) +{ +} + +TDERadioAction::TDERadioAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) +: TDEToggleAction( text, pix, cut, parent, name ) +{ +} + +TDERadioAction::TDERadioAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) +: TDEToggleAction( text, pix, cut, parent, name ) +{ +} + +TDERadioAction::TDERadioAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name ) +: TDEToggleAction( text, pix, cut, receiver, slot, parent, name ) +{ +} + +TDERadioAction::TDERadioAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name ) +: TDEToggleAction( text, pix, cut, receiver, slot, parent, name ) +{ +} + +TDERadioAction::TDERadioAction( TQObject* parent, const char* name ) +: TDEToggleAction( parent, name ) +{ +} + +void TDERadioAction::slotActivated() +{ + if ( isChecked() ) + { + const TQObject *senderObj = TQT_TQOBJECT_CONST(sender()); + + if ( !senderObj || !::tqqt_cast( senderObj ) ) + return; + + const_cast( static_cast( TQT_TQWIDGET_CONST(senderObj) ) )->on( true ); + + return; + } + + TDEToggleAction::slotActivated(); +} + +class TDESelectAction::TDESelectActionPrivate +{ +public: + TDESelectActionPrivate() + { + m_edit = false; + m_menuAccelsEnabled = true; + m_menu = 0; + m_current = -1; + m_comboWidth = -1; + m_maxComboViewCount = -1; + } + bool m_edit; + bool m_menuAccelsEnabled; + TQPopupMenu *m_menu; + int m_current; + int m_comboWidth; + TQStringList m_list; + int m_maxComboViewCount; + + TQString makeMenuText( const TQString &_text ) + { + if ( m_menuAccelsEnabled ) + return _text; + TQString text = _text; + uint i = 0; + while ( i < text.length() ) { + if ( text[ i ] == '&' ) { + text.insert( i, '&' ); + i += 2; + } + else + ++i; + } + return text; + } +}; + +TDESelectAction::TDESelectAction( const TQString& text, const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDEAction( text, cut, parent, name ) +{ + d = new TDESelectActionPrivate; +} + +TDESelectAction::TDESelectAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name ) + : TDEAction( text, cut, receiver, slot, parent, name ) +{ + d = new TDESelectActionPrivate; +} + +TDESelectAction::TDESelectAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDEAction( text, pix, cut, parent, name ) +{ + d = new TDESelectActionPrivate; +} + +TDESelectAction::TDESelectAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDEAction( text, pix, cut, parent, name ) +{ + d = new TDESelectActionPrivate; +} + +TDESelectAction::TDESelectAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, TQObject* parent, + const char* name ) + : TDEAction( text, pix, cut, receiver, slot, parent, name ) +{ + d = new TDESelectActionPrivate; +} + +TDESelectAction::TDESelectAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, TQObject* parent, + const char* name ) + : TDEAction( text, pix, cut, receiver, slot, parent, name ) +{ + d = new TDESelectActionPrivate; +} + +TDESelectAction::TDESelectAction( TQObject* parent, const char* name ) + : TDEAction( parent, name ) +{ + d = new TDESelectActionPrivate; +} + +TDESelectAction::~TDESelectAction() +{ + assert(d); + delete d->m_menu; + delete d; d = 0; +} + +void TDESelectAction::setCurrentItem( int id ) +{ + if ( id >= (int)d->m_list.count() ) { + Q_ASSERT(id < (int)d->m_list.count()); + return; + } + + if ( d->m_menu ) + { + if ( d->m_current >= 0 ) + d->m_menu->setItemChecked( d->m_current, false ); + if ( id >= 0 ) + d->m_menu->setItemChecked( id, true ); + } + + d->m_current = id; + + int len = containerCount(); + + for( int i = 0; i < len; ++i ) + updateCurrentItem( i ); + + // emit TDEAction::activated(); + // emit activated( currentItem() ); + // emit activated( currentText() ); +} + +void TDESelectAction::setComboWidth( int width ) +{ + if ( width < 0 ) + return; + + d->m_comboWidth=width; + + int len = containerCount(); + + for( int i = 0; i < len; ++i ) + updateComboWidth( i ); + +} + +void TDESelectAction::setMaxComboViewCount( int n ) +{ + d->m_maxComboViewCount = n; +} + +TQPopupMenu* TDESelectAction::popupMenu() const +{ + kdDebug(129) << "TDEAction::popupMenu()" << endl; // remove -- ellis + if ( !d->m_menu ) + { + d->m_menu = new TDEPopupMenu(0L, "TDESelectAction::popupMenu()"); + setupMenu(); + if ( d->m_current >= 0 ) + d->m_menu->setItemChecked( d->m_current, true ); + } + + return d->m_menu; +} + +void TDESelectAction::setupMenu() const +{ + if ( !d->m_menu ) + return; + d->m_menu->clear(); + + TQStringList::ConstIterator it = d->m_list.begin(); + for( uint id = 0; it != d->m_list.end(); ++it, ++id ) { + TQString text = *it; + if ( !text.isEmpty() ) + d->m_menu->insertItem( d->makeMenuText( text ), this, TQT_SLOT( slotActivated( int ) ), 0, id ); + else + d->m_menu->insertSeparator(); + } +} + +void TDESelectAction::changeItem( int index, const TQString& text ) +{ + if ( index < 0 || index >= (int)d->m_list.count() ) + { + kdWarning() << "TDESelectAction::changeItem Index out of scope" << endl; + return; + } + + d->m_list[ index ] = text; + + if ( d->m_menu ) + d->m_menu->changeItem( index, d->makeMenuText( text ) ); + + int len = containerCount(); + for( int i = 0; i < len; ++i ) + changeItem( i, index, text ); +} + +void TDESelectAction::changeItem( int id, int index, const TQString& text) +{ + if ( index < 0 ) + return; + + TQWidget* w = container( id ); + if ( ::tqqt_cast( w ) ) + { + TQWidget* r = (static_cast( w ))->getWidget( itemId( id ) ); + if ( ::tqqt_cast( r ) ) + { + TQComboBox *b = static_cast( r ); + b->changeItem(text, index ); + } + } +} + +void TDESelectAction::setItems( const TQStringList &lst ) +{ + d->m_list = lst; + d->m_current = -1; + + setupMenu(); + + int len = containerCount(); + for( int i = 0; i < len; ++i ) + updateItems( i ); + + // Disable if empty and not editable + setEnabled ( lst.count() > 0 || d->m_edit ); +} + +TQStringList TDESelectAction::items() const +{ + return d->m_list; +} + +TQString TDESelectAction::currentText() const +{ + if ( currentItem() < 0 ) + return TQString::null; + + return d->m_list[ currentItem() ]; +} + +int TDESelectAction::currentItem() const +{ + return d->m_current; +} + +void TDESelectAction::updateCurrentItem( int id ) +{ + if ( d->m_current < 0 ) + return; + + TQWidget* w = container( id ); + if ( ::tqqt_cast( w ) ) { + TQWidget* r = static_cast( w )->getWidget( itemId( id ) ); + if ( ::tqqt_cast( r ) ) { + TQComboBox *b = static_cast( r ); + b->setCurrentItem( d->m_current ); + } + } +} + +int TDESelectAction::comboWidth() const +{ + return d->m_comboWidth; +} + +void TDESelectAction::updateComboWidth( int id ) +{ + TQWidget* w = container( id ); + if ( ::tqqt_cast( w ) ) { + TQWidget* r = static_cast( w )->getWidget( itemId( id ) ); + if ( ::tqqt_cast( r ) ) { + TQComboBox *cb = static_cast( r ); + cb->setMinimumWidth( d->m_comboWidth ); + cb->setMaximumWidth( d->m_comboWidth ); + } + } +} + +void TDESelectAction::updateItems( int id ) +{ + kdDebug(129) << "TDEAction::updateItems( " << id << ", lst )" << endl; // remove -- ellis + TQWidget* w = container( id ); + if ( ::tqqt_cast( w ) ) { + TQWidget* r = static_cast( w )->getWidget( itemId( id ) ); + if ( ::tqqt_cast( r ) ) { + TQComboBox *cb = static_cast( r ); + cb->clear(); + TQStringList lst = comboItems(); + TQStringList::ConstIterator it = lst.begin(); + for( ; it != lst.end(); ++it ) + cb->insertItem( *it ); + // qt caches and never recalculates the sizeHint() + // qcombobox.cpp recommends calling setFont to invalidate the sizeHint + // setFont sets own_font = True, so we're a bit mean and calll + // unsetFont which calls setFont and then overwrites the own_font + cb->unsetFont(); + } + } +} + +int TDESelectAction::plug( TQWidget *widget, int index ) +{ + if (kapp && !kapp->authorizeTDEAction(name())) + return -1; + kdDebug(129) << "TDESelectAction::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis + if ( ::tqqt_cast( widget) ) + { + // Create the PopupMenu and store it in m_menu + (void)popupMenu(); + + TQPopupMenu* menu = static_cast( widget ); + int id; + if ( hasIcon() ) + id = menu->insertItem( iconSet(), text(), d->m_menu, -1, index ); + else + id = menu->insertItem( text(), d->m_menu, -1, index ); + + if ( !isEnabled() ) + menu->setItemEnabled( id, false ); + + TQString wth = whatsThis(); + if ( !wth.isEmpty() ) + menu->TQMenuData::setWhatsThis( id, wth ); + + addContainer( menu, id ); + connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + return containerCount() - 1; + } + else if ( ::tqqt_cast( widget ) ) + { + TDEToolBar* bar = static_cast( widget ); + int id_ = TDEAction::getToolButtonID(); + bar->insertCombo( comboItems(), id_, isEditable(), + TQT_SIGNAL( activated( const TQString & ) ), this, + TQT_SLOT( slotActivated( const TQString & ) ), isEnabled(), + toolTip(), -1, index ); + + TQComboBox *cb = bar->getCombo( id_ ); + if ( cb ) + { + if (!isEditable()) cb->setFocusPolicy(TQ_NoFocus); + cb->setMinimumWidth( cb->sizeHint().width() ); + if ( d->m_comboWidth > 0 ) + { + cb->setMinimumWidth( d->m_comboWidth ); + cb->setMaximumWidth( d->m_comboWidth ); + } + cb->setInsertionPolicy( TQComboBox::NoInsertion ); + TQWhatsThis::add( cb, whatsThis() ); + if ( d->m_maxComboViewCount != -1 ) cb->setSizeLimit( d->m_maxComboViewCount ); + } + + addContainer( bar, id_ ); + + connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + updateCurrentItem( containerCount() - 1 ); + + return containerCount() - 1; + } + else if ( ::tqqt_cast( widget ) ) + { + // Create the PopupMenu and store it in m_menu + (void)popupMenu(); + + TQMenuBar* menu = static_cast( widget ); + int id = menu->insertItem( text(), d->m_menu, -1, index ); + + if ( !isEnabled() ) + menu->setItemEnabled( id, false ); + + TQString wth = whatsThis(); + if ( !wth.isEmpty() ) + menu->TQMenuData::setWhatsThis( id, wth ); + + addContainer( menu, id ); + connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + return containerCount() - 1; + } + + kdWarning() << "Can not plug TDEAction in " << widget->className() << endl; + return -1; +} + +TQStringList TDESelectAction::comboItems() const +{ + if( d->m_menuAccelsEnabled ) { + TQStringList lst; + TQStringList::ConstIterator it = d->m_list.begin(); + for( ; it != d->m_list.end(); ++it ) + { + TQString item = *it; + int i = item.find( '&' ); + if ( i > -1 ) + item = item.remove( i, 1 ); + lst.append( item ); + } + return lst; + } + else + return d->m_list; +} + +void TDESelectAction::clear() +{ + if ( d->m_menu ) + d->m_menu->clear(); + + int len = containerCount(); + for( int i = 0; i < len; ++i ) + updateClear( i ); +} + +void TDESelectAction::updateClear( int id ) +{ + TQWidget* w = container( id ); + if ( ::tqqt_cast( w ) ) { + TQWidget* r = static_cast( w )->getWidget( itemId( id ) ); + if ( ::tqqt_cast( r ) ) { + TQComboBox *b = static_cast( r ); + b->clear(); + } + } +} + +void TDESelectAction::slotActivated( int id ) +{ + if ( d->m_current == id ) + return; + + setCurrentItem( id ); + // Delay this. Especially useful when the slot connected to activated() will re-create + // the menu, e.g. in the recent files action. This prevents a crash. + TQTimer::singleShot( 0, this, TQT_SLOT( slotActivated() ) ); +} + +void TDESelectAction::slotActivated( const TQString &text ) +{ + if ( isEditable() ) + { + TQStringList lst = d->m_list; + if(!lst.contains(text)) + { + lst.append( text ); + setItems( lst ); + } + } + + int i = d->m_list.findIndex( text ); + if ( i > -1 ) + setCurrentItem( i ); + else + setCurrentItem( comboItems().findIndex( text ) ); + // Delay this. Especially useful when the slot connected to activated() will re-create + // the menu, e.g. in the recent files action. This prevents a crash. + TQTimer::singleShot( 0, this, TQT_SLOT( slotActivated() ) ); +} + +void TDESelectAction::slotActivated() +{ + TDEAction::slotActivated(); + kdDebug(129) << "TDESelectAction::slotActivated currentItem=" << currentItem() << " currentText=" << currentText() << endl; + emit activated( currentItem() ); + emit activated( currentText() ); +} + +void TDESelectAction::setEditable( bool edit ) +{ + d->m_edit = edit; +} + +bool TDESelectAction::isEditable() const +{ + return d->m_edit; +} + +void TDESelectAction::setRemoveAmpersandsInCombo( bool b ) +{ + setMenuAccelsEnabled( b ); +} + +bool TDESelectAction::removeAmpersandsInCombo() const +{ + return menuAccelsEnabled( ); +} + +void TDESelectAction::setMenuAccelsEnabled( bool b ) +{ + d->m_menuAccelsEnabled = b; +} + +bool TDESelectAction::menuAccelsEnabled() const +{ + return d->m_menuAccelsEnabled; +} + +class TDEListAction::TDEListActionPrivate +{ +public: + TDEListActionPrivate() + { + m_current = 0; + } + int m_current; +}; + +TDEListAction::TDEListAction( const TQString& text, const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDESelectAction( text, cut, parent, name ) +{ + d = new TDEListActionPrivate; +} + +TDEListAction::TDEListAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name ) + : TDESelectAction( text, cut, parent, name ) +{ + d = new TDEListActionPrivate; + if ( receiver ) + connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot ); +} + +TDEListAction::TDEListAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDESelectAction( text, pix, cut, parent, name ) +{ + d = new TDEListActionPrivate; +} + +TDEListAction::TDEListAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDESelectAction( text, pix, cut, parent, name ) +{ + d = new TDEListActionPrivate; +} + +TDEListAction::TDEListAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, const TQObject* receiver, + const char* slot, TQObject* parent, + const char* name ) + : TDESelectAction( text, pix, cut, parent, name ) +{ + d = new TDEListActionPrivate; + if ( receiver ) + connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot ); +} + +TDEListAction::TDEListAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, const TQObject* receiver, + const char* slot, TQObject* parent, + const char* name ) + : TDESelectAction( text, pix, cut, parent, name ) +{ + d = new TDEListActionPrivate; + if ( receiver ) + connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot ); +} + +TDEListAction::TDEListAction( TQObject* parent, const char* name ) + : TDESelectAction( parent, name ) +{ + d = new TDEListActionPrivate; +} + +TDEListAction::~TDEListAction() +{ + delete d; d = 0; +} + +void TDEListAction::setCurrentItem( int index ) +{ + TDESelectAction::setCurrentItem( index ); + d->m_current = index; + + // emit TDEAction::activated(); + // emit activated( currentItem() ); + // emit activated( currentText() ); +} + +TQString TDEListAction::currentText() const +{ + return TDESelectAction::currentText(); +} + +int TDEListAction::currentItem() const +{ + return d->m_current; +} + +class TDERecentFilesAction::TDERecentFilesActionPrivate +{ +public: + TDERecentFilesActionPrivate() + { + m_maxItems = 0; + m_popup = 0; + } + uint m_maxItems; + TDEPopupMenu *m_popup; + TQMap m_shortNames; + TQMap m_urls; +}; + +TDERecentFilesAction::TDERecentFilesAction( const TQString& text, + const TDEShortcut& cut, + TQObject* parent, const char* name, + uint maxItems ) + : TDEListAction( text, cut, parent, name) +{ + d = new TDERecentFilesActionPrivate; + d->m_maxItems = maxItems; + + init(); +} + +TDERecentFilesAction::TDERecentFilesAction( const TQString& text, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, + TQObject* parent, const char* name, + uint maxItems ) + : TDEListAction( text, cut, parent, name) +{ + d = new TDERecentFilesActionPrivate; + d->m_maxItems = maxItems; + + init(); + + if ( receiver ) + connect( this, TQT_SIGNAL(urlSelected(const KURL&)), + receiver, slot ); +} + +TDERecentFilesAction::TDERecentFilesAction( const TQString& text, + const TQIconSet& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name, + uint maxItems ) + : TDEListAction( text, pix, cut, parent, name) +{ + d = new TDERecentFilesActionPrivate; + d->m_maxItems = maxItems; + + init(); +} + +TDERecentFilesAction::TDERecentFilesAction( const TQString& text, + const TQString& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name, + uint maxItems ) + : TDEListAction( text, pix, cut, parent, name) +{ + d = new TDERecentFilesActionPrivate; + d->m_maxItems = maxItems; + + init(); +} + +TDERecentFilesAction::TDERecentFilesAction( const TQString& text, + const TQIconSet& pix, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, + TQObject* parent, const char* name, + uint maxItems ) + : TDEListAction( text, pix, cut, parent, name) +{ + d = new TDERecentFilesActionPrivate; + d->m_maxItems = maxItems; + + init(); + + if ( receiver ) + connect( this, TQT_SIGNAL(urlSelected(const KURL&)), + receiver, slot ); +} + +TDERecentFilesAction::TDERecentFilesAction( const TQString& text, + const TQString& pix, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, + TQObject* parent, const char* name, + uint maxItems ) + : TDEListAction( text, pix, cut, parent, name) +{ + d = new TDERecentFilesActionPrivate; + d->m_maxItems = maxItems; + + init(); + + if ( receiver ) + connect( this, TQT_SIGNAL(urlSelected(const KURL&)), + receiver, slot ); +} + +TDERecentFilesAction::TDERecentFilesAction( TQObject* parent, const char* name, + uint maxItems ) + : TDEListAction( parent, name ) +{ + d = new TDERecentFilesActionPrivate; + d->m_maxItems = maxItems; + + init(); +} + +void TDERecentFilesAction::init() +{ + TDERecentFilesAction *that = const_cast(this); + that->d->m_popup = new TDEPopupMenu; + connect(d->m_popup, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(menuAboutToShow())); + connect(d->m_popup, TQT_SIGNAL(activated(int)), this, TQT_SLOT(menuItemActivated(int))); + connect( this, TQT_SIGNAL( activated( const TQString& ) ), + this, TQT_SLOT( itemSelected( const TQString& ) ) ); + + setMenuAccelsEnabled( false ); +} + +TDERecentFilesAction::~TDERecentFilesAction() +{ + delete d->m_popup; + delete d; d = 0; +} + +uint TDERecentFilesAction::maxItems() const +{ + return d->m_maxItems; +} + +void TDERecentFilesAction::setMaxItems( uint maxItems ) +{ + TQStringList lst = TDESelectAction::items(); + uint oldCount = lst.count(); + + // set new maxItems + d->m_maxItems = maxItems; + + // remove all items that are too much + while( lst.count() > maxItems ) + { + // remove last item + TQString lastItem = lst.last(); + d->m_shortNames.erase( lastItem ); + d->m_urls.erase( lastItem ); + lst.remove( lastItem ); + } + + // set new list if changed + if( lst.count() != oldCount ) + setItems( lst ); +} + +void TDERecentFilesAction::addURL( const KURL& url ) +{ + addURL( url, url.fileName() ); +} + +void TDERecentFilesAction::addURL( const KURL& url, const TQString& name ) +{ + if ( url.isLocalFile() && !TDEGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/")) + return; + const TQString file = url.pathOrURL(); + TQStringList lst = TDESelectAction::items(); + + // remove file if already in list + const TQStringList::Iterator end = lst.end(); + for ( TQStringList::Iterator it = lst.begin(); it != end; ++it ) + { + TQString title = (*it); + if ( title.endsWith( file + "]" ) ) + { + lst.remove( it ); + d->m_urls.erase( title ); + d->m_shortNames.erase( title ); + break; + } + } + // remove last item if already maxitems in list + if( lst.count() == d->m_maxItems ) + { + // remove last item + const TQString lastItem = lst.last(); + d->m_shortNames.erase( lastItem ); + d->m_urls.erase( lastItem ); + lst.remove( lastItem ); + } + + // add file to list + const TQString title = name + " [" + file + "]"; + d->m_shortNames.insert( title, name ); + d->m_urls.insert( title, url ); + lst.prepend( title ); + setItems( lst ); +} + +void TDERecentFilesAction::removeURL( const KURL& url ) +{ + TQStringList lst = TDESelectAction::items(); + TQString file = url.pathOrURL(); + + // remove url + TQStringList::Iterator end = lst.end(); + for ( TQStringList::Iterator it = lst.begin(); it != end; ++it ) + { + if ( (*it).endsWith( file + "]" )) + { + d->m_shortNames.erase( (*it) ); + d->m_urls.erase( (*it) ); + lst.remove( it ); + setItems( lst ); + break; + } + } +} + +void TDERecentFilesAction::clearURLList() +{ + clear(); + d->m_shortNames.clear(); + d->m_urls.clear(); +} + +void TDERecentFilesAction::loadEntries( TDEConfig* config, TQString groupname) +{ + TQString key; + TQString value; + TQString nameKey; + TQString nameValue; + TQString title; + TQString oldGroup; + TQStringList lst; + KURL url; + + oldGroup = config->group(); + + if (groupname.isEmpty()) + groupname = "RecentFiles"; + config->setGroup( groupname ); + + // read file list + for( unsigned int i = 1 ; i <= d->m_maxItems ; i++ ) + { + key = TQString( "File%1" ).arg( i ); + value = config->readPathEntry( key ); + url = KURL::fromPathOrURL( value ); + + // Don't restore if file doesn't exist anymore + if (url.isLocalFile() && !TQFile::exists(url.path())) + continue; + + nameKey = TQString( "Name%1" ).arg( i ); + nameValue = config->readPathEntry( nameKey, url.fileName() ); + title = nameValue + " [" + value + "]"; + if (!value.isNull()) + { + lst.append( title ); + d->m_shortNames.insert( title, nameValue ); + d->m_urls.insert( title, url ); + } + } + + // set file + setItems( lst ); + + config->setGroup( oldGroup ); +} + +void TDERecentFilesAction::saveEntries( TDEConfig* config, TQString groupname ) +{ + TQString key; + TQString value; + TQString oldGroup; + TQStringList lst = TDESelectAction::items(); + + oldGroup = config->group(); + + if (groupname.isEmpty()) + groupname = "RecentFiles"; + config->deleteGroup( groupname, true ); + config->setGroup( groupname ); + + // write file list + for( unsigned int i = 1 ; i <= lst.count() ; i++ ) + { + //kdDebug(129) << "Entry for " << lst[i-1] << d->m_urls[ lst[ i - 1 ] ] << endl; + key = TQString( "File%1" ).arg( i ); + value = d->m_urls[ lst[ i - 1 ] ].pathOrURL(); + config->writePathEntry( key, value ); + key = TQString( "Name%1" ).arg( i ); + value = d->m_shortNames[ lst[ i - 1 ] ]; + config->writePathEntry( key, value ); + } + + config->setGroup( oldGroup ); +} + +void TDERecentFilesAction::itemSelected( const TQString& text ) +{ + //return a copy of the URL since the slot where it is connected might call + //addURL or removeURL where the d->m_urls.erase( title ) could destroy the + //d->m_urls[ text ] and the emitted URL will be invalid in the rest of the slot + emit urlSelected( KURL(d->m_urls[ text ]) ); +} + +void TDERecentFilesAction::menuItemActivated( int id ) +{ + TQString text = d->m_popup->text(id); + //return a copy of the URL since the slot where it is connected might call + //addURL or removeURL where the d->m_urls.erase( title ) could destroy the + //d->m_urls[ text ] and the emitted URL will be invalid in the rest of the slot + emit urlSelected( KURL(d->m_urls[ text ]) ); +} + +void TDERecentFilesAction::menuAboutToShow() +{ + TDEPopupMenu *menu = d->m_popup; + menu->clear(); + TQStringList list = TDESelectAction::items(); + for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) + { + menu->insertItem(*it); + } +} + +int TDERecentFilesAction::plug( TQWidget *widget, int index ) +{ + if (kapp && !kapp->authorizeTDEAction(name())) + return -1; + // This is very related to TDEActionMenu::plug. + // In fact this class could be an interesting base class for TDEActionMenu + if ( ::tqqt_cast( widget ) ) + { + TDEToolBar *bar = (TDEToolBar *)widget; + + int id_ = TDEAction::getToolButtonID(); + + TDEInstance * instance; + if ( m_parentCollection ) + instance = m_parentCollection->instance(); + else + instance = TDEGlobal::instance(); + + bar->insertButton( icon(), id_, TQT_SIGNAL( clicked() ), this, + TQT_SLOT( slotClicked() ), isEnabled(), plainText(), + index, instance ); + + addContainer( bar, id_ ); + + connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + bar->setDelayedPopup( id_, d->m_popup, true); + + if ( !whatsThis().isEmpty() ) + TQWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() ); + + return containerCount() - 1; + } + + return TDEListAction::plug( widget, index ); +} + +void TDERecentFilesAction::slotClicked() +{ + TDEAction::slotActivated(); +} + +void TDERecentFilesAction::slotActivated(const TQString& text) +{ + TDEListAction::slotActivated(text); +} + + +void TDERecentFilesAction::slotActivated(int id) +{ + TDEListAction::slotActivated(id); +} + + +void TDERecentFilesAction::slotActivated() +{ + emit activated( currentItem() ); + emit activated( currentText() ); +} + +//KDE4: rename to urls() and return a KURL::List +TQStringList TDERecentFilesAction::items() const +{ + TQStringList lst = TDESelectAction::items(); + TQStringList result; + + for( unsigned int i = 1 ; i <= lst.count() ; i++ ) + { + result += d->m_urls[ lst[ i - 1 ] ].prettyURL(0, KURL::StripFileProtocol); + } + + return result; +} + +//KDE4: remove +TQStringList TDERecentFilesAction::completeItems() const +{ + return TDESelectAction::items(); +} + + +class TDEFontAction::TDEFontActionPrivate +{ +public: + TDEFontActionPrivate() + { + } + TQStringList m_fonts; +}; + +TDEFontAction::TDEFontAction( const TQString& text, + const TDEShortcut& cut, TQObject* parent, + const char* name ) + : TDESelectAction( text, cut, parent, name ) +{ + d = new TDEFontActionPrivate; + TDEFontChooser::getFontList( d->m_fonts, 0 ); + TDESelectAction::setItems( d->m_fonts ); + setEditable( true ); +} + +TDEFontAction::TDEFontAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name ) + : TDESelectAction( text, cut, receiver, slot, parent, name ) +{ + d = new TDEFontActionPrivate; + TDEFontChooser::getFontList( d->m_fonts, 0 ); + TDESelectAction::setItems( d->m_fonts ); + setEditable( true ); +} + +TDEFontAction::TDEFontAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDESelectAction( text, pix, cut, parent, name ) +{ + d = new TDEFontActionPrivate; + TDEFontChooser::getFontList( d->m_fonts, 0 ); + TDESelectAction::setItems( d->m_fonts ); + setEditable( true ); +} + +TDEFontAction::TDEFontAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDESelectAction( text, pix, cut, parent, name ) +{ + d = new TDEFontActionPrivate; + TDEFontChooser::getFontList( d->m_fonts, 0 ); + TDESelectAction::setItems( d->m_fonts ); + setEditable( true ); +} + +TDEFontAction::TDEFontAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name ) + : TDESelectAction( text, pix, cut, receiver, slot, parent, name ) +{ + d = new TDEFontActionPrivate; + TDEFontChooser::getFontList( d->m_fonts, 0 ); + TDESelectAction::setItems( d->m_fonts ); + setEditable( true ); +} + +TDEFontAction::TDEFontAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name ) + : TDESelectAction( text, pix, cut, receiver, slot, parent, name ) +{ + d = new TDEFontActionPrivate; + TDEFontChooser::getFontList( d->m_fonts, 0 ); + TDESelectAction::setItems( d->m_fonts ); + setEditable( true ); +} + +TDEFontAction::TDEFontAction( uint fontListCriteria, const TQString& text, + const TDEShortcut& cut, TQObject* parent, + const char* name ) + : TDESelectAction( text, cut, parent, name ) +{ + d = new TDEFontActionPrivate; + TDEFontChooser::getFontList( d->m_fonts, fontListCriteria ); + TDESelectAction::setItems( d->m_fonts ); + setEditable( true ); +} + +TDEFontAction::TDEFontAction( uint fontListCriteria, const TQString& text, const TQString& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDESelectAction( text, pix, cut, parent, name ) +{ + d = new TDEFontActionPrivate; + TDEFontChooser::getFontList( d->m_fonts, fontListCriteria ); + TDESelectAction::setItems( d->m_fonts ); + setEditable( true ); +} + +TDEFontAction::TDEFontAction( TQObject* parent, const char* name ) + : TDESelectAction( parent, name ) +{ + d = new TDEFontActionPrivate; + TDEFontChooser::getFontList( d->m_fonts, 0 ); + TDESelectAction::setItems( d->m_fonts ); + setEditable( true ); +} + +TDEFontAction::~TDEFontAction() +{ + delete d; + d = 0; +} + +/* + * Maintenance note: Keep in sync with TDEFontCombo::setCurrentFont() + */ +void TDEFontAction::setFont( const TQString &family ) +{ + TQString lowerName = family.lower(); + int i = 0; + for ( TQStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) + { + if ((*it).lower() == lowerName) + { + setCurrentItem(i); + return; + } + } + i = lowerName.find(" ["); + if (i>-1) + { + lowerName = lowerName.left(i); + i = 0; + for ( TQStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) + { + if ((*it).lower() == lowerName) + { + setCurrentItem(i); + return; + } + } + } + + lowerName += " ["; + i = 0; + for ( TQStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) + { + if ((*it).lower().startsWith(lowerName)) + { + setCurrentItem(i); + return; + } + } + + // nothing matched yet, try a fontconfig reverse lookup and + // check again to solve an alias + FcPattern *pattern = NULL; + FcConfig *config = NULL; + TQString realFamily; + TQRegExp regExp("[-:]"); + pattern = FcNameParse( (unsigned char*) family.ascii() ); + FcDefaultSubstitute(pattern); + FcConfigSubstitute (config, pattern, FcMatchPattern); + pattern = FcFontMatch(NULL, pattern, NULL); + realFamily = (char*)FcNameUnparse(pattern); + realFamily.remove(realFamily.find(regExp), realFamily.length()); + + if ( !realFamily.isEmpty() && realFamily != family ) + setFont( realFamily ); + else + kdDebug(129) << "Font not found " << family.lower() << endl; +} + +int TDEFontAction::plug( TQWidget *w, int index ) +{ + if (kapp && !kapp->authorizeTDEAction(name())) + return -1; + if ( ::tqqt_cast( w ) ) + { + TDEToolBar* bar = static_cast( w ); + int id_ = TDEAction::getToolButtonID(); + TDEFontCombo *cb = new TDEFontCombo( items(), bar ); + connect( cb, TQT_SIGNAL( activated( const TQString & ) ), + TQT_SLOT( slotActivated( const TQString & ) ) ); + cb->setEnabled( isEnabled() ); + bar->insertWidget( id_, comboWidth(), cb, index ); + cb->setMinimumWidth( cb->sizeHint().width() ); + + addContainer( bar, id_ ); + + connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + updateCurrentItem( containerCount() - 1 ); + + return containerCount() - 1; + } + else return TDESelectAction::plug( w, index ); +} + +class TDEFontSizeAction::TDEFontSizeActionPrivate +{ +public: + TDEFontSizeActionPrivate() + { + } +}; + +TDEFontSizeAction::TDEFontSizeAction( const TQString& text, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDESelectAction( text, cut, parent, name ) +{ + init(); +} + +TDEFontSizeAction::TDEFontSizeAction( const TQString& text, + const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name ) + : TDESelectAction( text, cut, receiver, slot, parent, name ) +{ + init(); +} + +TDEFontSizeAction::TDEFontSizeAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDESelectAction( text, pix, cut, parent, name ) +{ + init(); +} + +TDEFontSizeAction::TDEFontSizeAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDESelectAction( text, pix, cut, parent, name ) +{ + init(); +} + +TDEFontSizeAction::TDEFontSizeAction( const TQString& text, const TQIconSet& pix, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, TQObject* parent, + const char* name ) + : TDESelectAction( text, pix, cut, receiver, slot, parent, name ) +{ + init(); +} + +TDEFontSizeAction::TDEFontSizeAction( const TQString& text, const TQString& pix, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, TQObject* parent, + const char* name ) + : TDESelectAction( text, pix, cut, receiver, slot, parent, name ) +{ + init(); +} + +TDEFontSizeAction::TDEFontSizeAction( TQObject* parent, const char* name ) + : TDESelectAction( parent, name ) +{ + init(); +} + +TDEFontSizeAction::~TDEFontSizeAction() +{ + delete d; + d = 0; +} + +void TDEFontSizeAction::init() +{ + d = new TDEFontSizeActionPrivate; + + setEditable( true ); + TQFontDatabase fontDB; + TQValueList sizes = fontDB.standardSizes(); + TQStringList lst; + for ( TQValueList::Iterator it = sizes.begin(); it != sizes.end(); ++it ) + lst.append( TQString::number( *it ) ); + + setItems( lst ); +} + +void TDEFontSizeAction::setFontSize( int size ) +{ + if ( size == fontSize() ) { + setCurrentItem( items().findIndex( TQString::number( size ) ) ); + return; + } + + if ( size < 1 ) { + kdWarning() << "TDEFontSizeAction: Size " << size << " is out of range" << endl; + return; + } + + int index = items().findIndex( TQString::number( size ) ); + if ( index == -1 ) { + // Insert at the correct position in the list (to keep sorting) + TQValueList lst; + // Convert to list of ints + TQStringList itemsList = items(); + for (TQStringList::Iterator it = itemsList.begin() ; it != itemsList.end() ; ++it) + lst.append( (*it).toInt() ); + // New size + lst.append( size ); + // Sort the list + qHeapSort( lst ); + // Convert back to string list + TQStringList strLst; + for (TQValueList::Iterator it = lst.begin() ; it != lst.end() ; ++it) + strLst.append( TQString::number(*it) ); + TDESelectAction::setItems( strLst ); + // Find new current item + index = lst.findIndex( size ); + setCurrentItem( index ); + } + else + setCurrentItem( index ); + + + //emit TDEAction::activated(); + //emit activated( index ); + //emit activated( TQString::number( size ) ); + //emit fontSizeChanged( size ); +} + +int TDEFontSizeAction::fontSize() const +{ + return currentText().toInt(); +} + +void TDEFontSizeAction::slotActivated( int index ) +{ + TDESelectAction::slotActivated( index ); + + emit fontSizeChanged( items()[ index ].toInt() ); +} + +void TDEFontSizeAction::slotActivated( const TQString& size ) +{ + setFontSize( size.toInt() ); // insert sorted first + TDESelectAction::slotActivated( size ); + emit fontSizeChanged( size.toInt() ); +} + +class TDEActionMenu::TDEActionMenuPrivate +{ +public: + TDEActionMenuPrivate() + { + m_popup = new TDEPopupMenu(0L,"TDEActionMenu::TDEActionMenuPrivate"); + m_delayed = true; + m_stickyMenu = true; + } + ~TDEActionMenuPrivate() + { + delete m_popup; m_popup = 0; + } + TDEPopupMenu *m_popup; + bool m_delayed; + bool m_stickyMenu; +}; + +TDEActionMenu::TDEActionMenu( TQObject* parent, const char* name ) + : TDEAction( parent, name ) +{ + d = new TDEActionMenuPrivate; + setShortcutConfigurable( false ); +} + +TDEActionMenu::TDEActionMenu( const TQString& text, TQObject* parent, + const char* name ) + : TDEAction( text, 0, parent, name ) +{ + d = new TDEActionMenuPrivate; + setShortcutConfigurable( false ); +} + +TDEActionMenu::TDEActionMenu( const TQString& text, const TQIconSet& icon, + TQObject* parent, const char* name ) + : TDEAction( text, icon, 0, parent, name ) +{ + d = new TDEActionMenuPrivate; + setShortcutConfigurable( false ); +} + +TDEActionMenu::TDEActionMenu( const TQString& text, const TQString& icon, + TQObject* parent, const char* name ) + : TDEAction( text, icon, 0, parent, name ) +{ + d = new TDEActionMenuPrivate; + setShortcutConfigurable( false ); +} + +TDEActionMenu::~TDEActionMenu() +{ + unplugAll(); + kdDebug(129) << "TDEActionMenu::~TDEActionMenu()" << endl; // ellis + delete d; d = 0; +} + +void TDEActionMenu::popup( const TQPoint& global ) +{ + popupMenu()->popup( global ); +} + +TDEPopupMenu* TDEActionMenu::popupMenu() const +{ + return d->m_popup; +} + +void TDEActionMenu::insert( TDEAction* cmd, int index ) +{ + if ( cmd ) + cmd->plug( d->m_popup, index ); +} + +void TDEActionMenu::remove( TDEAction* cmd ) +{ + if ( cmd ) + cmd->unplug( d->m_popup ); +} + +bool TDEActionMenu::delayed() const { + return d->m_delayed; +} + +void TDEActionMenu::setDelayed(bool _delayed) { + d->m_delayed = _delayed; +} + +bool TDEActionMenu::stickyMenu() const { + return d->m_stickyMenu; +} + +void TDEActionMenu::setStickyMenu(bool sticky) { + d->m_stickyMenu = sticky; +} + +int TDEActionMenu::plug( TQWidget* widget, int index ) +{ + if (kapp && !kapp->authorizeTDEAction(name())) + return -1; + kdDebug(129) << "TDEActionMenu::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis + if ( ::tqqt_cast( widget ) ) + { + TQPopupMenu* menu = static_cast( widget ); + int id; + if ( hasIcon() ) + id = menu->insertItem( iconSet(), text(), d->m_popup, -1, index ); + else + id = menu->insertItem( text(), d->m_popup, -1, index ); + + if ( !isEnabled() ) + menu->setItemEnabled( id, false ); + + addContainer( menu, id ); + connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + if ( m_parentCollection ) + m_parentCollection->connectHighlight( menu, this ); + + return containerCount() - 1; + } + else if ( ::tqqt_cast( widget ) ) + { + TDEToolBar *bar = static_cast( widget ); + + int id_ = TDEAction::getToolButtonID(); + + if ( icon().isEmpty() && !iconSet().isNull() ) + bar->insertButton( iconSet().pixmap(), id_, TQT_SIGNAL( clicked() ), this, + TQT_SLOT( slotActivated() ), isEnabled(), plainText(), + index ); + else + { + TDEInstance *instance; + + if ( m_parentCollection ) + instance = m_parentCollection->instance(); + else + instance = TDEGlobal::instance(); + + bar->insertButton( icon(), id_, TQT_SIGNAL( clicked() ), this, + TQT_SLOT( slotActivated() ), isEnabled(), plainText(), + index, instance ); + } + + addContainer( bar, id_ ); + + if (!whatsThis().isEmpty()) + TQWhatsThis::add( bar->getButton(id_), whatsThis() ); + + connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + if (delayed()) { + bar->setDelayedPopup( id_, popupMenu(), stickyMenu() ); + } else { + bar->getButton(id_)->setPopup(popupMenu(), stickyMenu() ); + } + + if ( m_parentCollection ) + m_parentCollection->connectHighlight( bar, this ); + + return containerCount() - 1; + } + else if ( ::tqqt_cast( widget ) ) + { + TQMenuBar *bar = static_cast( widget ); + + int id; + + id = bar->insertItem( text(), popupMenu(), -1, index ); + + if ( !isEnabled() ) + bar->setItemEnabled( id, false ); + + addContainer( bar, id ); + connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + return containerCount() - 1; + } + + return -1; +} + +//////// + +TDEToolBarPopupAction::TDEToolBarPopupAction( const TQString& text, + const TQString& icon, + const TDEShortcut& cut, + TQObject* parent, const char* name ) + : TDEAction( text, icon, cut, parent, name ) +{ + m_popup = 0; + m_delayed = true; + m_stickyMenu = true; +} + +TDEToolBarPopupAction::TDEToolBarPopupAction( const TQString& text, + const TQString& icon, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, TQObject* parent, + const char* name ) + : TDEAction( text, icon, cut, receiver, slot, parent, name ) +{ + m_popup = 0; + m_delayed = true; + m_stickyMenu = true; +} + +TDEToolBarPopupAction::TDEToolBarPopupAction( const KGuiItem& item, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, TDEActionCollection* parent, + const char* name ) + : TDEAction( item, cut, receiver, slot, parent, name ) +{ + m_popup = 0; + m_delayed = true; + m_stickyMenu = true; +} + +TDEToolBarPopupAction::~TDEToolBarPopupAction() +{ + delete m_popup; +} + +bool TDEToolBarPopupAction::delayed() const { + return m_delayed; +} + +void TDEToolBarPopupAction::setDelayed(bool delayed) { + m_delayed = delayed; +} + +bool TDEToolBarPopupAction::stickyMenu() const { + return m_stickyMenu; +} + +void TDEToolBarPopupAction::setStickyMenu(bool sticky) { + m_stickyMenu = sticky; +} + +int TDEToolBarPopupAction::plug( TQWidget *widget, int index ) +{ + if (kapp && !kapp->authorizeTDEAction(name())) + return -1; + // This is very related to TDEActionMenu::plug. + // In fact this class could be an interesting base class for TDEActionMenu + if ( ::tqqt_cast( widget ) ) + { + TDEToolBar *bar = (TDEToolBar *)widget; + + int id_ = TDEAction::getToolButtonID(); + + if ( icon().isEmpty() && !iconSet().isNull() ) { + bar->insertButton( iconSet().pixmap(), id_, TQT_SIGNAL( buttonClicked(int, TQt::ButtonState) ), this, + TQT_SLOT( slotButtonClicked(int, TQt::ButtonState) ), + isEnabled(), plainText(), + index ); + } else { + TDEInstance * instance; + if ( m_parentCollection ) + instance = m_parentCollection->instance(); + else + instance = TDEGlobal::instance(); + + bar->insertButton( icon(), id_, TQT_SIGNAL( buttonClicked(int, TQt::ButtonState) ), this, + TQT_SLOT( slotButtonClicked(int, TQt::ButtonState) ), + isEnabled(), plainText(), + index, instance ); + } + + addContainer( bar, id_ ); + + connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + if (delayed()) { + bar->setDelayedPopup( id_, popupMenu(), stickyMenu() ); + } else { + bar->getButton(id_)->setPopup(popupMenu(), stickyMenu()); + } + + if ( !whatsThis().isEmpty() ) + TQWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() ); + + return containerCount() - 1; + } + + return TDEAction::plug( widget, index ); +} + +TDEPopupMenu *TDEToolBarPopupAction::popupMenu() const +{ + if ( !m_popup ) { + TDEToolBarPopupAction *that = const_cast(this); + that->m_popup = new TDEPopupMenu; + } + return m_popup; +} + +//////// + +TDEToggleToolBarAction::TDEToggleToolBarAction( const char* toolBarName, + const TQString& text, TDEActionCollection* parent, const char* name ) + : TDEToggleAction( text, TDEShortcut(), parent, name ) + , m_toolBarName( toolBarName ) + , m_toolBar( 0L ) +{ +} + +TDEToggleToolBarAction::TDEToggleToolBarAction( TDEToolBar *toolBar, const TQString &text, + TDEActionCollection *parent, const char *name ) + : TDEToggleAction( text, TDEShortcut(), parent, name ) + , m_toolBarName( 0 ), m_toolBar( toolBar ) +{ +} + +TDEToggleToolBarAction::~TDEToggleToolBarAction() +{ +} + +int TDEToggleToolBarAction::plug( TQWidget* w, int index ) +{ + if (kapp && !kapp->authorizeTDEAction(name())) + return -1; + + if ( !m_toolBar ) { + // Note: topLevelWidget() stops too early, we can't use it. + TQWidget * tl = w; + TQWidget * n; + while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store + tl = n; + + TDEMainWindow * mw = tqt_dynamic_cast(tl); // try to see if it's a kmainwindow + + if ( mw ) + m_toolBar = mw->toolBar( m_toolBarName ); + } + + if( m_toolBar ) { + setChecked( m_toolBar->isVisible() ); + connect( m_toolBar, TQT_SIGNAL(visibilityChanged(bool)), this, TQT_SLOT(setChecked(bool)) ); + // Also emit toggled when the toolbar's visibility changes (see comment in header) + connect( m_toolBar, TQT_SIGNAL(visibilityChanged(bool)), this, TQT_SIGNAL(toggled(bool)) ); + } else { + setEnabled( false ); + } + + return TDEToggleAction::plug( w, index ); +} + +void TDEToggleToolBarAction::setChecked( bool c ) +{ + if( m_toolBar && c != m_toolBar->isVisible() ) { + if( c ) { + m_toolBar->show(); + } else { + m_toolBar->hide(); + } + TQMainWindow* mw = m_toolBar->mainWindow(); + if ( mw && ::tqqt_cast( mw ) ) + static_cast( mw )->setSettingsDirty(); + } + TDEToggleAction::setChecked( c ); +} + +//////// + +TDEToggleFullScreenAction::TDEToggleFullScreenAction( const TDEShortcut &cut, + const TQObject* receiver, const char* slot, + TQObject* parent, TQWidget* window, + const char* name ) + : TDEToggleAction( TQString::null, cut, receiver, slot, parent, name ), + window( NULL ) +{ + setWindow( window ); +} + +TDEToggleFullScreenAction::~TDEToggleFullScreenAction() +{ +} + +void TDEToggleFullScreenAction::setWindow( TQWidget* w ) +{ + if( window ) + window->removeEventFilter( this ); + window = w; + if( window ) + window->installEventFilter( this ); +} + +void TDEToggleFullScreenAction::setChecked( bool c ) +{ + if (c) + { + setText(i18n("Exit F&ull Screen Mode")); + setIcon("window_nofullscreen"); + } + else + { + setText(i18n("F&ull Screen Mode")); + setIcon("window_fullscreen"); + } + TDEToggleAction::setChecked( c ); +} + +bool TDEToggleFullScreenAction::eventFilter( TQObject* o, TQEvent* e ) +{ + if( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(window) ) + if( e->type() == TQEvent::WindowStateChange ) + { + if( window->isFullScreen() != isChecked()) + slotActivated(); // setChecked( window->isFullScreen()) wouldn't emit signals + } + return false; +} + +//////// + +KWidgetAction::KWidgetAction( TQWidget* widget, + const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TDEActionCollection* parent, const char* name ) + : TDEAction( text, cut, receiver, slot, parent, name ) + , m_widget( widget ) + , m_autoSized( false ) +{ + connect( this, TQT_SIGNAL(enabled(bool)), widget, TQT_SLOT(setEnabled(bool)) ); +} + +KWidgetAction::~KWidgetAction() +{ +} + +void KWidgetAction::setAutoSized( bool autoSized ) +{ + if( m_autoSized == autoSized ) + return; + + m_autoSized = autoSized; + + if( !m_widget || !isPlugged() ) + return; + + TDEToolBar* toolBar = (TDEToolBar*)m_widget->parent(); + int i = findContainer( toolBar ); + if ( i == -1 ) + return; + int id = itemId( i ); + + toolBar->setItemAutoSized( id, m_autoSized ); +} + +int KWidgetAction::plug( TQWidget* w, int index ) +{ + if (kapp && !kapp->authorizeTDEAction(name())) + return -1; + + if ( !::tqqt_cast( w ) ) { + kdError() << "KWidgetAction::plug: KWidgetAction must be plugged into TDEToolBar." << endl; + return -1; + } + if ( !m_widget ) { + kdError() << "KWidgetAction::plug: Widget was deleted or null!" << endl; + return -1; + } + + TDEToolBar* toolBar = static_cast( w ); + + int id = TDEAction::getToolButtonID(); + + m_widget->reparent( toolBar, TQPoint() ); + toolBar->insertWidget( id, 0, m_widget, index ); + toolBar->setItemAutoSized( id, m_autoSized ); + + TQWhatsThis::add( m_widget, whatsThis() ); + addContainer( toolBar, id ); + + connect( toolBar, TQT_SIGNAL( toolbarDestroyed() ), this, TQT_SLOT( slotToolbarDestroyed() ) ); + connect( toolBar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + return containerCount() - 1; +} + +void KWidgetAction::unplug( TQWidget *w ) +{ + if( !m_widget || !isPlugged() ) + return; + + TDEToolBar* toolBar = (TDEToolBar*)m_widget->parent(); + if ( toolBar == w ) + { + disconnect( toolBar, TQT_SIGNAL( toolbarDestroyed() ), this, TQT_SLOT( slotToolbarDestroyed() ) ); + m_widget->reparent( 0L, TQPoint(), false /*showIt*/ ); + } + TDEAction::unplug( w ); +} + +void KWidgetAction::slotToolbarDestroyed() +{ + //Q_ASSERT( m_widget ); // When exiting the app the widget could be destroyed before the toolbar. + Q_ASSERT( isPlugged() ); + if( !m_widget || !isPlugged() ) + return; + + // Don't let a toolbar being destroyed, delete my widget. + m_widget->reparent( 0L, TQPoint(), false /*showIt*/ ); +} + +//////// + +TDEActionSeparator::TDEActionSeparator( TQObject *parent, const char *name ) + : TDEAction( parent, name ) +{ +} + +TDEActionSeparator::~TDEActionSeparator() +{ +} + +int TDEActionSeparator::plug( TQWidget *widget, int index ) +{ + if ( ::tqqt_cast( widget) ) + { + TQPopupMenu* menu = static_cast( widget ); + + int id = menu->insertSeparator( index ); + + addContainer( menu, id ); + connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + return containerCount() - 1; + } + else if ( ::tqqt_cast( widget ) ) + { + TQMenuBar *menuBar = static_cast( widget ); + + int id = menuBar->insertSeparator( index ); + + addContainer( menuBar, id ); + + connect( menuBar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + return containerCount() - 1; + } + else if ( ::tqqt_cast( widget ) ) + { + TDEToolBar *toolBar = static_cast( widget ); + + int id = toolBar->insertSeparator( index ); + + addContainer( toolBar, id ); + + connect( toolBar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + return containerCount() - 1; + } + + return -1; +} + +TDEPasteTextAction::TDEPasteTextAction( const TQString& text, + const TQString& icon, + const TDEShortcut& cut, + const TQObject* receiver, + const char* slot, TQObject* parent, + const char* name) + : TDEAction( text, icon, cut, receiver, slot, parent, name ) +{ + m_popup = new TDEPopupMenu; + connect(m_popup, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(menuAboutToShow())); + connect(m_popup, TQT_SIGNAL(activated(int)), this, TQT_SLOT(menuItemActivated(int))); + m_popup->setCheckable(true); + m_mixedMode = true; +} + +TDEPasteTextAction::~TDEPasteTextAction() +{ + delete m_popup; +} + +void TDEPasteTextAction::setMixedMode(bool mode) +{ + m_mixedMode = mode; +} + +int TDEPasteTextAction::plug( TQWidget *widget, int index ) +{ + if (kapp && !kapp->authorizeTDEAction(name())) + return -1; + if ( ::tqqt_cast( widget ) ) + { + TDEToolBar *bar = (TDEToolBar *)widget; + + int id_ = TDEAction::getToolButtonID(); + + TDEInstance * instance; + if ( m_parentCollection ) + instance = m_parentCollection->instance(); + else + instance = TDEGlobal::instance(); + + bar->insertButton( icon(), id_, TQT_SIGNAL( clicked() ), this, + TQT_SLOT( slotActivated() ), isEnabled(), plainText(), + index, instance ); + + addContainer( bar, id_ ); + + connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + bar->setDelayedPopup( id_, m_popup, true ); + + if ( !whatsThis().isEmpty() ) + TQWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() ); + + return containerCount() - 1; + } + + return TDEAction::plug( widget, index ); +} + +void TDEPasteTextAction::menuAboutToShow() +{ + m_popup->clear(); + TQStringList list; + DCOPClient *client = kapp->dcopClient(); + if (client->isAttached() && client->isApplicationRegistered("klipper")) { + DCOPRef klipper("klipper","klipper"); + DCOPReply reply = klipper.call("getClipboardHistoryMenu"); + if (reply.isValid()) + list = reply; + } + TQString clipboardText = tqApp->clipboard()->text(TQClipboard::Clipboard); + if (list.isEmpty()) + list << clipboardText; + bool found = false; + for ( TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) + { + TQString text = KStringHandler::cEmSqueeze((*it).simplifyWhiteSpace(), m_popup->fontMetrics(), 20); + text.replace("&", "&&"); + int id = m_popup->insertItem(text); + if (!found && *it == clipboardText) + { + m_popup->setItemChecked(id, true); + found = true; + } + } +} + +void TDEPasteTextAction::menuItemActivated( int id) +{ + DCOPClient *client = kapp->dcopClient(); + if (client->isAttached() && client->isApplicationRegistered("klipper")) { + DCOPRef klipper("klipper","klipper"); + DCOPReply reply = klipper.call("getClipboardHistoryItem(int)", m_popup->indexOf(id)); + if (!reply.isValid()) + return; + TQString clipboardText = reply; + reply = klipper.call("setClipboardContents(TQString)", clipboardText); + if (reply.isValid()) + kdDebug(129) << "Clipboard: " << TQString(tqApp->clipboard()->text(TQClipboard::Clipboard)) << endl; + } + TQTimer::singleShot(20, this, TQT_SLOT(slotActivated())); +} + +void TDEPasteTextAction::slotActivated() +{ + if (!m_mixedMode) { + TQWidget *w = tqApp->widgetAt(TQCursor::pos(), true); + TQMimeSource *data = TQApplication::clipboard()->data(); + if (!data->provides("text/plain") && w) { + m_popup->popup(w->mapToGlobal(TQPoint(0, w->height()))); + } else + TDEAction::slotActivated(); + } else + TDEAction::slotActivated(); +} + + +void TDEToggleAction::virtual_hook( int id, void* data ) +{ TDEAction::virtual_hook( id, data ); } + +void TDERadioAction::virtual_hook( int id, void* data ) +{ TDEToggleAction::virtual_hook( id, data ); } + +void TDESelectAction::virtual_hook( int id, void* data ) +{ TDEAction::virtual_hook( id, data ); } + +void TDEListAction::virtual_hook( int id, void* data ) +{ TDESelectAction::virtual_hook( id, data ); } + +void TDERecentFilesAction::virtual_hook( int id, void* data ) +{ TDEListAction::virtual_hook( id, data ); } + +void TDEFontAction::virtual_hook( int id, void* data ) +{ TDESelectAction::virtual_hook( id, data ); } + +void TDEFontSizeAction::virtual_hook( int id, void* data ) +{ TDESelectAction::virtual_hook( id, data ); } + +void TDEActionMenu::virtual_hook( int id, void* data ) +{ TDEAction::virtual_hook( id, data ); } + +void TDEToolBarPopupAction::virtual_hook( int id, void* data ) +{ TDEAction::virtual_hook( id, data ); } + +void TDEToggleToolBarAction::virtual_hook( int id, void* data ) +{ TDEToggleAction::virtual_hook( id, data ); } + +void TDEToggleFullScreenAction::virtual_hook( int id, void* data ) +{ TDEToggleAction::virtual_hook( id, data ); } + +void KWidgetAction::virtual_hook( int id, void* data ) +{ TDEAction::virtual_hook( id, data ); } + +void TDEActionSeparator::virtual_hook( int id, void* data ) +{ TDEAction::virtual_hook( id, data ); } + +void TDEPasteTextAction::virtual_hook( int id, void* data ) +{ TDEAction::virtual_hook( id, data ); } + +/* vim: et sw=2 ts=2 + */ + +#include "kactionclasses.moc" diff --git a/tdeui/tdeactionclasses.h b/tdeui/tdeactionclasses.h new file mode 100644 index 000000000..07078a722 --- /dev/null +++ b/tdeui/tdeactionclasses.h @@ -0,0 +1,1436 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999 Reginald Stadlbauer + (C) 1999 Simon Hausmann + (C) 2000 Nicolas Hadacek + (C) 2000 Kurt Granroth + (C) 2000 Michael Koch + (C) 2001 Holger Freyther + (C) 2002 Ellis Whitehead + (C) 2003 Andras Mantia + + 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. +*/ +//$Id$ + +#ifndef __kactionclasses_h__ +#define __kactionclasses_h__ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +class TQMenuBar; +class TQPopupMenu; +class TQComboBox; +class TQPoint; +class TQIconSet; +class TQString; +class TDEToolBar; + +class TDEAccel; +class TDEAccelActions; +class TDEConfig; +class TDEConfigBase; +class KURL; +class TDEInstance; +class TDEToolBar; +class TDEActionCollection; +class TDEPopupMenu; +class TDEMainWindow; + +/** + * @short Checkbox like action. + * + * Checkbox like action. + * + * This action provides two states: checked or not. + * + */ +class TDEUI_EXPORT TDEToggleAction : public TDEAction +{ + Q_OBJECT + + TQ_PROPERTY( bool checked READ isChecked WRITE setChecked ) + TQ_PROPERTY( TQString exclusiveGroup READ exclusiveGroup WRITE setExclusiveGroup ) +public: + + /** + * Constructs a toggle action with text and potential keyboard + * accelerator but nothing else. Use this only if you really + * know what you are doing. + * + * @param text The text that will be displayed. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToggleAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToggleAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The icons that go with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToggleAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The dynamically loaded icon that goes with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToggleAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The icons that go with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToggleAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The dynamically loaded icon that goes with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToggleAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name = 0 ); + + /** + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToggleAction( TQObject* parent = 0, const char* name = 0 ); + + /** + * Destructor + */ + virtual ~TDEToggleAction(); + + /** + * "Plug" or insert this action into a given widget. + * + * This will typically be a menu or a toolbar. From this point + * on, you will never need to directly manipulate the item in the + * menu or toolbar. You do all enabling/disabling/manipulation + * directly with your TDEToggleAction object. + * + * @param widget The GUI element to display this action. + * @param index The index of the item. + */ + virtual int plug( TQWidget* widget, int index = -1 ); + + /** + * Returns the actual state of the action. + */ + bool isChecked() const; + + /** + * @return which "exclusive group" this action is part of. + * @see setExclusiveGroup + */ + TQString exclusiveGroup() const; + + /** + * Defines which "exclusive group" this action is part of. + * In a given exclusive group, only one toggle action can be checked + * at a any moment. Checking an action unchecks the other actions + * of the group. + */ + virtual void setExclusiveGroup( const TQString& name ); + + /** + * Defines the text (and icon, tooltip, whatsthis) that should be displayed + * instead of the normal text, when the action is checked. + * This feature replaces the checkmark that usually appears in front of the text, in menus. + * It is useful when the text is mainly a verb: e.g. "Show " + * should turn into "Hide " when activated. + * + * If hasIcon(), the icon is kept for the 'checked state', unless + * @p checkedItem defines an icon explicitely. Same thing for tooltip and whatsthis. + * @since 3.3 + */ + void setCheckedState( const KGuiItem& checkedItem ); + + /// Reimplemented for internal reasons + virtual TQString toolTip() const; + +public slots: + /** + * Sets the state of the action. + */ + virtual void setChecked( bool ); + +protected slots: + virtual void slotActivated(); + +protected: + virtual void updateChecked( int id ); + +signals: + void toggled( bool ); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEToggleActionPrivate; + TDEToggleActionPrivate *d; +}; + +/** + * @short Radiobox like action. + * + * An action that operates like a radio button. At any given time + * only a single action from the group will be active. + */ +class TDEUI_EXPORT TDERadioAction : public TDEToggleAction +{ + Q_OBJECT + +public: + /** + * Constructs a radio action with text and potential keyboard + * accelerator but nothing else. Use this only if you really + * know what you are doing. + * + * @param text The text that will be displayed. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDERadioAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDERadioAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The icons that go with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDERadioAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The dynamically loaded icon that goes with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDERadioAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The icons that go with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDERadioAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The dynamically loaded icon that goes with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDERadioAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name = 0 ); + + /** + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDERadioAction( TQObject* parent = 0, const char* name = 0 ); + +protected: + virtual void slotActivated(); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDERadioActionPrivate; + TDERadioActionPrivate *d; +}; + +/** + * @short Action for selecting one of several items + * + * Action for selecting one of several items. + * + * This action shows up a submenu with a list of items. + * One of them can be checked. If the user clicks on an item + * this item will automatically be checked, + * the formerly checked item becomes unchecked. + * There can be only one item checked at a time. + */ +class TDEUI_EXPORT TDESelectAction : public TDEAction +{ + Q_OBJECT + + TQ_PROPERTY( int currentItem READ currentItem WRITE setCurrentItem ) + TQ_PROPERTY( TQStringList items READ items WRITE setItems ) + TQ_PROPERTY( bool editable READ isEditable WRITE setEditable ) + TQ_PROPERTY( int comboWidth READ comboWidth WRITE setComboWidth ) + TQ_PROPERTY( TQString currentText READ currentText ) + TQ_PROPERTY( bool menuAccelsEnabled READ menuAccelsEnabled WRITE setMenuAccelsEnabled ) +public: + + /** + * Constructs a select action with text and potential keyboard + * accelerator but nothing else. Use this only if you really + * know what you are doing. + * + * @param text The text that will be displayed. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDESelectAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDESelectAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The icons that go with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDESelectAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The dynamically loaded icon that goes with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDESelectAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The icons that go with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDESelectAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The dynamically loaded icon that goes with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDESelectAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name = 0 ); + + /** + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDESelectAction( TQObject* parent = 0, const char* name = 0 ); + + /** + * Destructor + */ + virtual ~TDESelectAction(); + + /** + * "Plug" or insert this action into a given widget. + * + * This will typically be a menu or a toolbar. + * From this point on, you will never need to directly + * manipulate the item in the menu or toolbar. + * You do all enabling/disabling/manipulation directly with your TDESelectAction object. + * + * @param widget The GUI element to display this action. + * @param index The index of the item. + */ + virtual int plug( TQWidget* widget, int index = -1 ); + + /** + * When this action is plugged into a toolbar, it creates a combobox. + * @return true if the combo editable. + */ + virtual bool isEditable() const; + + /** + * @return the items that can be selected with this action. + * Use setItems to set them. + */ + virtual TQStringList items() const; + + /** + * Changes the text of item @param index to @param text . + */ + virtual void changeItem( int index, const TQString& text ); + + /** + * Returns the text of the currently selected item. + */ + virtual TQString currentText() const; + + /** + * Returns the index of the current item. + * @see setCurrentItem + */ + virtual int currentItem() const; + + /** + * When this action is plugged into a toolbar, it creates a combobox. + * This returns the maximum width set by setComboWidth + */ + virtual int comboWidth() const; + + /** + * Sets the maximum items that are visible at once if the action + * is a combobox, that is the number of items in the combobox's viewport + * Only works before the action is plugged + * @since 3.5 + */ + void setMaxComboViewCount( int n ); + + /** + * Returns a pointer to the popup menu used by this action. + */ + TQPopupMenu* popupMenu() const; + + /** + * @deprecated See setMenuAccelsEnabled . + * @since 3.1 + */ + void setRemoveAmpersandsInCombo( bool b ) KDE_DEPRECATED; + /// @since 3.1 + bool removeAmpersandsInCombo() const; + + /** + * Sets whether any occurrence of the ampersand character ( & ) in items + * should be interpreted as keyboard accelerator for items displayed in a + * menu or not. + * @since 3.1 + */ + void setMenuAccelsEnabled( bool b ); + /// @since 3.1 + bool menuAccelsEnabled() const; + + virtual bool isShortcutConfigurable() const { return false; } + +public slots: + /** + * Sets the currently checked item. + * + * @param index Index of the item (remember the first item is zero). + */ + virtual void setCurrentItem( int index ); + + /** + * Sets the items to be displayed in this action + * You need to call this. + */ + virtual void setItems( const TQStringList &lst ); + + /** + * Clears up all the items in this action + */ + virtual void clear(); + + /** + * When this action is plugged into a toolbar, it creates a combobox. + * This makes the combo editable or read-only. + */ + virtual void setEditable( bool ); + + /** + * When this action is plugged into a toolbar, it creates a combobox. + * This gives a _maximum_ size to the combobox. + * The minimum size is automatically given by the contents (the items). + */ + virtual void setComboWidth( int width ); + +protected: + virtual void changeItem( int id, int index, const TQString& text ); + + /** + * Depending on the menuAccelsEnabled property this method will return the + * actions items in a way for inclusion in a combobox with the ampersand + * character removed from all items or not. + * @since 3.1 + */ + TQStringList comboItems() const; + +protected slots: + virtual void slotActivated( int id ); + virtual void slotActivated( const TQString &text ); + virtual void slotActivated(); + +signals: + /** + * This signal is emitted when an item is selected; @param index indicated + * the item selected. + */ + void activated( int index ); + /** + * This signal is emitted when an item is selected; @param text indicates + * the item selected. + */ + void activated( const TQString& text ); + +protected: + virtual void updateCurrentItem( int id ); + + virtual void updateComboWidth( int id ); + + virtual void updateItems( int id ); + + virtual void updateClear( int id ); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + void setupMenu() const; + class TDESelectActionPrivate; + TDESelectActionPrivate *d; + +}; + +/// Remove this class in KDE-4.0. It doesn't add _anything_ to TDESelectAction +/** + * @deprecated Use TDESelectAction instead. + */ +class TDEUI_EXPORT_DEPRECATED TDEListAction : public TDESelectAction +{ + Q_OBJECT + +public: + /** + * Constructs a list action with text and potential keyboard + * accelerator but nothing else. Use this only if you really + * know what you are doing. + * + * @param text The text that will be displayed. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEListAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, + const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEListAction( const TQString& text, const TDEShortcut& cut, const TQObject* receiver, + const char* slot, TQObject* parent, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The icons that go with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEListAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The dynamically loaded icon that goes with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEListAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The icons that go with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEListAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, + const char* name = 0 ); + + /** + * @param text The text that will be displayed. + * @param pix The dynamically loaded icon that goes with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEListAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, + const char* name = 0 ); + + /** + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEListAction( TQObject* parent = 0, const char* name = 0 ); + + /** + * Destructor + */ + virtual ~TDEListAction(); + + + virtual TQString currentText() const; + virtual int currentItem() const; + + +public slots: + /** + * Sets the currently checked item. + * + * @param index Index of the item (remember the first item is zero). + */ + virtual void setCurrentItem( int index ); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEListActionPrivate; + TDEListActionPrivate *d; +}; + +/** + * @short Recent files action + * + * This class is an action to handle a recent files submenu. + * The best way to create the action is to use KStdAction::openRecent. + * Then you simply need to call loadEntries on startup, saveEntries + * on shutdown, addURL when your application loads/saves a file. + * + * @author Michael Koch + */ +class TDEUI_EXPORT TDERecentFilesAction : public TDEListAction // TODO public TDESelectAction +{ + Q_OBJECT + + TQ_PROPERTY( uint maxItems READ maxItems WRITE setMaxItems ) +public: + /** + * @param text The text that will be displayed. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + * @param maxItems The maximum number of files to display + */ + TDERecentFilesAction( const TQString& text, const TDEShortcut& cut, + TQObject* parent, const char* name = 0, + uint maxItems = 10 ); + + /** + * @param text The text that will be displayed. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke when a URL is selected. + * Its signature is of the form slotURLSelected( const KURL & ). + * @param parent This action's parent. + * @param name An internal name for this action. + * @param maxItems The maximum number of files to display + */ + TDERecentFilesAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name = 0, + uint maxItems = 10 ); + + /** + * @param text The text that will be displayed. + * @param pix The icons that go with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + * @param maxItems The maximum number of files to display + */ + TDERecentFilesAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, + TQObject* parent, const char* name = 0, + uint maxItems = 10 ); + + /** + * @param text The text that will be displayed. + * @param pix The dynamically loaded icon that goes with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + * @param maxItems The maximum number of files to display + */ + TDERecentFilesAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, + TQObject* parent, const char* name = 0, + uint maxItems = 10 ); + + /** + * @param text The text that will be displayed. + * @param pix The icons that go with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke when a URL is selected. + * Its signature is of the form slotURLSelected( const KURL & ). + * @param parent This action's parent. + * @param name An internal name for this action. + * @param maxItems The maximum number of files to display + */ + TDERecentFilesAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name = 0, + uint maxItems = 10 ); + + /** + * @param text The text that will be displayed. + * @param pix The dynamically loaded icon that goes with this action. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke when a URL is selected. + * Its signature is of the form slotURLSelected( const KURL & ). + * @param parent This action's parent. + * @param name An internal name for this action. + * @param maxItems The maximum number of files to display + */ + TDERecentFilesAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name = 0, + uint maxItems = 10 ); + + /** + * @param parent This action's parent. + * @param name An internal name for this action. + * @param maxItems The maximum number of files to display + */ + TDERecentFilesAction( TQObject* parent = 0, const char* name = 0, + uint maxItems = 10 ); + + /** + * Destructor. + */ + virtual ~TDERecentFilesAction(); + + virtual int plug( TQWidget *widget, int index = -1 ); + + /** + * Returns the maximum of items in the recent files list. + */ + uint maxItems() const; + +//KDE4: remove completeItems() and rename items() to urls(), to get the list of URLs added to +// the action. + /** + * @return the items that can be selected with this action. + * The returned items do not contain the pretty name that can be set by addURL, + * matching the pre-3.5 behavior. + */ + + virtual TQStringList items() const; + + /** + * @return the items that can be selected with this action. + * The returned items contain the pretty name that can be set by addURL. + * @since 3.5 + */ + TQStringList completeItems() const; + +public slots: + /** + * Sets the maximum of items in the recent files list. + * The default for this value is 10 set in the constructor. + * + * If this value is lesser than the number of items currently + * in the recent files list the last items are deleted until + * the number of items are equal to the new maximum. + */ + void setMaxItems( uint maxItems ); + + /** + * Loads the recent files entries from a given TDEConfig object. + * You can provide the name of the group used to load the entries. + * If the groupname is empty, entries are load from a group called 'RecentFiles' + * + * This method does not effect the active group of TDEConfig. + */ + void loadEntries( TDEConfig* config, TQString groupname=TQString::null ); + + /** + * Saves the current recent files entries to a given TDEConfig object. + * You can provide the name of the group used to load the entries. + * If the groupname is empty, entries are saved to a group called 'RecentFiles' + * + * This method does not effect the active group of TDEConfig. + */ + void saveEntries( TDEConfig* config, TQString groupname=TQString::null ); + + /** + * Add URL to recent files list. + * + * @param url The URL of the file + */ + void addURL( const KURL& url ); + + /** + * Add URL to recent files list. + * + * @param url The URL of the file + * @param name The user visible pretty name that appears before the URL + * @since 3.5 + */ + void addURL( const KURL& url, const TQString& name ); //KDE4: Combine the above two methods + + /** + * Remove an URL from the recent files list. + * + * @param url The URL of the file + */ + void removeURL( const KURL& url ); + + /** + * Removes all entries from the recent files list. + */ + void clearURLList(); + +signals: + + /** + * This signal gets emited when the user selects an URL. + * + * @param url The URL thats the user selected. + */ + void urlSelected( const KURL& url ); + +protected slots: + void itemSelected( const TQString& string ); + void menuAboutToShow(); + void menuItemActivated( int id ); + void slotClicked(); + virtual void slotActivated(int); + virtual void slotActivated(const TQString& ); + virtual void slotActivated(); + +protected: + virtual void virtual_hook( int id, void* data ); + +private: + void init(); + + class TDERecentFilesActionPrivate; + TDERecentFilesActionPrivate *d; +}; + +class TDEUI_EXPORT TDEFontAction : public TDESelectAction +{ + Q_OBJECT + + TQ_PROPERTY( TQString font READ font WRITE setFont ) +public: + TDEFontAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, + const char* name = 0 ); + TDEFontAction( const TQString& text, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, + const char* name = 0 ); + TDEFontAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + TDEFontAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + TDEFontAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, + const char* name = 0 ); + TDEFontAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, TQObject* parent, + const char* name = 0 ); + +// The ctors with fontListCriteria were added after 3.3-beta1. +// This define is used in koffice. Remove when koffice has a dependency on tdelibs-3.3 or more. +#define KFONTACTION_HAS_CRITERIA_ARG + TDEFontAction( uint fontListCriteria, const TQString& text, + const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, + const char* name = 0 ); + TDEFontAction( uint fontListCriteria, const TQString& text, const TQString& pix, + const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + + TDEFontAction( TQObject* parent = 0, const char* name = 0 ); + ~TDEFontAction(); + + TQString font() const { + return currentText(); + } + + int plug( TQWidget*widget, int index = -1 ); + +public slots: + void setFont( const TQString &family ); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEFontActionPrivate; + TDEFontActionPrivate *d; +}; + +class TDEUI_EXPORT TDEFontSizeAction : public TDESelectAction +{ + Q_OBJECT + + TQ_PROPERTY( int fontSize READ fontSize WRITE setFontSize ) +public: + TDEFontSizeAction( const TQString& text, const TDEShortcut& cut = TDEShortcut(), TQObject* parent = 0, + const char* name = 0 ); + TDEFontSizeAction( const TQString& text, const TDEShortcut& cut, const TQObject* receiver, + const char* slot, TQObject* parent, const char* name = 0 ); + TDEFontSizeAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + TDEFontSizeAction( const TQString& text, const TQString& pix, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + TDEFontSizeAction( const TQString& text, const TQIconSet& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name = 0 ); + TDEFontSizeAction( const TQString& text, const TQString& pix, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent, const char* name = 0 ); + TDEFontSizeAction( TQObject* parent = 0, const char* name = 0 ); + + virtual ~TDEFontSizeAction(); + + virtual int fontSize() const; + +public slots: + virtual void setFontSize( int size ); + +protected slots: + virtual void slotActivated( int ); + virtual void slotActivated( const TQString& ); + virtual void slotActivated() { TDEAction::slotActivated(); } + +signals: + void fontSizeChanged( int ); + +private: + void init(); + + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEFontSizeActionPrivate; + TDEFontSizeActionPrivate *d; +}; + + +/** + * A TDEActionMenu is an action that holds a sub-menu of other actions. + * insert() and remove() allow to insert and remove actions into this action-menu. + * Plugged in a popupmenu, it will create a submenu. + * Plugged in a toolbar, it will create a button with a popup menu. + * + * This is the action used by the XMLGUI since it holds other actions. + * If you want a submenu for selecting one tool among many (without icons), see TDESelectAction. + * See also setDelayed about the main action. + */ +class TDEUI_EXPORT TDEActionMenu : public TDEAction +{ + Q_OBJECT + + TQ_PROPERTY( bool delayed READ delayed WRITE setDelayed ) + TQ_PROPERTY( bool stickyMenu READ stickyMenu WRITE setStickyMenu ) + +public: + TDEActionMenu( const TQString& text, TQObject* parent = 0, + const char* name = 0 ); + TDEActionMenu( const TQString& text, const TQIconSet& icon, + TQObject* parent = 0, const char* name = 0 ); + TDEActionMenu( const TQString& text, const TQString& icon, + TQObject* parent = 0, const char* name = 0 ); + TDEActionMenu( TQObject* parent = 0, const char* name = 0 ); + virtual ~TDEActionMenu(); + + virtual void insert( TDEAction*, int index = -1 ); + virtual void remove( TDEAction* ); + + TDEPopupMenu* popupMenu() const; + void popup( const TQPoint& global ); + + /** + * Returns true if this action creates a delayed popup menu + * when plugged in a TDEToolbar. + */ + bool delayed() const; + /** + * If set to true, this action will create a delayed popup menu + * when plugged in a TDEToolbar. Otherwise it creates a normal popup. + * Default: delayed + * + * Remember that if the "main" action (the toolbar button itself) + * cannot be clicked, then you should call setDelayed(false). + * + * On the opposite, if the main action can be clicked, it can only happen + * in a toolbar: in a menu, the parent of a submenu can't be activated. + * To get a "normal" menu item when plugged a menu (and no submenu) + * use TDEToolBarPopupAction. + */ + void setDelayed(bool _delayed); + + /** + * Returns true if this action creates a sticky popup menu. + * See setStickyMenu(). + */ + bool stickyMenu() const; + /** + * If set to true, this action will create a sticky popup menu + * when plugged in a TDEToolbar. + * "Sticky", means it's visible until a selection is made or the mouse is + * clicked elsewhere. This feature allows you to make a selection without + * having to press and hold down the mouse while making a selection. + * Default: sticky. + */ + void setStickyMenu(bool sticky); + + virtual int plug( TQWidget* widget, int index = -1 ); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEActionMenuPrivate; + TDEActionMenuPrivate *d; +}; + +/** + * This action is a normal action everywhere, except in a toolbar + * where it also has a popupmenu (optionnally delayed). This action is designed + * for history actions (back/forward, undo/redo) and for any other action + * that has more detail in a toolbar than in a menu (e.g. tool chooser + * with "Other" leading to a dialog...). + */ +class TDEUI_EXPORT TDEToolBarPopupAction : public TDEAction +{ + Q_OBJECT + + TQ_PROPERTY( bool delayed READ delayed WRITE setDelayed ) + TQ_PROPERTY( bool stickyMenu READ stickyMenu WRITE setStickyMenu ) + +public: + //Not all constructors - because we need an icon, since this action only makes + // sense when being plugged at least in a toolbar. + /** + * Create a TDEToolBarPopupAction, with a text, an icon, an optional accelerator, + * parent and name. + * + * @param text The text that will be displayed. + * @param icon The icon to display. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToolBarPopupAction( const TQString& text, const TQString& icon, const TDEShortcut& cut = TDEShortcut(), + TQObject* parent = 0, const char* name = 0 ); + + /** + * Create a TDEToolBarPopupAction, with a text, an icon, an accelerator, + * a slot connected to the action, parent and name. + * + * If you do not want or have a keyboard accelerator, set the + * @p cut param to 0. + * + * @param text The text that will be displayed. + * @param icon The icon to display. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's owner. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToolBarPopupAction( const TQString& text, const TQString& icon, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent = 0, const char* name = 0 ); + + /** + * Create a TDEToolBarPopupAction, with a KGuiItem, an accelerator, + * a slot connected to the action, parent and name. The text and the + * icon are taken from the KGuiItem. + * + * If you do not want or have a keyboard accelerator, set the + * @p cut param to 0. + * + * @param item The text and icon that will be displayed. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's owner. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToolBarPopupAction( const KGuiItem& item, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TDEActionCollection* parent, const char* name ); + + virtual ~TDEToolBarPopupAction(); + + virtual int plug( TQWidget *widget, int index = -1 ); + + /** + * The popup menu that is shown when clicking (some time) on the toolbar + * button. You may want to plug items into it on creation, or connect to + * aboutToShow for a more dynamic menu. + */ + TDEPopupMenu *popupMenu() const; + + /** + * Returns true if this action creates a delayed popup menu + * when plugged in a TDEToolbar. + */ + bool delayed() const; + /** + * If set to true, this action will create a delayed popup menu + * when plugged in a TDEToolbar. Otherwise it creates a normal popup. + * Default: delayed. + */ + void setDelayed(bool delayed); + /** + * Returns true if this action creates a sticky popup menu. + * See setStickyMenu(). + */ + bool stickyMenu() const; + /** + * If set to true, this action will create a sticky popup menu + * when plugged in a TDEToolbar. + * "Sticky", means it's visible until a selection is made or the mouse is + * clicked elsewhere. This feature allows you to make a selection without + * having to press and hold down the mouse while making a selection. + * Only available if delayed() is true. + * Default: sticky. + */ + void setStickyMenu(bool sticky); + +private: + TDEPopupMenu *m_popup; + bool m_delayed:1; + bool m_stickyMenu:1; +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEToolBarPopupActionPrivate; + TDEToolBarPopupActionPrivate *d; +}; + +/** + * An action that takes care of everything associated with + * showing or hiding a toolbar by a menu action. It will + * show or hide the toolbar with the given name when + * activated, and check or uncheck itself if the toolbar + * is manually shown or hidden. + * + * If you need to perfom some additional action when the + * toolbar is shown or hidden, connect to the toggled(bool) + * signal. It will be emitted after the toolbar's + * visibility has changed, whenever it changes. + * @since 3.1 + */ +class TDEUI_EXPORT TDEToggleToolBarAction : public TDEToggleAction +{ + Q_OBJECT + +public: + /** + * Create a TDEToggleToolbarAction that manages the toolbar + * named toolBarName. This can be either the name of a + * toolbar in an xml ui file, or a toolbar programmatically + * created with that name. + */ + TDEToggleToolBarAction( const char* toolBarName, const TQString& text, + TDEActionCollection* parent, const char* name ); + TDEToggleToolBarAction( TDEToolBar *toolBar, const TQString &text, + TDEActionCollection *parent, const char *name ); + virtual ~TDEToggleToolBarAction(); + + virtual int plug( TQWidget * widget, int index = -1 ); + + TDEToolBar *toolBar() { return m_toolBar; } + +public slots: + virtual void setChecked( bool ); + +private: + TQCString m_toolBarName; + TQGuardedPtr m_toolBar; +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEToggleToolBarActionPrivate; + TDEToggleToolBarActionPrivate *d; +}; + +/** + * An action for switching between to/from full screen mode. Note that + * TQWidget::isFullScreen() may reflect the new or the old state + * depending on how the action was triggered (by the application or + * from the window manager). Also don't try to track the window state + * yourself. Rely on this action's state (isChecked()) instead. + * + * Important: If you need to set/change the fullscreen state manually, + * use the relevant TQWidget function (showFullScreen etc.), do not + * call directly the slot connected to the toggled() signal. The slot + * still needs to explicitly set the window state though. + * @since 3.2 + */ +class TDEUI_EXPORT TDEToggleFullScreenAction : public TDEToggleAction +{ + Q_OBJECT + +public: + /** + * Create a TDEToggleFullScreenAction + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param window the window that will switch to/from full screen mode + * @param name An internal name for this action. + */ + TDEToggleFullScreenAction( const TDEShortcut &cut, + const TQObject* receiver, const char* slot, + TQObject* parent, TQWidget* window, + const char* name ); + virtual ~TDEToggleFullScreenAction(); + + /** + * Sets the window that will be related to this action. + */ + void setWindow( TQWidget* window ); +public slots: + virtual void setChecked( bool ); +protected: + /** + * @internal + */ + virtual bool eventFilter( TQObject* o, TQEvent* e ); +private: + TQWidget* window; +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEToggleFullScreenActionPrivate; + TDEToggleFullScreenActionPrivate *d; +}; + + +/** + * An action that automatically embeds a widget into a + * toolbar. + */ +class TDEUI_EXPORT KWidgetAction : public TDEAction +{ + Q_OBJECT + +public: + /** + * Create an action that will embed widget into a toolbar + * when plugged. This action may only be plugged into + * a toolbar. + */ + KWidgetAction( TQWidget* widget, const TQString& text, + const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TDEActionCollection* parent, const char* name ); + virtual ~KWidgetAction(); + + /** + * Returns the widget associated with this action. + */ + TQWidget* widget() { return m_widget; } + + void setAutoSized( bool ); + + /** + * Plug the action. The widget passed to the constructor + * will be reparented to w, which must inherit TDEToolBar. + */ + virtual int plug( TQWidget* widget, int index = -1 ); + /** + * Unplug the action. Ensures that the action is not + * destroyed. It will be hidden and reparented to 0L instead. + */ + virtual void unplug( TQWidget *w ); +protected slots: + void slotToolbarDestroyed(); +private: + TQGuardedPtr m_widget; + bool m_autoSized; +protected: + virtual void virtual_hook( int id, void* data ); +private: + class KWidgetActionPrivate; + KWidgetActionPrivate *d; +}; + +class TDEUI_EXPORT TDEActionSeparator : public TDEAction +{ + Q_OBJECT + +public: + TDEActionSeparator( TQObject* parent = 0, const char* name = 0 ); + virtual ~TDEActionSeparator(); + + virtual int plug( TQWidget *widget, int index = -1 ); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEActionSeparatorPrivate; + TDEActionSeparatorPrivate *d; +}; + +/** + * An action for pasting text from the clipboard. + * It's useful for text handling applications as + * when plugged into a toolbar it provides a menu + * with the clipboard history if klipper is running. + * If klipper is not running, the menu has only one + * item: the current clipboard content. + * + * @since 3.2 + */ +class TDEUI_EXPORT TDEPasteTextAction: public TDEAction +{ + Q_OBJECT + +public: + /** + * Create a TDEPasteTextAction, with a text, an icon, an accelerator, + * a slot connected to the action, parent and name. + * + * If you do not want or have a keyboard accelerator, set the + * @p cut param to 0. + * + * @param text The text that will be displayed. + * @param icon The icon to display. + * @param cut The corresponding keyboard accelerator (shortcut). + * @param receiver The SLOT's owner. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEPasteTextAction( const TQString& text, const TQString& icon, const TDEShortcut& cut, + const TQObject* receiver, const char* slot, + TQObject* parent = 0, const char* name = 0 ); + + virtual ~TDEPasteTextAction(); + + /** + * Controls the behavior of the clipboard history menu popup. + * + * @param mode If false and the clipboard contains a non-text object + * the popup menu with the clipboard history will appear + * immediately as the user clicks the toolbar action; if + * true, the action works like the standard paste action + * even if the current clipboard object is not text. + * Default value is true. + */ + void setMixedMode(bool mode); + + virtual int plug( TQWidget *widget, int index = -1 ); + +protected slots: + void menuAboutToShow(); + void menuItemActivated( int id); + virtual void slotActivated(); + +protected: + virtual void virtual_hook( int id, void* data ); + +private: + TDEPopupMenu *m_popup; + bool m_mixedMode; + class TDEPasteTextActionPrivate; + TDEPasteTextActionPrivate *d; +}; + +#endif diff --git a/tdeui/tdeactioncollection.cpp b/tdeui/tdeactioncollection.cpp new file mode 100644 index 000000000..74f273994 --- /dev/null +++ b/tdeui/tdeactioncollection.cpp @@ -0,0 +1,802 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999 Reginald Stadlbauer + (C) 1999 Simon Hausmann + (C) 2000 Nicolas Hadacek + (C) 2000 Kurt Granroth + (C) 2000 Michael Koch + (C) 2001 Holger Freyther + (C) 2002 Ellis Whitehead + (C) 2002 Joseph Wenninger + + 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. +*/ + +#include "kactioncollection.h" +#include "kactionshortcutlist.h" +#include "ktoolbar.h" +#include "kxmlguifactory.h" +#include "kxmlguiclient.h" + +#include +#include +#include +#include + +#include +#include +#include + +class TDEActionCollection::TDEActionCollectionPrivate +{ +public: + TDEActionCollectionPrivate() + { + m_instance = 0; + //m_bOneTDEAccelOnly = false; + //m_iWidgetCurrent = 0; + m_bAutoConnectShortcuts = true; + m_widget = 0; + m_kaccel = m_builderTDEAccel = 0; + m_dctHighlightContainers.setAutoDelete( true ); + m_highlight = false; + m_currentHighlightAction = 0; + m_statusCleared = true; + m_parentGUIClient = 0L; + } + + TDEInstance *m_instance; + TQString m_sXMLFile; + bool m_bAutoConnectShortcuts; + //bool m_bOneTDEAccelOnly; + //int m_iWidgetCurrent; + //TQValueList m_widgetList; + //TQValueList m_kaccelList; + TQValueList m_docList; + TQWidget *m_widget; + TDEAccel *m_kaccel; + TDEAccel *m_builderTDEAccel; + + TQAsciiDict m_actionDict; + TQPtrDict< TQPtrList > m_dctHighlightContainers; + bool m_highlight; + TDEAction *m_currentHighlightAction; + bool m_statusCleared; + const KXMLGUIClient *m_parentGUIClient; +}; + +TDEActionCollection::TDEActionCollection( TQWidget *parent, const char *name, + TDEInstance *instance ) + : TQObject( parent, name ) +{ + kdDebug(129) << "TDEActionCollection::TDEActionCollection( " << parent << ", " << name << " ): this = " << this << endl; // ellis + d = new TDEActionCollectionPrivate; + if( parent ) + setWidget( parent ); + //d->m_bOneTDEAccelOnly = (d->m_kaccelList.count() > 0); + setInstance( instance ); +} + + +TDEActionCollection::TDEActionCollection( TQWidget *watch, TQObject* parent, const char *name, + TDEInstance *instance ) + : TQObject( parent, name ) +{ + kdDebug(129) << "TDEActionCollection::TDEActionCollection( " << watch << ", " << parent << ", " << name << " ): this = " << this << endl; //ellis + d = new TDEActionCollectionPrivate; + if( watch ) + setWidget( watch ); + //d->m_bOneTDEAccelOnly = (d->m_kaccelList.count() > 0); + setInstance( instance ); +} + +#ifndef KDE_NO_COMPAT +// KDE 4: remove +TDEActionCollection::TDEActionCollection( TQObject *parent, const char *name, + TDEInstance *instance ) + : TQObject( parent, name ) +{ + kdWarning(129) << "TDEActionCollection::TDEActionCollection( TQObject *parent, const char *name, TDEInstance *instance )" << endl; //ellis + kdDebug(129) << kdBacktrace() << endl; + d = new TDEActionCollectionPrivate; + TQWidget* w = tqt_dynamic_cast( parent ); + if( w ) + setWidget( w ); + //d->m_bOneTDEAccelOnly = (d->m_kaccelList.count() > 0); + setInstance( instance ); +} + +TDEActionCollection::TDEActionCollection( const TDEActionCollection © ) + : TQObject() +{ + kdWarning(129) << "TDEActionCollection::TDEActionCollection( const TDEActionCollection & ): function is severely deprecated." << endl; + d = new TDEActionCollectionPrivate; + *this = copy; +} +#endif // KDE 4: remove end + +TDEActionCollection::TDEActionCollection( const char *name, const KXMLGUIClient *parent ) + : TQObject( 0L, name ) +{ + d = new TDEActionCollectionPrivate; + d->m_parentGUIClient=parent; + d->m_instance=parent->instance(); +} + + +TDEActionCollection::~TDEActionCollection() +{ + kdDebug(129) << "TDEActionCollection::~TDEActionCollection(): this = " << this << endl; + for ( TQAsciiDictIterator it( d->m_actionDict ); it.current(); ++it ) { + TDEAction* pAction = it.current(); + if ( pAction->m_parentCollection == this ) + pAction->m_parentCollection = 0L; + } + + delete d->m_kaccel; + delete d->m_builderTDEAccel; + delete d; d = 0; +} + +void TDEActionCollection::setWidget( TQWidget* w ) +{ + //if ( d->m_actionDict.count() > 0 ) { + // kdError(129) << "TDEActionCollection::setWidget(): must be called before any actions are added to collection!" << endl; + // kdDebug(129) << kdBacktrace() << endl; + //} + //else + if ( !d->m_widget ) { + d->m_widget = w; + d->m_kaccel = new TDEAccel( w, this, "TDEActionCollection-TDEAccel" ); + } + else if ( d->m_widget != w ) + kdWarning(129) << "TDEActionCollection::setWidget(): tried to change widget from " << d->m_widget << " to " << w << endl; +} + +void TDEActionCollection::setAutoConnectShortcuts( bool b ) +{ + d->m_bAutoConnectShortcuts = b; +} + +bool TDEActionCollection::isAutoConnectShortcuts() +{ + return d->m_bAutoConnectShortcuts; +} + +bool TDEActionCollection::addDocCollection( TDEActionCollection* pDoc ) +{ + d->m_docList.append( pDoc ); + return true; +} + +void TDEActionCollection::beginXMLPlug( TQWidget *widget ) +{ + kdDebug(129) << "TDEActionCollection::beginXMLPlug( buildWidget = " << widget << " ): this = " << this << " d->m_builderTDEAccel = " << d->m_builderTDEAccel << endl; + + if( widget && !d->m_builderTDEAccel ) { + d->m_builderTDEAccel = new TDEAccel( widget, this, "TDEActionCollection-BuilderTDEAccel" ); + } +} + +void TDEActionCollection::endXMLPlug() +{ + kdDebug(129) << "TDEActionCollection::endXMLPlug(): this = " << this << endl; + //s_kaccelXML = 0; +} + +void TDEActionCollection::prepareXMLUnplug() +{ + kdDebug(129) << "TDEActionCollection::prepareXMLUnplug(): this = " << this << endl; + unplugShortcuts( d->m_kaccel ); + + if( d->m_builderTDEAccel ) { + unplugShortcuts( d->m_builderTDEAccel ); + delete d->m_builderTDEAccel; + d->m_builderTDEAccel = 0; + } +} + +void TDEActionCollection::unplugShortcuts( TDEAccel* kaccel ) +{ + for ( TQAsciiDictIterator it( d->m_actionDict ); it.current(); ++it ) { + TDEAction* pAction = it.current(); + pAction->removeTDEAccel( kaccel ); + } + + for( uint i = 0; i < d->m_docList.count(); i++ ) + d->m_docList[i]->unplugShortcuts( kaccel ); +} + +/*void TDEActionCollection::addWidget( TQWidget* w ) +{ + if( !d->m_bOneTDEAccelOnly ) { + kdDebug(129) << "TDEActionCollection::addWidget( " << w << " ): this = " << this << endl; + for( uint i = 0; i < d->m_widgetList.count(); i++ ) { + if( d->m_widgetList[i] == w ) { + d->m_iWidgetCurrent = i; + return; + } + } + d->m_iWidgetCurrent = d->m_widgetList.count(); + d->m_widgetList.append( w ); + d->m_kaccelList.append( new TDEAccel( w, this, "TDEActionCollection-TDEAccel" ) ); + } +} + +void TDEActionCollection::removeWidget( TQWidget* w ) +{ + if( !d->m_bOneTDEAccelOnly ) { + kdDebug(129) << "TDEActionCollection::removeWidget( " << w << " ): this = " << this << endl; + for( uint i = 0; i < d->m_widgetList.count(); i++ ) { + if( d->m_widgetList[i] == w ) { + // Remove TDEAccel object from children. + TDEAccel* pTDEAccel = d->m_kaccelList[i]; + for ( TQAsciiDictIterator it( d->m_actionDict ); it.current(); ++it ) { + TDEAction* pAction = it.current(); + if ( pAction->m_parentCollection == this ) { + pAction->removeTDEAccel( pTDEAccel ); + } + } + delete pTDEAccel; + + d->m_widgetList.remove( d->m_widgetList.at( i ) ); + d->m_kaccelList.remove( d->m_kaccelList.at( i ) ); + + if( d->m_iWidgetCurrent == (int)i ) + d->m_iWidgetCurrent = -1; + else if( d->m_iWidgetCurrent > (int)i ) + d->m_iWidgetCurrent--; + return; + } + } + kdWarning(129) << "TDEActionCollection::removeWidget( " << w << " ): widget not in list." << endl; + } +} + +bool TDEActionCollection::ownsTDEAccel() const +{ + return d->m_bOneTDEAccelOnly; +} + +uint TDEActionCollection::widgetCount() const +{ + return d->m_widgetList.count(); +} + +const TDEAccel* TDEActionCollection::widgetTDEAccel( uint i ) const +{ + return d->m_kaccelList[i]; +}*/ + +TDEAccel* TDEActionCollection::kaccel() +{ + //if( d->m_kaccelList.count() > 0 ) + // return d->m_kaccelList[d->m_iWidgetCurrent]; + //else + // return 0; + return d->m_kaccel; +} + +const TDEAccel* TDEActionCollection::kaccel() const +{ + //if( d->m_kaccelList.count() > 0 ) + // return d->m_kaccelList[d->m_iWidgetCurrent]; + //else + // return 0; + return d->m_kaccel; +} + +// Return the key to use in d->m_actionDict for the given action. +// Usually name(), except when unnamed. +static const char* actionDictKey( TDEAction* action, char* buffer ) +{ + const char* name = action->name(); + if( !qstrcmp( name, "unnamed" ) ) + { + sprintf(buffer, "unnamed-%p", (void *)action); + return buffer; + } + return name; +} + +void TDEActionCollection::_insert( TDEAction* action ) +{ + char unnamed_name[100]; + const char *name = actionDictKey( action, unnamed_name ); + TDEAction *a = d->m_actionDict[ name ]; + if ( a == action ) + return; + + d->m_actionDict.insert( name, action ); + + emit inserted( action ); +} + +void TDEActionCollection::_remove( TDEAction* action ) +{ + char unnamed_name[100]; + const char *name = actionDictKey( action, unnamed_name ); + + TDEAction *a = d->m_actionDict.take( name ); + if ( !a || a != action ) + return; + + emit removed( action ); + // note that we delete the action without its parent collection set to 0. + // This triggers kaccel::remove, to remove any shortcut. + delete a; +} + +TDEAction* TDEActionCollection::_take( TDEAction* action ) +{ + char unnamed_name[100]; + const char *name = actionDictKey( action, unnamed_name ); + + TDEAction *a = d->m_actionDict.take( name ); + if ( !a || a != action ) + return 0; + + if ( a->m_parentCollection == this ) + a->m_parentCollection = 0; + + emit removed( action ); + + return a; +} + +void TDEActionCollection::_clear() +{ + TQAsciiDictIterator it( d->m_actionDict ); + while ( it.current() ) + _remove( it.current() ); +} + +void TDEActionCollection::insert( TDEAction* action ) { _insert( action ); } +void TDEActionCollection::remove( TDEAction* action ) { _remove( action ); } +TDEAction* TDEActionCollection::take( TDEAction* action ) { return _take( action ); } +void TDEActionCollection::clear() { _clear(); } +TDEAccel* TDEActionCollection::accel() { return kaccel(); } +const TDEAccel* TDEActionCollection::accel() const { return kaccel(); } +TDEAccel* TDEActionCollection::builderTDEAccel() const { return d->m_builderTDEAccel; } + +TDEAction* TDEActionCollection::action( const char* name, const char* classname ) const +{ + TDEAction* pAction = 0; + + if ( !classname && name ) + pAction = d->m_actionDict[ name ]; + + else { + TQAsciiDictIterator it( d->m_actionDict ); + for( ; it.current(); ++it ) + { + if ( ( !name || !strcmp( it.current()->name(), name ) ) && + ( !classname || !strcmp( it.current()->className(), classname ) ) ) { + pAction = it.current(); + break; + } + } + } + + if( !pAction ) { + for( uint i = 0; i < d->m_docList.count() && !pAction; i++ ) + pAction = d->m_docList[i]->action( name, classname ); + } + + return pAction; +} + +TDEAction* TDEActionCollection::action( int index ) const +{ + TQAsciiDictIterator it( d->m_actionDict ); + it += index; + return it.current(); +// return d->m_actions.at( index ); +} + +bool TDEActionCollection::readShortcutSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig ) +{ + return TDEActionShortcutList(this).readSettings( sConfigGroup, pConfig ); +} + +bool TDEActionCollection::writeShortcutSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig ) const +{ + return TDEActionShortcutList((TDEActionCollection*)this).writeSettings( sConfigGroup, pConfig ); +} + +uint TDEActionCollection::count() const +{ + return d->m_actionDict.count(); +} + +TQStringList TDEActionCollection::groups() const +{ + TQStringList lst; + + TQAsciiDictIterator it( d->m_actionDict ); + for( ; it.current(); ++it ) + if ( !it.current()->group().isEmpty() && !lst.contains( it.current()->group() ) ) + lst.append( it.current()->group() ); + + return lst; +} + +TDEActionPtrList TDEActionCollection::actions( const TQString& group ) const +{ + TDEActionPtrList lst; + + TQAsciiDictIterator it( d->m_actionDict ); + for( ; it.current(); ++it ) + if ( it.current()->group() == group ) + lst.append( it.current() ); + else if ( it.current()->group().isEmpty() && group.isEmpty() ) + lst.append( it.current() ); + + return lst; +} + +TDEActionPtrList TDEActionCollection::actions() const +{ + TDEActionPtrList lst; + + TQAsciiDictIterator it( d->m_actionDict ); + for( ; it.current(); ++it ) + lst.append( it.current() ); + + return lst; +} + +void TDEActionCollection::setInstance( TDEInstance *instance ) +{ + if ( instance ) + d->m_instance = instance; + else + d->m_instance = TDEGlobal::instance(); +} + +TDEInstance *TDEActionCollection::instance() const +{ + return d->m_instance; +} + +void TDEActionCollection::setXMLFile( const TQString& sXMLFile ) +{ + d->m_sXMLFile = sXMLFile; +} + +const TQString& TDEActionCollection::xmlFile() const +{ + return d->m_sXMLFile; +} + +void TDEActionCollection::setHighlightingEnabled( bool enable ) +{ + d->m_highlight = enable; +} + +bool TDEActionCollection::highlightingEnabled() const +{ + return d->m_highlight; +} + +void TDEActionCollection::connectHighlight( TQWidget *container, TDEAction *action ) +{ + if ( !d->m_highlight ) + return; + + TQPtrList *actionList = d->m_dctHighlightContainers[ container ]; + + if ( !actionList ) + { + actionList = new TQPtrList; + + if ( ::tqqt_cast( container ) ) + { + connect( container, TQT_SIGNAL( highlighted( int ) ), + this, TQT_SLOT( slotMenuItemHighlighted( int ) ) ); + connect( container, TQT_SIGNAL( aboutToHide() ), + this, TQT_SLOT( slotMenuAboutToHide() ) ); + } + else if ( ::tqqt_cast( container ) ) + { + connect( container, TQT_SIGNAL( highlighted( int, bool ) ), + this, TQT_SLOT( slotToolBarButtonHighlighted( int, bool ) ) ); + } + + connect( container, TQT_SIGNAL( destroyed() ), + this, TQT_SLOT( slotDestroyed() ) ); + + d->m_dctHighlightContainers.insert( container, actionList ); + } + + actionList->append( action ); +} + +void TDEActionCollection::disconnectHighlight( TQWidget *container, TDEAction *action ) +{ + if ( !d->m_highlight ) + return; + + TQPtrList *actionList = d->m_dctHighlightContainers[ container ]; + + if ( !actionList ) + return; + + actionList->removeRef( action ); + + if ( actionList->isEmpty() ) + d->m_dctHighlightContainers.remove( container ); +} + +void TDEActionCollection::slotMenuItemHighlighted( int id ) +{ + if ( !d->m_highlight ) + return; + + if ( d->m_currentHighlightAction ) + emit actionHighlighted( d->m_currentHighlightAction, false ); + + TQWidget *container = const_cast(TQT_TQWIDGET_CONST( sender() )); + + d->m_currentHighlightAction = findAction( container, id ); + + if ( !d->m_currentHighlightAction ) + { + if ( !d->m_statusCleared ) + emit clearStatusText(); + d->m_statusCleared = true; + return; + } + + d->m_statusCleared = false; + emit actionHighlighted( d->m_currentHighlightAction ); + emit actionHighlighted( d->m_currentHighlightAction, true ); + emit actionStatusText( d->m_currentHighlightAction->toolTip() ); +} + +void TDEActionCollection::slotMenuAboutToHide() +{ + if ( d->m_currentHighlightAction ) + emit actionHighlighted( d->m_currentHighlightAction, false ); + d->m_currentHighlightAction = 0; + + if ( !d->m_statusCleared ) + emit clearStatusText(); + d->m_statusCleared = true; +} + +void TDEActionCollection::slotToolBarButtonHighlighted( int id, bool highlight ) +{ + if ( !d->m_highlight ) + return; + + TQWidget *container = const_cast(TQT_TQWIDGET_CONST( sender() )); + + TDEAction *action = findAction( container, id ); + + if ( !action ) + { + d->m_currentHighlightAction = 0; + // use tooltip groups for toolbar status text stuff instead (Simon) +// emit clearStatusText(); + return; + } + + emit actionHighlighted( action, highlight ); + + if ( highlight ) + d->m_currentHighlightAction = action; + else + { + d->m_currentHighlightAction = 0; +// emit clearStatusText(); + } +} + +void TDEActionCollection::slotDestroyed() +{ + d->m_dctHighlightContainers.remove( reinterpret_cast( const_cast(TQT_TQOBJECT_CONST(sender())) ) ); +} + +TDEAction *TDEActionCollection::findAction( TQWidget *container, int id ) +{ + TQPtrList *actionList = d->m_dctHighlightContainers[ reinterpret_cast( container ) ]; + + if ( !actionList ) + return 0; + + TQPtrListIterator it( *actionList ); + for (; it.current(); ++it ) + if ( it.current()->isPlugged( container, id ) ) + return it.current(); + + return 0; +} + +const KXMLGUIClient *TDEActionCollection::parentGUIClient() const +{ + return d->m_parentGUIClient; +} + +#ifndef KDE_NO_COMPAT +// KDE 4: remove +TDEActionCollection TDEActionCollection::operator+(const TDEActionCollection &c ) const +{ + kdWarning(129) << "TDEActionCollection::operator+(): function is severely deprecated." << endl; + TDEActionCollection ret( *this ); + + TQValueList actions = c.actions(); + TQValueList::ConstIterator it = actions.begin(); + TQValueList::ConstIterator end = actions.end(); + for (; it != end; ++it ) + ret.insert( *it ); + + return ret; +} + +TDEActionCollection &TDEActionCollection::operator=( const TDEActionCollection © ) +{ + kdWarning(129) << "TDEActionCollection::operator=(): function is severely deprecated." << endl; + //d->m_bOneTDEAccelOnly = copy.d->m_bOneTDEAccelOnly; + //d->m_iWidgetCurrent = copy.d->m_iWidgetCurrent; + //d->m_widgetList = copy.d->m_widgetList; + //d->m_kaccelList = copy.d->m_kaccelList; + d->m_widget = copy.d->m_widget; + d->m_kaccel = copy.d->m_kaccel; + d->m_actionDict = copy.d->m_actionDict; + setInstance( copy.instance() ); + return *this; +} + +TDEActionCollection &TDEActionCollection::operator+=( const TDEActionCollection &c ) +{ + kdWarning(129) << "TDEActionCollection::operator+=(): function is severely deprecated." << endl; + TQAsciiDictIterator it(c.d->m_actionDict); + for ( ; it.current(); ++it ) + insert( it.current() ); + + return *this; +} +#endif // KDE 4: remove end + +//--------------------------------------------------------------------- +// TDEActionShortcutList +//--------------------------------------------------------------------- + +TDEActionShortcutList::TDEActionShortcutList( TDEActionCollection* pColl ) +: m_actions( *pColl ) + { } +TDEActionShortcutList::~TDEActionShortcutList() + { } +uint TDEActionShortcutList::count() const + { return m_actions.count(); } +TQString TDEActionShortcutList::name( uint i ) const + { return m_actions.action(i)->name(); } +TQString TDEActionShortcutList::label( uint i ) const + { return m_actions.action(i)->text(); } +TQString TDEActionShortcutList::whatsThis( uint i ) const + { return m_actions.action(i)->whatsThis(); } +const TDEShortcut& TDEActionShortcutList::shortcut( uint i ) const + { return m_actions.action(i)->shortcut(); } +const TDEShortcut& TDEActionShortcutList::shortcutDefault( uint i ) const + { return m_actions.action(i)->shortcutDefault(); } +bool TDEActionShortcutList::isConfigurable( uint i ) const + { return m_actions.action(i)->isShortcutConfigurable(); } +bool TDEActionShortcutList::setShortcut( uint i, const TDEShortcut& cut ) + { return m_actions.action(i)->setShortcut( cut ); } +const TDEInstance* TDEActionShortcutList::instance() const + { return m_actions.instance(); } +TQVariant TDEActionShortcutList::getOther( Other, uint ) const + { return TQVariant(); } +bool TDEActionShortcutList::setOther( Other, uint, TQVariant ) + { return false; } +const TDEAction *TDEActionShortcutList::action( uint i) const + { return m_actions.action(i); } + +bool TDEActionShortcutList::save() const +{ + const KXMLGUIClient* guiClient=m_actions.parentGUIClient(); + const TQString xmlFile=guiClient ? guiClient->xmlFile() : m_actions.xmlFile(); + kdDebug(129) << "TDEActionShortcutList::save(): xmlFile = " << xmlFile << endl; + + if( m_actions.xmlFile().isEmpty() ) + return writeSettings(); + + TQString attrShortcut = TQString::fromLatin1("shortcut"); + TQString attrAccel = TQString::fromLatin1("accel"); // Depricated attribute + + // Read XML file + TQString sXml( KXMLGUIFactory::readConfigFile( xmlFile, false, instance() ) ); + TQDomDocument doc; + doc.setContent( sXml ); + + // Process XML data + + // Get hold of ActionProperties tag + TQDomElement elem = KXMLGUIFactory::actionPropertiesElement( doc ); + + // now, iterate through our actions + uint nSize = count(); + for( uint i = 0; i < nSize; i++ ) { + const TQString& sName = name(i); + + bool bSameAsDefault = (shortcut(i) == shortcutDefault(i)); + //kdDebug(129) << "name = " << sName << " shortcut = " << shortcut(i).toStringInternal() << " def = " << shortcutDefault(i).toStringInternal() << endl; + + // now see if this element already exists + // and create it if necessary (unless bSameAsDefault) + TQDomElement act_elem = KXMLGUIFactory::findActionByName( elem, sName, !bSameAsDefault ); + if ( act_elem.isNull() ) + continue; + + act_elem.removeAttribute( attrAccel ); + if( bSameAsDefault ) { + act_elem.removeAttribute( attrShortcut ); + //kdDebug(129) << "act_elem.attributes().count() = " << act_elem.attributes().count() << endl; + if( act_elem.attributes().count() == 1 ) + elem.removeChild( act_elem ); + } else { + act_elem.setAttribute( attrShortcut, shortcut(i).toStringInternal() ); + } + } + + // Write back to XML file + return KXMLGUIFactory::saveConfigFile( doc, guiClient ? guiClient->localXMLFile() : m_actions.xmlFile(), instance() ); +} + +//--------------------------------------------------------------------- +// TDEActionPtrShortcutList +//--------------------------------------------------------------------- + +TDEActionPtrShortcutList::TDEActionPtrShortcutList( TDEActionPtrList& list ) +: m_actions( list ) + { } +TDEActionPtrShortcutList::~TDEActionPtrShortcutList() + { } +uint TDEActionPtrShortcutList::count() const + { return m_actions.count(); } +TQString TDEActionPtrShortcutList::name( uint i ) const + { return m_actions[i]->name(); } +TQString TDEActionPtrShortcutList::label( uint i ) const + { return m_actions[i]->text(); } +TQString TDEActionPtrShortcutList::whatsThis( uint i ) const + { return m_actions[i]->whatsThis(); } +const TDEShortcut& TDEActionPtrShortcutList::shortcut( uint i ) const + { return m_actions[i]->shortcut(); } +const TDEShortcut& TDEActionPtrShortcutList::shortcutDefault( uint i ) const + { return m_actions[i]->shortcutDefault(); } +bool TDEActionPtrShortcutList::isConfigurable( uint i ) const + { return m_actions[i]->isShortcutConfigurable(); } +bool TDEActionPtrShortcutList::setShortcut( uint i, const TDEShortcut& cut ) + { return m_actions[i]->setShortcut( cut ); } +TQVariant TDEActionPtrShortcutList::getOther( Other, uint ) const + { return TQVariant(); } +bool TDEActionPtrShortcutList::setOther( Other, uint, TQVariant ) + { return false; } +bool TDEActionPtrShortcutList::save() const + { return false; } + +void TDEActionShortcutList::virtual_hook( int id, void* data ) +{ TDEShortcutList::virtual_hook( id, data ); } + +void TDEActionPtrShortcutList::virtual_hook( int id, void* data ) +{ TDEShortcutList::virtual_hook( id, data ); } + +void TDEActionCollection::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +/* vim: et sw=2 ts=2 + */ + +#include "kactioncollection.moc" diff --git a/tdeui/tdeactioncollection.h b/tdeui/tdeactioncollection.h new file mode 100644 index 000000000..9ef517579 --- /dev/null +++ b/tdeui/tdeactioncollection.h @@ -0,0 +1,393 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999 Reginald Stadlbauer + (C) 1999 Simon Hausmann + (C) 2000 Nicolas Hadacek + (C) 2000 Kurt Granroth + (C) 2000 Michael Koch + (C) 2001 Holger Freyther + (C) 2002 Ellis Whitehead + + 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 __kactioncollection_h__ +#define __kactioncollection_h__ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +class TQMenuBar; +class TQPopupMenu; +class TQComboBox; +class TQPoint; +class TQIconSet; +class TQString; +class TDEToolBar; + +class TDEAccel; +class TDEAccelActions; +class TDEConfig; +class TDEConfigBase; +class KURL; +class TDEInstance; +class TDEToolBar; +class TDEActionCollection; +class TDEPopupMenu; +class TDEMainWindow; +class KXMLGUIClient; + +typedef TQValueList TDEActionPtrList; + +/** + * A managed set of TDEAction objects. + * + * If you set the tooltips on TDEActions and want the tooltip to show in statusbar + * (recommended) then you will need to connect a couple of the actionclass signals + * to the toolbar. + * The easiest way of doing this is in your TDEMainWindow subclass, where you create + * a statusbar, do: + * + * \code + * actionCollection()->setHighlightingEnabled(true); + * connect(actionCollection(), TQT_SIGNAL( actionStatusText( const TQString & ) ), + * statusBar(), TQT_SLOT( message( const TQString & ) ) ); + * connect(actionCollection(), TQT_SIGNAL( clearStatusText() ), + * statusBar(), TQT_SLOT( clear() ) ); + * \endcode + */ +class TDEUI_EXPORT TDEActionCollection : public TQObject +{ + friend class TDEAction; + friend class KXMLGUIClient; + + Q_OBJECT + +public: + TDEActionCollection( TQWidget *parent, const char *name = 0, TDEInstance *instance = 0 ); + /** + * Use this constructor if you want the collection's actions to restrict + * their accelerator keys to @p watch rather than the @p parent. If + * you don't require shortcuts, you can pass a null to the @p watch parameter. + */ + TDEActionCollection( TQWidget *watch, TQObject* parent, const char *name = 0, TDEInstance *instance = 0 ); +#ifndef KDE_NO_COMPAT + TDEActionCollection( const TDEActionCollection © ); +#endif + virtual ~TDEActionCollection(); + + /** + * This sets the widget to which the keyboard shortcuts should be attached. + * You only need to call this if a null pointer was passed in the constructor. + */ + virtual void setWidget( TQWidget *widget ); + + /** + * This indicates whether new actions which are created in this collection + * should have their keyboard shortcuts automatically connected on + * construction. Set to 'false' if you will be loading XML-based settings. + * This is automatically done by KParts. The default is 'true'. + * @see isAutoConnectShortcuts() + */ + void setAutoConnectShortcuts( bool ); + + /** + * This indicates whether new actions which are created in this collection + * have their keyboard shortcuts automatically connected on + * construction. + * @see setAutoConnectShortcuts() + */ + bool isAutoConnectShortcuts(); + + /** + * This sets the default shortcut scope for new actions created in this + * collection. The default is ScopeUnspecified. Ideally the default + * would have been ScopeWidget, but that would cause some backwards + * compatibility problems. + */ + //void setDefaultScope( TDEAction::Scope ); + + /** + * Doc/View model. This lets you add the action collection of a document + * to a view's action collection. + */ + bool addDocCollection( TDEActionCollection* pDoc ); + + /** Returns the number of widgets which this collection is associated with. */ + //uint widgetCount() const; + + /** + * Returns true if the collection has its own TDEAccel object. This will be + * the case if it was constructed with a valid widget ptr or if setWidget() + * was called. + */ + //bool ownsTDEAccel() const; + + /** @deprecated Deprecated because of ambiguous name. Use kaccel() */ + virtual TDEAccel* accel() KDE_DEPRECATED; + /** @deprecated Deprecated because of ambiguous name. Use kaccel() */ + virtual const TDEAccel* accel() const KDE_DEPRECATED; + + /** Returns the TDEAccel object of the most recently set widget. */ + TDEAccel* kaccel(); + /** Returns the TDEAccel object of the most recently set widget. Const version for convenience. */ + const TDEAccel* kaccel() const; + + /** @internal, for TDEAction::kaccelCurrent() */ + TDEAccel* builderTDEAccel() const; + /** Returns the TDEAccel object associated with widget #. */ + //TDEAccel* widgetTDEAccel( uint i ); + //const TDEAccel* widgetTDEAccel( uint i ) const; + + /** Returns the number of actions in the collection */ + virtual uint count() const; + bool isEmpty() const { return (count() == 0); } + /** + * Return the TDEAction* at position "index" in the action collection. + * @see count() + */ + virtual TDEAction* action( int index ) const; + /** + * Find an action (optionally, of a given subclass of TDEAction) in the action collection. + * @param name Name of the TDEAction. + * @param classname Name of the TDEAction subclass. + * @return A pointer to the first TDEAction in the collection which matches the parameters or + * null if nothing matches. + */ + virtual TDEAction* action( const char* name, const char* classname = 0 ) const; + + /** Returns a list of all the groups of all the TDEActions in this action collection. + * @see TDEAction::group() + * @see TDEAction::setGroup() + */ + virtual TQStringList groups() const; + /** + * Returns the list of actions in a particular group managed by this action collection. + * @param group The name of the group. + */ + virtual TDEActionPtrList actions( const TQString& group ) const; + /** Returns the list of actions managed by this action collection. */ + virtual TDEActionPtrList actions() const; + + /** + * Used for reading shortcut configuration from a non-XML rc file. + */ + bool readShortcutSettings( const TQString& sConfigGroup = TQString::null, TDEConfigBase* pConfig = 0 ); + /** + * Used for writing shortcut configuration to a non-XML rc file. + */ + bool writeShortcutSettings( const TQString& sConfigGroup = TQString::null, TDEConfigBase* pConfig = 0 ) const; + + void setInstance( TDEInstance *instance ); + /** The instance with which this class is associated. */ + TDEInstance *instance() const; + + /** + * @deprecated + */ + void setXMLFile( const TQString& ); + /** + * @deprecated + */ + const TQString& xmlFile() const; + + //TODO FOR KDE4 make this default true + /** + * Enable highlighting notification for specific TDEActions. + * This is false by default, so, by default, the highlighting + * signals will not be emitted. + * + * @see connectHighlight() + * @see disconnectHighlight() + * @see actionHighlighted() + * @see actionHighlighted() + * @see highlightingEnabled() + */ + void setHighlightingEnabled( bool enable ); + /** + * Return whether highlighting notifications are enabled. + * @see connectHighlight() + * @see disconnectHighlight() + * @see actionHighlighted() + * @see setHighlightingEnabled() + * @see actionHighlighted() + */ + bool highlightingEnabled() const; + + /** + * Call this function if you want to receive a signal whenever a TDEAction is highlighted in a menu or a toolbar. + * This is only needed if you do not add this action to this container. + * You will generally not need to call this function. + * + * @param container A container in which the TDEAction is plugged (must inherit TQPopupMenu or TDEToolBar) + * @param action The action you are interested in + * @see disconnectHighlight() + * @see actionHighlighted() + * @see setHighlightingEnabled() + * @see highlightingEnabled() + * @see actionHighlighted() + */ + void connectHighlight( TQWidget *container, TDEAction *action ); + /** + * Disconnect highlight notifications for a particular pair of contianer and action. + * This is only needed if you do not add this action to this container. + * You will generally not need to call this function. + * + * @param container A container in which the TDEAction is plugged (must inherit TQPopupMenu or TDEToolBar) + * @param action The action you are interested in + * @see connectHighlight() + * @see actionHighlighted() + * @see setHighlightingEnabled() + * @see highlightingEnabled() + * @see actionHighlighted() + */ + void disconnectHighlight( TQWidget *container, TDEAction *action ); + + /** + * The parent KXMLGUIClient, return 0L if not available. + */ + const KXMLGUIClient *parentGUIClient() const; + +signals: + void inserted( TDEAction* ); + void removed( TDEAction* ); + + /** Emitted when @p action is highlighted. + * This is only emitted if you have setHighlightingEnabled() + * @see connectHighlight() + * @see disconnectHighlight() + * @see actionHighlighted() + * @see setHighlightingEnabled() + * @see highlightingEnabled() + */ + void actionHighlighted( TDEAction *action ); + /** Emitted when @p action is highlighed or loses highlighting. + * This is only emitted if you have setHighlightingEnabled() + * @see connectHighlight() + * @see disconnectHighlight() + * @see actionHighlighted() + * @see setHighlightingEnabled() + * @see highlightingEnabled() + */ + void actionHighlighted( TDEAction *action, bool highlight ); + /** Emitted when an action is highlighted, with text + * being the tooltip for the action. + * This is only emitted if you have setHighlightingEnabled() + * + * This is useful to connect to KStatusBar::message(). See + * this class overview for more information. + * + * @see setHighlightingEnabled() + */ + void actionStatusText( const TQString &text ); + /** Emitted when an action loses highlighting. + * This is only emitted if you have setHighlightingEnabled() + * + * @see setHighlightingEnabled() + */ + void clearStatusText(); + +private: + /** + * @internal Only to be called by KXMLGUIFactory::addClient(). + * When actions are being connected, TDEAction needs to know what + * widget it should connect widget-scope actions to, and what + * main window it should connect + */ + void beginXMLPlug( TQWidget *widget ); + void endXMLPlug(); + /** @internal. Only to be called by KXMLGUIFactory::removeClient() */ + void prepareXMLUnplug(); + void unplugShortcuts( TDEAccel* kaccel ); + + void _clear(); + void _insert( TDEAction* ); + void _remove( TDEAction* ); + TDEAction* _take( TDEAction* ); + +private slots: + void slotMenuItemHighlighted( int id ); + void slotToolBarButtonHighlighted( int id, bool highlight ); + void slotMenuAboutToHide(); + void slotDestroyed(); + +private: + TDEAction *findAction( TQWidget *container, int id ); + +#ifndef KDE_NO_COMPAT +public: + TDEActionCollection( TQObject *parent, const char *name = 0, TDEInstance *instance = 0 ); +#endif + +public: + /** + * Add an action to the collection. + * Generally you don't have to call this. The action inserts itself automatically + * into its parent collection. This can be useful however for a short-lived + * collection (e.g. for a popupmenu, where the signals from the collection are needed too). + * (don't forget that in the simple case, a list of actions should be a simple TDEActionPtrList). + * If you manually insert actions into a 2nd collection, don't forget to take them out + * again before destroying the collection. + * @param action The TDEAction to add. + */ + void insert( TDEAction* action); + + /** + * Removes an action from the collection and deletes it. + * Since the TDEAction destructor removes the action from the collection, you generally + * don't have to call this. + * @param action The TDEAction to remove. + */ + void remove( TDEAction* action ); + + /** + * Removes an action from the collection. + * Since the TDEAction destructor removes the action from the collection, you generally + * don't have to call this. + * @return NULL if not found else returns action. + * @param action the TDEAction to remove. + */ + TDEAction* take( TDEAction* action ); + +#ifndef KDE_NO_COMPAT + TDEActionCollection operator+ ( const TDEActionCollection& ) const; + TDEActionCollection& operator= ( const TDEActionCollection& ); + TDEActionCollection& operator+= ( const TDEActionCollection& ); +#endif // !KDE_NO_COMPAT + + // KDE4: clear() doesn't need to be a slot +public slots: + /** + * Clears the entire actionCollection, deleting all actions. + * @see remove + */ + void clear(); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + TDEActionCollection( const char* name, const KXMLGUIClient* parent ); + class TDEActionCollectionPrivate; + TDEActionCollectionPrivate *d; +}; + +#endif diff --git a/tdeui/tdeactionselector.cpp b/tdeui/tdeactionselector.cpp new file mode 100644 index 000000000..e913f01f6 --- /dev/null +++ b/tdeui/tdeactionselector.cpp @@ -0,0 +1,540 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Anders Lund + + 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. +*/ + + +#include "kactionselector.h" + +#include +#include +#include // for spacingHint() +#include +#include +#include +#include +#include +#include +#include +#include + +class TDEActionSelectorPrivate { + public: + TQListBox *availableListBox, *selectedListBox; + TQToolButton *btnAdd, *btnRemove, *btnUp, *btnDown; + TQLabel *lAvailable, *lSelected; + bool moveOnDoubleClick, keyboardEnabled; + TDEActionSelector::ButtonIconSize iconSize; + TQString addIcon, removeIcon, upIcon, downIcon; + TDEActionSelector::InsertionPolicy availableInsertionPolicy, selectedInsertionPolicy; + bool showUpDownButtons; +}; + +//BEGIN Constructor/destructor + +TDEActionSelector::TDEActionSelector( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ + d = new TDEActionSelectorPrivate(); + d->moveOnDoubleClick = true; + d->keyboardEnabled = true; + d->iconSize = SmallIcon; + d->addIcon = TQApplication::reverseLayout()? "back" : "forward"; + d->removeIcon = TQApplication::reverseLayout()? "forward" : "back"; + d->upIcon = "up"; + d->downIcon = "down"; + d->availableInsertionPolicy = Sorted; + d->selectedInsertionPolicy = BelowCurrent; + d->showUpDownButtons = true; + + //int isz = IconSize( KIcon::Small ); + + TQHBoxLayout *lo = new TQHBoxLayout( this ); + lo->setSpacing( KDialog::spacingHint() ); + + TQVBoxLayout *loAv = new TQVBoxLayout( lo ); + d->lAvailable = new TQLabel( i18n("&Available:"), this ); + loAv->addWidget( d->lAvailable ); + d->availableListBox = new TQListBox( this ); + loAv->addWidget( d->availableListBox ); + d->lAvailable->setBuddy( d->availableListBox ); + + TQVBoxLayout *loHBtns = new TQVBoxLayout( lo ); + loHBtns->addStretch( 1 ); + d->btnAdd = new TQToolButton( this ); + loHBtns->addWidget( d->btnAdd ); + d->btnRemove = new TQToolButton( this ); + loHBtns->addWidget( d->btnRemove ); + loHBtns->addStretch( 1 ); + + TQVBoxLayout *loS = new TQVBoxLayout( lo ); + d->lSelected = new TQLabel( i18n("&Selected:"), this ); + loS->addWidget( d->lSelected ); + d->selectedListBox = new TQListBox( this ); + loS->addWidget( d->selectedListBox ); + d->lSelected->setBuddy( d->selectedListBox ); + + TQVBoxLayout *loVBtns = new TQVBoxLayout( lo ); + loVBtns->addStretch( 1 ); + d->btnUp = new TQToolButton( this ); + d->btnUp->setAutoRepeat( true ); + loVBtns->addWidget( d->btnUp ); + d->btnDown = new TQToolButton( this ); + d->btnDown->setAutoRepeat( true ); + loVBtns->addWidget( d->btnDown ); + loVBtns->addStretch( 1 ); + + loadIcons(); + + connect( d->btnAdd, TQT_SIGNAL(clicked()), this, TQT_SLOT(buttonAddClicked()) ); + connect( d->btnRemove, TQT_SIGNAL(clicked()), this, TQT_SLOT(buttonRemoveClicked()) ); + connect( d->btnUp, TQT_SIGNAL(clicked()), this, TQT_SLOT(buttonUpClicked()) ); + connect( d->btnDown, TQT_SIGNAL(clicked()), this, TQT_SLOT(buttonDownClicked()) ); + connect( d->availableListBox, TQT_SIGNAL(doubleClicked(TQListBoxItem*)), + this, TQT_SLOT(itemDoubleClicked(TQListBoxItem*)) ); + connect( d->selectedListBox, TQT_SIGNAL(doubleClicked(TQListBoxItem*)), + this, TQT_SLOT(itemDoubleClicked(TQListBoxItem*)) ); + connect( d->availableListBox, TQT_SIGNAL(currentChanged(TQListBoxItem*)), + this, TQT_SLOT(slotCurrentChanged(TQListBoxItem *)) ); + connect( d->selectedListBox, TQT_SIGNAL(currentChanged(TQListBoxItem*)), + this, TQT_SLOT(slotCurrentChanged(TQListBoxItem *)) ); + + d->availableListBox->installEventFilter( this ); + d->selectedListBox->installEventFilter( this ); +} + +TDEActionSelector::~TDEActionSelector() +{ + delete d; +} + +//END Constructor/destroctor + +//BEGIN Public Methods + +TQListBox *TDEActionSelector::availableListBox() const +{ + return d->availableListBox; +} + +TQListBox *TDEActionSelector::selectedListBox() const +{ + return d->selectedListBox; +} + +void TDEActionSelector::setButtonIcon( const TQString &icon, MoveButton button ) +{ + switch ( button ) + { + case ButtonAdd: + d->addIcon = icon; + d->btnAdd->setIconSet( SmallIconSet( icon, d->iconSize ) ); + break; + case ButtonRemove: + d->removeIcon = icon; + d->btnRemove->setIconSet( SmallIconSet( icon, d->iconSize ) ); + break; + case ButtonUp: + d->upIcon = icon; + d->btnUp->setIconSet( SmallIconSet( icon, d->iconSize ) ); + break; + case ButtonDown: + d->downIcon = icon; + d->btnDown->setIconSet( SmallIconSet( icon, d->iconSize ) ); + break; + default: + kdDebug(13001)<<"TDEActionSelector::setButtonIcon: DAINBREAD!"<btnAdd->setIconSet( iconset ); + break; + case ButtonRemove: + d->btnRemove->setIconSet( iconset ); + break; + case ButtonUp: + d->btnUp->setIconSet( iconset ); + break; + case ButtonDown: + d->btnDown->setIconSet( iconset ); + break; + default: + kdDebug(13001)<<"TDEActionSelector::setButtonIconSet: DAINBREAD!"<btnAdd->setTextLabel( tip ); + break; + case ButtonRemove: + d->btnRemove->setTextLabel( tip ); + break; + case ButtonUp: + d->btnUp->setTextLabel( tip ); + break; + case ButtonDown: + d->btnDown->setTextLabel( tip ); + break; + default: + kdDebug(13001)<<"TDEActionSelector::setButtonToolTip: DAINBREAD!"<btnAdd, text ); + break; + case ButtonRemove: + TQWhatsThis::add( d->btnRemove, text ); + break; + case ButtonUp: + TQWhatsThis::add( d->btnUp, text ); + break; + case ButtonDown: + TQWhatsThis::add( d->btnDown, text ); + break; + default: + kdDebug(13001)<<"TDEActionSelector::setButtonWhatsThis: DAINBREAD!"<btnAdd->setEnabled( d->availableListBox->currentItem() > -1 ); + d->btnRemove->setEnabled( d->selectedListBox->currentItem() > -1 ); + d->btnUp->setEnabled( d->selectedListBox->currentItem() > 0 ); + d->btnDown->setEnabled( d->selectedListBox->currentItem() > -1 && + d->selectedListBox->currentItem() < (int)d->selectedListBox->count() - 1 ); +} + +//END Public Methods + +//BEGIN Properties + +bool TDEActionSelector::moveOnDoubleClick() const +{ + return d->moveOnDoubleClick; +} + +void TDEActionSelector::setMoveOnDoubleClick( bool b ) +{ + d->moveOnDoubleClick = b; +} + +bool TDEActionSelector::keyboardEnabled() const +{ + return d->keyboardEnabled; +} + +void TDEActionSelector::setKeyboardEnabled( bool b ) +{ + d->keyboardEnabled = b; +} + +TQString TDEActionSelector::availableLabel() const +{ + return d->lAvailable->text(); +} + +void TDEActionSelector::setAvailableLabel( const TQString &text ) +{ + d->lAvailable->setText( text ); +} + +TQString TDEActionSelector::selectedLabel() const +{ + return d->lSelected->text(); +} + +void TDEActionSelector::setSelectedLabel( const TQString &text ) +{ + d->lSelected->setText( text ); +} + +TDEActionSelector::ButtonIconSize TDEActionSelector::buttonIconSize() const +{ + return d->iconSize; +} + +void TDEActionSelector::setButtonIconSize( ButtonIconSize size ) +{ + d->iconSize = size; + // reload icons + loadIcons(); +} + +TDEActionSelector::InsertionPolicy TDEActionSelector::availableInsertionPolicy() const +{ + return d->availableInsertionPolicy; +} + +void TDEActionSelector::setAvailableInsertionPolicy( InsertionPolicy p ) +{ + d->availableInsertionPolicy = p; +} + +TDEActionSelector::InsertionPolicy TDEActionSelector::selectedInsertionPolicy() const +{ + return d->selectedInsertionPolicy; +} + +void TDEActionSelector::setSelectedInsertionPolicy( InsertionPolicy p ) +{ + d->selectedInsertionPolicy = p; +} + +bool TDEActionSelector::showUpDownButtons() const +{ + return d->showUpDownButtons; +} + +void TDEActionSelector::setShowUpDownButtons( bool show ) +{ + d->showUpDownButtons = show; + if ( show ) + { + d->btnUp->show(); + d->btnDown->show(); + } + else + { + d->btnUp->hide(); + d->btnDown->hide(); + } +} + +//END Properties + +//BEGIN Public Slots + +void TDEActionSelector::polish() +{ + setButtonsEnabled(); +} + +//END Public Slots + +//BEGIN Protected +void TDEActionSelector::keyPressEvent( TQKeyEvent *e ) +{ + if ( ! d->keyboardEnabled ) return; + if ( (e->state() & TQt::ControlButton) ) + { + switch ( e->key() ) + { + case Key_Right: + buttonAddClicked(); + break; + case Key_Left: + buttonRemoveClicked(); + break; + case Key_Up: + buttonUpClicked(); + break; + case Key_Down: + buttonDownClicked(); + break; + default: + e->ignore(); + return; + } + } +} + +bool TDEActionSelector::eventFilter( TQObject *o, TQEvent *e ) +{ + if ( d->keyboardEnabled && e->type() == TQEvent::KeyPress ) + { + if ( (((TQKeyEvent*)e)->state() & TQt::ControlButton) ) + { + switch ( ((TQKeyEvent*)e)->key() ) + { + case Key_Right: + buttonAddClicked(); + break; + case Key_Left: + buttonRemoveClicked(); + break; + case Key_Up: + buttonUpClicked(); + break; + case Key_Down: + buttonDownClicked(); + break; + default: + return TQWidget::eventFilter( o, e ); + break; + } + return true; + } + else if ( o->inherits( TQLISTBOX_OBJECT_NAME_STRING ) ) + { + switch ( ((TQKeyEvent*)e)->key() ) + { + case Key_Return: + case Key_Enter: + TQListBox *lb = (TQListBox*)o; + int index = lb->currentItem(); + if ( index < 0 ) break; + moveItem( lb->item( index ) ); + return true; + } + } + } + return TQWidget::eventFilter( o, e ); +} + +//END Protected + +//BEGIN Private Slots + +void TDEActionSelector::buttonAddClicked() +{ + // move all selected items from available to selected listbox + TQListBoxItem *item = d->availableListBox->firstItem(); + while ( item ) { + if ( item->isSelected() ) { + d->availableListBox->takeItem( item ); + d->selectedListBox->insertItem( item, insertionIndex( d->selectedListBox, d->selectedInsertionPolicy ) ); + d->selectedListBox->setCurrentItem( item ); + emit added( item ); + item = d->availableListBox->firstItem(); + } else + item = item->next(); + } + if ( d->selectedInsertionPolicy == Sorted ) + d->selectedListBox->sort(); + d->selectedListBox->setFocus(); +} + +void TDEActionSelector::buttonRemoveClicked() +{ + // move all selected items from selected to available listbox + TQListBoxItem *item = d->selectedListBox->firstItem(); + while ( item ) { + if ( item->isSelected() ) { + d->selectedListBox->takeItem( item ); + d->availableListBox->insertItem( item, insertionIndex( d->availableListBox, d->availableInsertionPolicy ) ); + d->availableListBox->setCurrentItem( item ); + emit removed( item ); + item = d->selectedListBox->firstItem(); + } else + item = item->next(); + } + if ( d->availableInsertionPolicy == Sorted ) + d->availableListBox->sort(); + d->availableListBox->setFocus(); +} + +void TDEActionSelector::buttonUpClicked() +{ + int c = d->selectedListBox->currentItem(); + if ( c < 1 ) return; + TQListBoxItem *item = d->selectedListBox->item( c ); + d->selectedListBox->takeItem( item ); + d->selectedListBox->insertItem( item, c-1 ); + d->selectedListBox->setCurrentItem( item ); + emit movedUp( item ); +} + +void TDEActionSelector::buttonDownClicked() +{ + int c = d->selectedListBox->currentItem(); + if ( c < 0 || c == int( d->selectedListBox->count() ) - 1 ) return; + TQListBoxItem *item = d->selectedListBox->item( c ); + d->selectedListBox->takeItem( item ); + d->selectedListBox->insertItem( item, c+1 ); + d->selectedListBox->setCurrentItem( item ); + emit movedDown( item ); +} + +void TDEActionSelector::itemDoubleClicked( TQListBoxItem *item ) +{ + if ( d->moveOnDoubleClick ) + moveItem( item ); +} + +//END Private Slots + +//BEGIN Private Methods + +void TDEActionSelector::loadIcons() +{ + d->btnAdd->setIconSet( SmallIconSet( d->addIcon, d->iconSize ) ); + d->btnRemove->setIconSet( SmallIconSet( d->removeIcon, d->iconSize ) ); + d->btnUp->setIconSet( SmallIconSet( d->upIcon, d->iconSize ) ); + d->btnDown->setIconSet( SmallIconSet( d->downIcon, d->iconSize ) ); +} + +void TDEActionSelector::moveItem( TQListBoxItem *item ) +{ + TQListBox *lbFrom = item->listBox(); + TQListBox *lbTo; + if ( lbFrom == d->availableListBox ) + lbTo = d->selectedListBox; + else if ( lbFrom == d->selectedListBox ) + lbTo = d->availableListBox; + else //?! somewhat unlikely... + return; + + InsertionPolicy p = ( lbTo == d->availableListBox ) ? + d->availableInsertionPolicy : d->selectedInsertionPolicy; + + lbFrom->takeItem( item ); + lbTo->insertItem( item, insertionIndex( lbTo, p ) ); + lbTo->setFocus(); + lbTo->setCurrentItem( item ); + + if ( p == Sorted ) + lbTo->sort(); + if ( lbTo == d->selectedListBox ) + emit added( item ); + else + emit removed( item ); +} + +int TDEActionSelector::insertionIndex( TQListBox *lb, InsertionPolicy policy ) +{ + int index; + switch ( policy ) + { + case BelowCurrent: + index = lb->currentItem(); + if ( index > -1 ) index += 1; + break; + case AtTop: + index = 0; + break; + default: + index = -1; + } + return index; +} + +//END Private Methods +#include "kactionselector.moc" diff --git a/tdeui/tdeactionselector.h b/tdeui/tdeactionselector.h new file mode 100644 index 000000000..7cdd20116 --- /dev/null +++ b/tdeui/tdeactionselector.h @@ -0,0 +1,402 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Anders Lund + + 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 _KACTION_SELECTOR_H_ +#define _KACTION_SELECTOR_H_ + +#include + +#include + +class TQListBox; +class TQListBoxItem; +class TQKeyEvent; +class TQEvent; +class TQIconSet; + +class TDEActionSelectorPrivate; + +/** + @short A widget for selecting and arranging actions/objects + + This widget allows the user to select from a set of objects and arrange + the order of the selected ones using two list boxes labeled "Available" + and "Used" with horizontal arrows in between to move selected objects between + the two, and vertical arrows on the right to arrange the order of the selected + objects. + + The widget moves objects to the other listbox when doubleclicked if + the property moveOnDoubleClick is set to true (default). See moveOnDoubleClick() + and setMoveOnDoubleClick(). + + The user control the widget using the keyboard if enabled (default), + see keyboardEnabled. + + Note that this may conflist with keyboard selection in the selected list box, + if you set that to anything else than TQListBox::Single (which is the default). + + To use it, simply construct an instance and then add items to the two listboxes, + available through lbAvailable() and lbSelected(). Whenever you want, you can retrieve + the selected options using TQListBox methods on lbSelected(). + + This way, you can use your own TQListBoxItem class, allowing you to easily + store object data in those. + + When an item is moved to a listbox, it is placed below the current item + of that listbox. + + Standard arrow icons are used, but you can use icons of your own choice if desired, + see setButtonIcon(). It is also possible to set tooltips and whatsthis help + for the buttons. See setButtonTooltip() and setButtonWhatsThis(). + + To set whatsthis or tooltips for the listboxes, access them through + availableListbox() and selectedListBox(). + + All the moving buttons are automatically set enabled as expected. + + Signals are sent each time an item is moved, allowing you to follow the + users actions if you need to. See addedToSelection(), removedFromSelection(), + movedUp() and movedDown() + + @author Anders Lund +*/ + +class TDEUI_EXPORT TDEActionSelector : public TQWidget { + Q_OBJECT + TQ_ENUMS( ButtonIconSize InsertionPolicy ) + TQ_PROPERTY( bool moveOnDoubleClick READ moveOnDoubleClick WRITE setMoveOnDoubleClick ) + TQ_PROPERTY( bool keyboardEnabled READ keyboardEnabled WRITE setKeyboardEnabled ) + TQ_PROPERTY( TQString availableLabel READ availableLabel WRITE setAvailableLabel ) + TQ_PROPERTY( TQString selectedLabel READ selectedLabel WRITE setSelectedLabel ) + TQ_PROPERTY( ButtonIconSize buttonIconSize READ buttonIconSize WRITE setButtonIconSize ) + TQ_PROPERTY( InsertionPolicy availableInsertionPolicy READ availableInsertionPolicy WRITE setAvailableInsertionPolicy ) + TQ_PROPERTY( InsertionPolicy selectedInsertionPolicy READ selectedInsertionPolicy WRITE setSelectedInsertionPolicy ) + TQ_PROPERTY( bool showUpDownButtons READ showUpDownButtons WRITE setShowUpDownButtons ) + +public: + TDEActionSelector( TQWidget *parent=0, const char *name=0 ); + ~TDEActionSelector(); + + /** + @return The TQListBox holding the available actions + */ + TQListBox *availableListBox() const; + + /** + @return The TQListBox holding the selected actions + */ + TQListBox *selectedListBox() const; + + /** + This enum indentifies the moving buttons + */ + enum MoveButton { + ButtonAdd, + ButtonRemove, + ButtonUp, + ButtonDown + }; + + /** + This enum identifies the icon sizes, used for the move buttons. + The values correspond to the following pixel sizes: + @li SmallIcon - the return value of IconSize( KIcon::Small ), the user defined size + of a small icon in KDE. This is the default setting. + @li Small - 16px + @li Medium - 22px + @li Large - 32px + @li XLarge - 48px + */ + enum ButtonIconSize { + SmallIcon, + Small, + Medium, + Large, + XLarge + }; + + /** + This enum defines policies for where to insert moved items in a listbox. + The following policies are currently defined: + @li BelowCurrent - The item is inserted below the listbox' + currentItem() or at the end if there is no curent item. + @li Sorted - The listbox is sort()ed after one or more items are inserted. + @li AtTop - The item is inserted at index 0 in the listbox. + @li AtBottom - The item is inserted at the end of the listbox. + + @sa availableInsertionPolicy(), setAvailableInsertionPolicy(), + selectedInsertionPolicy(), setSelectedInsertionPolicy(). + */ + enum InsertionPolicy { + BelowCurrent, + Sorted, + AtTop, + AtBottom + }; + + /** + @return Wheather moveOnDoubleClcik is enabled. + + If enabled, an item in any listbox will be moved to the other one whenever + doubleclicked. + @sa setMoveOnDoubleClick() + */ + bool moveOnDoubleClick() const; + + /** + Sets moveOnDoubleClick to @p enable + @sa moveOnDoubleClick() + */ + void setMoveOnDoubleClick( bool enable ); + + /** + @return Weather keyboard control is enabled. + + When Keyboard control is enabled, the widget will react to + the following keyboard actions: + @li CTRL + Right - simulate clicking the add button + @li CTRL + Left - simulate clicking the remove button + @li CTRL + Up - simulate clicking the up button + @li CTRL + Down - simulate clicking the down button + + Additionally, pressing RETURN or ENTER on one of the list boxes + will cause the current item of that listbox to be moved to the other + listbox. + + The keyboard actions are enabled by default. + + @sa setKeyboardEnabled() + */ + bool keyboardEnabled() const; + + /** + Sets the keyboard enabled depending on @p enable. + @sa keyboardEnabled() + */ + void setKeyboardEnabled( bool enable ); + + /** + @return The text of the label for the available items listbox. + */ + TQString availableLabel() const; + + /** + Sets the label for the available items listbox to @p text. + Note that this label has the listbox as its @e buddy, so that + if you have a single ampersand in the text, the following character + will become the accellerator to focus te listbox. + */ + void setAvailableLabel( const TQString & text ); + + /** + @return the label of the selected items listbox. + */ + TQString selectedLabel() const; + + /** + Sets the label for the selected items listbox to @p text. + Note that this label has the listbox as its @e buddy, so that + if you have a single ampersand in the text, the following character + will become the accellerator to focus te listbox. + */ + void setSelectedLabel( const TQString & text ); + + /** + @return the current ButtonIconSize. + */ + ButtonIconSize buttonIconSize() const; + + /** + Sets the button icon size. + See ButtonIconSize for the possible values and their pixel meaning. + */ + void setButtonIconSize( ButtonIconSize size ); + + /** + @return The current insertion policy for the available listbox. + The default policy for the available listbox is Sorted. + See also InsertionPolicy, setAvailableInsertionPolicy(). + */ + InsertionPolicy availableInsertionPolicy() const; + + /** + Sets the insertion policy for the available listbox. + See also InsertionPolicy, availableInsertionPolicy(). + */ + void setAvailableInsertionPolicy( InsertionPolicy policy ); + + /** + @return The current insertion policy for the selected listbox. + The default policy for the selected listbox is BelowCurrent. + See also InsertionPolicy, setSelectedInsertionPolicy(). + */ + InsertionPolicy selectedInsertionPolicy() const; + + /** + Sets the insertion policy for the selected listbox. + See also InsertionPolicy, selectedInsertionPolicy(). + */ + void setSelectedInsertionPolicy( InsertionPolicy policy ); + + /** + @return wheather the Up and Down buttons should be displayed. + */ + bool showUpDownButtons() const; + + /** + Sets wheather the Up and Down buttons should be displayed + according to @p show + */ + void setShowUpDownButtons( bool show ); + + /** + Sets the pixmap of the button @p button to @p icon. + It calls SmallIconSet(pm) to generate the icon set. + */ + void setButtonIcon( const TQString &icon, MoveButton button ); + + /** + Sets the iconset for button @p button to @p iconset. + You can use this method to et a costum icon set. Either + created by TQIconSet, or use the application instance of + KIconLoader (recommended). + */ + void setButtonIconSet( const TQIconSet &iconset, MoveButton button ); + + /** + Sets the tooltip for the button @p button to @p tip. + */ + void setButtonTooltip( const TQString &tip, MoveButton button ); + + /** + Sets the whatsthis help for button @p button to @p text. + */ + void setButtonWhatsThis( const TQString &text, MoveButton button ); + + /** + Sets the enabled state of all moving buttons to reflect the current + options. + + Be sure to call this if you add or removes items to either listbox after the + widget is show()n + */ + void setButtonsEnabled(); + +signals: + /** + Emitted when an item is moved to the "selected" listbox. + */ + void added( TQListBoxItem *item ); + + /** + Emitted when an item is moved out of the "selected" listbox. + */ + void removed( TQListBoxItem *item ); + + /** + Emitted when an item is moved upwards in the "selected" listbox. + */ + void movedUp( TQListBoxItem *item ); + + /** + Emitted when an item is moved downwards in the "selected" listbox. + */ + void movedDown( TQListBoxItem *item ); + + /** + Emitted when an item is moved to the "selected" listbox. + */ +// void addedToSelection( TQListBoxItem *item ); + +public slots: + /** + Reimplemented for internal reasons. + (calls setButtonsEnabled()) + */ + void polish(); + +protected: + /** + Reimplamented for internal reasons. + */ + void keyPressEvent( TQKeyEvent * ); + + /** + Reimplemented for internal reasons. + */ + bool eventFilter( TQObject *, TQEvent * ); + +private slots: + /** + Move selected item from available box to the selected box + */ + void buttonAddClicked(); + + /** + Move selected item from selected box to available box + */ + void buttonRemoveClicked(); + + /** + Move selected item in selected box upwards + */ + void buttonUpClicked(); + + /** + Move seleted item in selected box downwards + */ + void buttonDownClicked(); + + /** + Moves the item @p item to the other listbox if moveOnDoubleClick is enabled. + */ + void itemDoubleClicked( TQListBoxItem *item ); + + /** + connected to both list boxes to set the buttons enabled + */ + void slotCurrentChanged( TQListBoxItem * ) { setButtonsEnabled(); } + +private: + + /** + Move item @p item to the other listbox + */ + void moveItem( TQListBoxItem *item ); + + /** + loads the icons for the move buttons. + */ + void loadIcons(); + + /** + @return the index to insert an item into listbox @p lb, + given InsertionPolicy @p policy. + + Note that if policy is Sorted, this will return -1. + Sort the listbox after inserting the item in that case. + */ + int insertionIndex( TQListBox *lb, InsertionPolicy policy ); + + /** @private + Private data storage + */ + TDEActionSelectorPrivate *d; +}; + +#endif // _KACTION_SELECTOR_H_ diff --git a/tdeui/tdeactionshortcutlist.h b/tdeui/tdeactionshortcutlist.h new file mode 100644 index 000000000..ac8ac020d --- /dev/null +++ b/tdeui/tdeactionshortcutlist.h @@ -0,0 +1,79 @@ +#ifndef _KACTIONSHORTCUTLIST_H +#define _KACTIONSHORTCUTLIST_H + +#include +#include + +//--------------------------------------------------------------------- +// class TDEActionShortcutList +//--------------------------------------------------------------------- + +class TDEAccelShortcutListPrivate; +class TDEUI_EXPORT TDEActionShortcutList : public TDEShortcutList +{ + public: + TDEActionShortcutList( TDEActionCollection* ); + virtual ~TDEActionShortcutList(); + + virtual uint count() const; + virtual TQString name( uint index ) const; + virtual TQString label( uint index ) const; + virtual TQString whatsThis( uint index ) const; + virtual const TDEShortcut& shortcut( uint index ) const; + virtual const TDEShortcut& shortcutDefault( uint index ) const; + virtual bool isConfigurable( uint index ) const; + virtual bool setShortcut( uint index, const TDEShortcut& shortcut ); + + virtual const TDEInstance* instance() const; + + virtual TQVariant getOther( Other, uint index ) const; + virtual bool setOther( Other, uint index, TQVariant ); + + virtual bool save() const; + + const TDEAction *action( uint ) const; + + protected: + TDEActionCollection& m_actions; + + protected: + virtual void virtual_hook( int id, void* data ); + private: + TDEAccelShortcutListPrivate* d; +}; + +//--------------------------------------------------------------------- +// class TDEActionPtrShortcutList +//--------------------------------------------------------------------- + +class TDEAccelShortcutListPrivate; +class TDEUI_EXPORT TDEActionPtrShortcutList : public TDEShortcutList +{ + public: + TDEActionPtrShortcutList( TDEActionPtrList& ); + virtual ~TDEActionPtrShortcutList(); + + virtual uint count() const; + virtual TQString name( uint index ) const; + virtual TQString label( uint index ) const; + virtual TQString whatsThis( uint index ) const; + virtual const TDEShortcut& shortcut( uint index ) const; + virtual const TDEShortcut& shortcutDefault( uint index ) const; + virtual bool isConfigurable( uint index ) const; + virtual bool setShortcut( uint index, const TDEShortcut& shortcut); + + virtual TQVariant getOther( Other, uint index ) const; + virtual bool setOther( Other, uint index, TQVariant ); + + virtual bool save() const; + + protected: + TDEActionPtrList& m_actions; + + protected: + virtual void virtual_hook( int id, void* data ); + private: + TDEAccelShortcutListPrivate* d; +}; + +#endif // !_KACTIONSHORTCUTLIST_H diff --git a/tdeui/tdefontcombo.cpp b/tdeui/tdefontcombo.cpp new file mode 100644 index 000000000..8ce088f8b --- /dev/null +++ b/tdeui/tdefontcombo.cpp @@ -0,0 +1,382 @@ +/* This file is part of the KDE libraries + Copyright (c) 2001 Malte Starostik + + 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. +*/ + + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kfontcombo.h" +#include "kfontcombo.moc" + +#include +#include +#include +#include +#include +#include +#include + +#include + + +struct TDEFontComboPrivate +{ + TDEFontComboPrivate() + : bold(false), + italic(false), + underline(false), + strikeOut(false), + modified(false), + size(0), + lineSpacing(0) + { + } + + bool bold : 1; + bool italic : 1; + bool underline : 1; + bool strikeOut : 1; + bool displayFonts : 1; + bool modified : 1; + int size; + int lineSpacing; + TQString defaultFamily; +}; + +class TDEFontListItem : public TQListBoxItem +{ +public: + TDEFontListItem(const TQString &fontName, TDEFontCombo *combo); + virtual ~TDEFontListItem(); + + virtual int width(const TQListBox *) const; + virtual int height(const TQListBox *) const; + + void updateFont(); + +protected: + virtual void paint(TQPainter *p); + +private: + void createFont(); + +private: + TDEFontCombo *m_combo; + TQString m_fontName; + TQFont *m_font; + bool m_canPaintName; +}; + +TDEFontListItem::TDEFontListItem(const TQString &fontName, TDEFontCombo *combo) + : TQListBoxItem(combo->listBox()), + m_combo(combo), + m_fontName(fontName), + m_font(0), + m_canPaintName(true) +{ + setText(fontName); +} + +TDEFontListItem::~TDEFontListItem() +{ + delete m_font; +} + +int TDEFontListItem::width(const TQListBox *lb) const +{ + if (m_font) + return TQFontMetrics(*m_font).width(text()) + 6; + return lb->fontMetrics().width(text()) + 6; +} + +int TDEFontListItem::height(const TQListBox *lb) const +{ + if (m_combo->d->displayFonts) + return m_combo->d->lineSpacing + 2; + TQFontMetrics fm(lb->fontMetrics()); + return fm.lineSpacing() + 2; +} + +void TDEFontListItem::paint(TQPainter *p) +{ + if (m_combo->d->displayFonts) + { + if (!m_font) + createFont(); + + TQString t = m_fontName; + if (p->device() != m_combo) + { + if (m_canPaintName) + p->setFont(*m_font); + else + t = TQString::fromLatin1("(%1)").arg(m_fontName); + } + TQFontMetrics fm(p->fontMetrics()); + p->drawText(3, (m_combo->d->lineSpacing + fm.ascent() + fm.leading() / 2) / 2, t); + } + else + { + TQFontMetrics fm(p->fontMetrics()); + p->drawText(3, fm.ascent() + fm.leading() / 2, m_fontName); + } +} + +void TDEFontListItem::updateFont() +{ + if (!m_font) + return; + + m_font->setBold(m_combo->d->bold); + m_font->setItalic(m_combo->d->italic); + m_font->setUnderline(m_combo->d->underline); + m_font->setStrikeOut(m_combo->d->strikeOut); + m_font->setPointSize(m_combo->d->size); +} + +void TDEFontListItem::createFont() +{ + if (m_font) + return; + + m_font = new TQFont(m_fontName); + TQFontMetrics fm(*m_font); + for (unsigned int i = 0; i < m_fontName.length(); ++i) + if (!fm.inFont(m_fontName[i])) + { + m_canPaintName = false; + break; + } + updateFont(); +} + +TDEFontCombo::TDEFontCombo(TQWidget *parent, const char *name) + : KComboBox(true, parent, name) +{ + init(); + TQStringList families; + TDEFontChooser::getFontList(families, 0); + setFonts(families); +} + +TDEFontCombo::TDEFontCombo(const TQStringList &fonts, TQWidget *parent, const char *name) + : KComboBox(true, parent, name) +{ + init(); + setFonts(fonts); +} + +void TDEFontCombo::setFonts(const TQStringList &fonts) +{ + clear(); + for (TQStringList::ConstIterator it = fonts.begin(); it != fonts.end(); ++it) + new TDEFontListItem(*it, this); +} + +/* + * Maintenance note: Keep in sync with TDEFontAction::setFont() + */ +void TDEFontCombo::setCurrentFont(const TQString &family) +{ + TQString lowerName = family.lower(); + int c = count(); + for(int i = 0; i < c; i++) + { + if (text(i).lower() == lowerName) + { + setCurrentItem(i); + d->defaultFamily = text(i); + d->modified = false; + return; + } + } + int x = lowerName.find(" ["); + if (x>-1) + { + lowerName = lowerName.left(x); + for(int i = 0; i < c; i++) + { + if (text(i).lower() == lowerName) + { + setCurrentItem(i); + d->defaultFamily = text(i); + d->modified = false; + return; + } + } + } + + lowerName += " ["; + for(int i = 0; i < c; i++) + { + if (text(i).lower().startsWith(lowerName)) + { + setCurrentItem(i); + d->defaultFamily = text(i); + d->modified = false; + return; + } + } + + // nothing matched yet, try a fontconfig reverse lookup and + // check again to solve an alias + FcPattern *pattern = NULL; + FcConfig *config = NULL; + TQString realFamily; + TQRegExp regExp("[-:]"); + pattern = FcNameParse( (unsigned char*) family.ascii() ); + FcDefaultSubstitute(pattern); + FcConfigSubstitute (config, pattern, FcMatchPattern); + pattern = FcFontMatch(NULL, pattern, NULL); + realFamily = (char*)FcNameUnparse(pattern); + realFamily.remove(realFamily.find(regExp), realFamily.length()); + + if ( !realFamily.isEmpty() && realFamily != family ) + setCurrentFont( realFamily ); +} + +void TDEFontCombo::slotModified( int ) +{ + d->modified = 1; +} + +TQString TDEFontCombo::currentFont() const +{ + if (d->modified) + return currentText(); + return d->defaultFamily; +} + +void TDEFontCombo::setCurrentItem(int i) +{ + d->modified = true; + TQComboBox::setCurrentItem(i); +} + +void TDEFontCombo::init() +{ + d = new TDEFontComboPrivate; + d->displayFonts = displayFonts(); + setInsertionPolicy(NoInsertion); + setAutoCompletion(true); + setSize(12); + connect( this, TQT_SIGNAL(highlighted(int)), TQT_SLOT(slotModified(int))); +} + +TDEFontCombo::~TDEFontCombo() +{ + delete d; +} + +void TDEFontCombo::setBold(bool bold) +{ + if (d->bold == bold) + return; + d->bold = bold; + updateFonts(); +} + +bool TDEFontCombo::bold() const +{ + return d->bold; +} + +void TDEFontCombo::setItalic(bool italic) +{ + if (d->italic == italic) + return; + d->italic = italic; + updateFonts(); +} + +bool TDEFontCombo::italic() const +{ + return d->italic; +} + +void TDEFontCombo::setUnderline(bool underline) +{ + if (d->underline == underline) + return; + d->underline = underline; + updateFonts(); +} + +bool TDEFontCombo::underline() const +{ + return d->underline; +} + +void TDEFontCombo::setStrikeOut(bool strikeOut) +{ + if (d->strikeOut == strikeOut) + return; + d->strikeOut = strikeOut; + updateFonts(); +} + +bool TDEFontCombo::strikeOut() const +{ + return d->strikeOut; +} + +void TDEFontCombo::setSize(int size) +{ + if (d->size == size) + return; + d->size = size; + TQFont f; + f.setPointSize(size); + TQFontMetrics fm(f); + d->lineSpacing = fm.lineSpacing(); + updateFonts(); +} + +int TDEFontCombo::size() const +{ + return d->size; +} + +void TDEFontCombo::updateFonts() +{ + if (!d->displayFonts) + return; + + for (unsigned int i = 0; i < listBox()->count(); ++i) + { + TDEFontListItem *item = static_cast(listBox()->item(i)); + item->updateFont(); + } +} + +bool TDEFontCombo::displayFonts() +{ + TDEConfigGroupSaver saver(TDEGlobal::config(), "KDE"); + return TDEGlobal::config()->readBoolEntry("DisplayFontItems", true); +} + +void TDEFontCombo::virtual_hook( int id, void* data ) +{ KComboBox::virtual_hook( id, data ); } + diff --git a/tdeui/tdefontcombo.h b/tdeui/tdefontcombo.h new file mode 100644 index 000000000..13c55215b --- /dev/null +++ b/tdeui/tdefontcombo.h @@ -0,0 +1,179 @@ +/* This file is part of the KDE libraries + Copyright (c) 2001 Malte Starostik + + 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. +*/ + +// $Id$ + +#ifndef _KFONTCOMBO_H_ +#define _KFONTCOMBO_H_ + +#include + +/** + * @short A combobox that lists the available fonts. + * + * The items are painted using the respective font itself, so the user + * can easily choose a font based on its look. This can be turned off + * globally if the user wishes so. + * + * @author Malte Starostik + */ +class TDEUI_EXPORT TDEFontCombo : public KComboBox +{ + Q_OBJECT + TQ_PROPERTY(TQString family READ currentFont WRITE setCurrentFont) + TQ_PROPERTY(bool bold READ bold WRITE setBold DESIGNABLE true) + TQ_PROPERTY(bool italic READ italic WRITE setItalic DESIGNABLE true) + TQ_PROPERTY(bool underline READ underline WRITE setUnderline DESIGNABLE true) + TQ_PROPERTY(bool strikeOut READ strikeOut WRITE setStrikeOut DESIGNABLE true) + TQ_PROPERTY(int fontSize READ size WRITE setSize DESIGNABLE true) +public: + /** + * Constructor + * + * @param parent The parent widget + * @param name The object name for the widget + */ + TDEFontCombo(TQWidget *parent, const char *name = 0); + /** + * Constructor that takes an already initialzed font list + * + * @param fonts A list of fonts to show + * @param parent The parent widget + * @param name The object name for the widget + */ + TDEFontCombo(const TQStringList &fonts, TQWidget *parent, const char *name = 0); + /** + * Destructor + */ + virtual ~TDEFontCombo(); + + /** + * Sets the font list. + * + * @param fonts Font list to show + */ + void setFonts(const TQStringList &fonts); + /** + * Sets the currently selected font. + * + * @param family Font to select. + */ + void setCurrentFont(const TQString &family); + /** + * @return the currently selected font. + */ + TQString currentFont() const; + + /** + * Sets the listed fonts to bold or normal. + * + * @param bold Set to true to display fonts in bold + */ + void setBold(bool bold); + /** + * Returns the current bold status. + * + * @return true if fonts are bold + */ + bool bold() const; + /** + * Sets the listed fonts to italic or regular. + * + * @param italic Set to true to display fonts italic + */ + void setItalic(bool italic); + /** + * Returns the current italic status + * + * @return True if fonts are italic + */ + bool italic() const; + /** + * Sets the listed fonts to underlined or not underlined + * + * @param underline Set to true to display fonts underlined + */ + void setUnderline(bool underline); + /** + * Returns the current underline status + * + * @return True if fonts are underlined + */ + bool underline() const; + /** + * Sets the listed fonts to striked out or not + * + * @param strikeOut Set to true to display fonts striked out + */ + void setStrikeOut(bool strikeOut); + /** + * Returns the current strike out status + * + * @return True if fonts are striked out + */ + bool strikeOut() const; + /** + * Sets the listed fonts' size + * + * @param size Set to the point size to display the fonts in + */ + void setSize(int size); + /** + * Returns the current font size + * + * @return The point size of the fonts + */ + int size() const; + + /** + * Returns the user's setting of whether the items should be painted + * in the respective fonts or not + * + * @return True if the respective fonts are used for painting + */ + static bool displayFonts(); + + virtual void setCurrentItem(int i); + +protected slots: + /** + * @internal + * Listens to highlighted(int) + */ + void slotModified( int i ); + +protected: + /** + * Updated the combo's listBox() to reflect changes made to the + * fonts' attributed + */ + void updateFonts(); + +private: + void init(); + +private: + friend class TDEFontListItem; +protected: + virtual void virtual_hook( int id, void* data ); +private: + struct TDEFontComboPrivate *d; +}; + +#endif + diff --git a/tdeui/tdefontdialog.cpp b/tdeui/tdefontdialog.cpp new file mode 100644 index 000000000..107755e7f --- /dev/null +++ b/tdeui/tdefontdialog.cpp @@ -0,0 +1,799 @@ +/* + + Requires the Qt widget libraries, available at no cost at + http://www.troll.no + + Copyright (C) 1996 Bernd Johannes Wuebben + Copyright (c) 1999 Preston Brown + Copyright (c) 1999 Mario Weilguni + + This library 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. + + 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. +*/ + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kfontdialog.moc" + +static int minimumListWidth( const TQListBox *list ) +{ + int w=0; + for( uint i=0; icount(); i++ ) + { + int itemWidth = list->item(i)->width(list); + w = QMAX(w,itemWidth); + } + if( w == 0 ) { w = 40; } + w += list->frameWidth() * 2; + w += list->verticalScrollBar()->sizeHint().width(); + return w; +} + +static int minimumListHeight( const TQListBox *list, int numVisibleEntry ) +{ + int w = list->count() > 0 ? list->item(0)->height(list) : + list->fontMetrics().lineSpacing(); + + if( w < 0 ) { w = 10; } + if( numVisibleEntry <= 0 ) { numVisibleEntry = 4; } + return ( w * numVisibleEntry + 2 * list->frameWidth() ); +} + +class TDEFontChooser::TDEFontChooserPrivate +{ +public: + TDEFontChooserPrivate() + { m_palette.setColor(TQPalette::Active, TQColorGroup::Text, Qt::black); + m_palette.setColor(TQPalette::Active, TQColorGroup::Base, Qt::white); } + TQPalette m_palette; +}; + +TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, + bool onlyFixed, const TQStringList &fontList, + bool makeFrame, int visibleListSize, bool diff, + TQButton::ToggleState *sizeIsRelativeState ) + : TQWidget(parent, name), usingFixed(onlyFixed) +{ + charsetsCombo = 0; + + TQString mainWhatsThisText = + i18n( "Here you can choose the font to be used." ); + TQWhatsThis::add( this, mainWhatsThisText ); + + d = new TDEFontChooserPrivate; + TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint() ); + int checkBoxGap = KDialog::spacingHint() / 2; + + TQWidget *page; + TQGridLayout *gridLayout; + int row = 0; + if( makeFrame ) + { + page = new TQGroupBox( i18n("Requested Font"), this ); + topLayout->addWidget(page); + gridLayout = new TQGridLayout( page, 5, 3, KDialog::marginHint(), KDialog::spacingHint() ); + gridLayout->addRowSpacing( 0, fontMetrics().lineSpacing() ); + row = 1; + } + else + { + page = new TQWidget( this ); + topLayout->addWidget(page); + gridLayout = new TQGridLayout( page, 4, 3, 0, KDialog::spacingHint() ); + } + + // + // first, create the labels across the top + // + TQHBoxLayout *familyLayout = new TQHBoxLayout(); + familyLayout->addSpacing( checkBoxGap ); + if (diff) { + familyCheckbox = new TQCheckBox(i18n("Font"), page); + connect(familyCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox())); + familyLayout->addWidget(familyCheckbox, 0, Qt::AlignLeft); + TQString familyCBToolTipText = + i18n("Change font family?"); + TQString familyCBWhatsThisText = + i18n("Enable this checkbox to change the font family settings."); + TQWhatsThis::add( familyCheckbox, familyCBWhatsThisText ); + TQToolTip::add( familyCheckbox, familyCBToolTipText ); + familyLabel = 0; + } else { + familyCheckbox = 0; + familyLabel = new TQLabel( i18n("Font:"), page, "familyLabel" ); + familyLayout->addWidget(familyLabel, 1, Qt::AlignLeft); + } + gridLayout->addLayout(familyLayout, row, 0 ); + + TQHBoxLayout *styleLayout = new TQHBoxLayout(); + if (diff) { + styleCheckbox = new TQCheckBox(i18n("Font style"), page); + connect(styleCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox())); + styleLayout->addWidget(styleCheckbox, 0, Qt::AlignLeft); + TQString styleCBToolTipText = + i18n("Change font style?"); + TQString styleCBWhatsThisText = + i18n("Enable this checkbox to change the font style settings."); + TQWhatsThis::add( styleCheckbox, styleCBWhatsThisText ); + TQToolTip::add( styleCheckbox, styleCBToolTipText ); + styleLabel = 0; + } else { + styleCheckbox = 0; + styleLabel = new TQLabel( i18n("Font style:"), page, "styleLabel"); + styleLayout->addWidget(styleLabel, 1, Qt::AlignLeft); + } + styleLayout->addSpacing( checkBoxGap ); + gridLayout->addLayout(styleLayout, row, 1 ); + + TQHBoxLayout *sizeLayout = new TQHBoxLayout(); + if (diff) { + sizeCheckbox = new TQCheckBox(i18n("Size"),page); + connect(sizeCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox())); + sizeLayout->addWidget(sizeCheckbox, 0, Qt::AlignLeft); + TQString sizeCBToolTipText = + i18n("Change font size?"); + TQString sizeCBWhatsThisText = + i18n("Enable this checkbox to change the font size settings."); + TQWhatsThis::add( sizeCheckbox, sizeCBWhatsThisText ); + TQToolTip::add( sizeCheckbox, sizeCBToolTipText ); + sizeLabel = 0; + } else { + sizeCheckbox = 0; + sizeLabel = new TQLabel( i18n("Size:"), page, "sizeLabel"); + sizeLayout->addWidget(sizeLabel, 1, Qt::AlignLeft); + } + sizeLayout->addSpacing( checkBoxGap ); + sizeLayout->addSpacing( checkBoxGap ); // prevent label from eating border + gridLayout->addLayout(sizeLayout, row, 2 ); + + row ++; + + // + // now create the actual boxes that hold the info + // + familyListBox = new TDEListBox( page, "familyListBox"); + familyListBox->setEnabled( !diff ); + gridLayout->addWidget( familyListBox, row, 0 ); + TQString fontFamilyWhatsThisText = + i18n("Here you can choose the font family to be used." ); + TQWhatsThis::add( familyListBox, fontFamilyWhatsThisText ); + TQWhatsThis::add(diff?(TQWidget *) familyCheckbox:(TQWidget *) familyLabel, fontFamilyWhatsThisText ); + connect(familyListBox, TQT_SIGNAL(highlighted(const TQString &)), + TQT_SLOT(family_chosen_slot(const TQString &))); + if(!fontList.isEmpty()) + { + familyListBox->insertStringList(fontList); + } + else + { + fillFamilyListBox(onlyFixed); + } + + familyListBox->setMinimumWidth( minimumListWidth( familyListBox ) ); + familyListBox->setMinimumHeight( + minimumListHeight( familyListBox, visibleListSize ) ); + + styleListBox = new TDEListBox( page, "styleListBox"); + styleListBox->setEnabled( !diff ); + gridLayout->addWidget(styleListBox, row, 1); + TQString fontStyleWhatsThisText = + i18n("Here you can choose the font style to be used." ); + TQWhatsThis::add( styleListBox, fontStyleWhatsThisText ); + TQWhatsThis::add(diff?(TQWidget *)styleCheckbox:(TQWidget *)styleLabel, fontFamilyWhatsThisText ); + styleListBox->insertItem(i18n("Regular")); + styleListBox->insertItem(i18n("Italic")); + styleListBox->insertItem(i18n("Bold")); + styleListBox->insertItem(i18n("Bold Italic")); + styleListBox->setMinimumWidth( minimumListWidth( styleListBox ) ); + styleListBox->setMinimumHeight( + minimumListHeight( styleListBox, visibleListSize ) ); + + connect(styleListBox, TQT_SIGNAL(highlighted(const TQString &)), + TQT_SLOT(style_chosen_slot(const TQString &))); + + + sizeListBox = new TDEListBox( page, "sizeListBox"); + sizeOfFont = new KIntNumInput( page, "sizeOfFont"); + sizeOfFont->setMinValue(4); + + sizeListBox->setEnabled( !diff ); + sizeOfFont->setEnabled( !diff ); + if( sizeIsRelativeState ) { + TQString sizeIsRelativeCBText = + i18n("Relative"); + TQString sizeIsRelativeCBToolTipText = + i18n("Font size
fixed or relative
to environment"); + TQString sizeIsRelativeCBWhatsThisText = + i18n("Here you can switch between fixed font size and font size " + "to be calculated dynamically and adjusted to changing " + "environment (e.g. widget dimensions, paper size)." ); + sizeIsRelativeCheckBox = new TQCheckBox( sizeIsRelativeCBText, + page, + "sizeIsRelativeCheckBox" ); + sizeIsRelativeCheckBox->setTristate( diff ); + TQGridLayout *sizeLayout2 = new TQGridLayout( 3,2, KDialog::spacingHint()/2, "sizeLayout2" ); + gridLayout->addLayout(sizeLayout2, row, 2); + sizeLayout2->setColStretch( 1, 1 ); // to prevent text from eating the right border + sizeLayout2->addMultiCellWidget( sizeOfFont, 0, 0, 0, 1); + sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,1); + sizeLayout2->addWidget(sizeIsRelativeCheckBox, 2, 0, Qt::AlignLeft); + TQWhatsThis::add( sizeIsRelativeCheckBox, sizeIsRelativeCBWhatsThisText ); + TQToolTip::add( sizeIsRelativeCheckBox, sizeIsRelativeCBToolTipText ); + } + else { + sizeIsRelativeCheckBox = 0L; + TQGridLayout *sizeLayout2 = new TQGridLayout( 2,1, KDialog::spacingHint()/2, "sizeLayout2" ); + gridLayout->addLayout(sizeLayout2, row, 2); + sizeLayout2->addWidget( sizeOfFont, 0, 0); + sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,0); + } + TQString fontSizeWhatsThisText = + i18n("Here you can choose the font size to be used." ); + TQWhatsThis::add( sizeListBox, fontSizeWhatsThisText ); + TQWhatsThis::add( diff?(TQWidget *)sizeCheckbox:(TQWidget *)sizeLabel, fontSizeWhatsThisText ); + + fillSizeList(); + sizeListBox->setMinimumWidth( minimumListWidth(sizeListBox) + + sizeListBox->fontMetrics().maxWidth() ); + sizeListBox->setMinimumHeight( + minimumListHeight( sizeListBox, visibleListSize ) ); + + connect( sizeOfFont, TQT_SIGNAL( valueChanged(int) ), + TQT_SLOT(size_value_slot(int))); + + connect( sizeListBox, TQT_SIGNAL(highlighted(const TQString&)), + TQT_SLOT(size_chosen_slot(const TQString&)) ); + sizeListBox->setSelected(sizeListBox->findItem(TQString::number(10)), true); // default to 10pt. + + row ++; + + row ++; + sampleEdit = new TQLineEdit( page, "sampleEdit"); + TQFont tmpFont( TDEGlobalSettings::generalFont().family(), 64, TQFont::Black ); + sampleEdit->setFont(tmpFont); + //i18n: This is a classical test phrase. (It contains all letters from A to Z.) + sampleEdit->setText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog")); + sampleEdit->setMinimumHeight( sampleEdit->fontMetrics().lineSpacing() ); + sampleEdit->setAlignment(Qt::AlignCenter); + gridLayout->addMultiCellWidget(sampleEdit, 4, 4, 0, 2); + TQString sampleEditWhatsThisText = + i18n("This sample text illustrates the current settings. " + "You may edit it to test special characters." ); + TQWhatsThis::add( sampleEdit, sampleEditWhatsThisText ); + connect(this, TQT_SIGNAL(fontSelected(const TQFont &)), + TQT_SLOT(displaySample(const TQFont &))); + + TQVBoxLayout *vbox; + if( makeFrame ) + { + page = new TQGroupBox( i18n("Actual Font"), this ); + topLayout->addWidget(page); + vbox = new TQVBoxLayout( page, KDialog::spacingHint() ); + vbox->addSpacing( fontMetrics().lineSpacing() ); + } + else + { + page = new TQWidget( this ); + topLayout->addWidget(page); + vbox = new TQVBoxLayout( page, 0, KDialog::spacingHint() ); + TQLabel *label = new TQLabel( i18n("Actual Font"), page ); + vbox->addWidget( label ); + } + + xlfdEdit = new TQLineEdit( page, "xlfdEdit" ); + vbox->addWidget( xlfdEdit ); + + // lets initialize the display if possible + setFont( TDEGlobalSettings::generalFont(), usingFixed ); + // check or uncheck or gray out the "relative" checkbox + if( sizeIsRelativeState && sizeIsRelativeCheckBox ) + setSizeIsRelative( *sizeIsRelativeState ); + + TDEConfig *config = TDEGlobal::config(); + TDEConfigGroupSaver saver(config, TQString::fromLatin1("General")); + showXLFDArea(config->readBoolEntry(TQString::fromLatin1("fontSelectorShowXLFD"), false)); +} + +TDEFontChooser::~TDEFontChooser() +{ + delete d; +} + +void TDEFontChooser::fillSizeList() { + if(! sizeListBox) return; //assertion. + + static const int c[] = + { + 4, 5, 6, 7, + 8, 9, 10, 11, + 12, 13, 14, 15, + 16, 17, 18, 19, + 20, 22, 24, 26, + 28, 32, 48, 64, + 0 + }; + for(int i = 0; c[i]; ++i) + { + sizeListBox->insertItem(TQString::number(c[i])); + } +} + +void TDEFontChooser::setColor( const TQColor & col ) +{ + d->m_palette.setColor( TQPalette::Active, TQColorGroup::Text, col ); + TQPalette pal = sampleEdit->palette(); + pal.setColor( TQPalette::Active, TQColorGroup::Text, col ); + sampleEdit->setPalette( pal ); +} + +TQColor TDEFontChooser::color() const +{ + return d->m_palette.color( TQPalette::Active, TQColorGroup::Text ); +} + +void TDEFontChooser::setBackgroundColor( const TQColor & col ) +{ + d->m_palette.setColor( TQPalette::Active, TQColorGroup::Base, col ); + TQPalette pal = sampleEdit->palette(); + pal.setColor( TQPalette::Active, TQColorGroup::Base, col ); + sampleEdit->setPalette( pal ); +} + +TQColor TDEFontChooser::backgroundColor() const +{ + return d->m_palette.color( TQPalette::Active, TQColorGroup::Base ); +} + +void TDEFontChooser::setSizeIsRelative( TQButton::ToggleState relative ) +{ + // check or uncheck or gray out the "relative" checkbox + if( sizeIsRelativeCheckBox ) { + if( TQButton::NoChange == relative ) + sizeIsRelativeCheckBox->setNoChange(); + else + sizeIsRelativeCheckBox->setChecked( TQButton::On == relative ); + } +} + +TQButton::ToggleState TDEFontChooser::sizeIsRelative() const +{ + return sizeIsRelativeCheckBox + ? sizeIsRelativeCheckBox->state() + : TQButton::NoChange; +} + +TQSize TDEFontChooser::sizeHint( void ) const +{ + return minimumSizeHint(); +} + + +void TDEFontChooser::enableColumn( int column, bool state ) +{ + if( column & FamilyList ) + { + familyListBox->setEnabled(state); + } + if( column & StyleList ) + { + styleListBox->setEnabled(state); + } + if( column & SizeList ) + { + sizeListBox->setEnabled(state); + } +} + + +void TDEFontChooser::setFont( const TQFont& aFont, bool onlyFixed ) +{ + selFont = aFont; + selectedSize=aFont.pointSize(); + if (selectedSize == -1) + selectedSize = TQFontInfo(aFont).pointSize(); + + if( onlyFixed != usingFixed) + { + usingFixed = onlyFixed; + fillFamilyListBox(usingFixed); + } + setupDisplay(); + displaySample(selFont); +} + + +int TDEFontChooser::fontDiffFlags() { + int diffFlags = 0; + if (familyCheckbox && styleCheckbox && sizeCheckbox) { + diffFlags = (int)(familyCheckbox->isChecked() ? FontDiffFamily : 0) + | (int)( styleCheckbox->isChecked() ? FontDiffStyle : 0) + | (int)( sizeCheckbox->isChecked() ? FontDiffSize : 0); + } + return diffFlags; +} + +void TDEFontChooser::toggled_checkbox() +{ + familyListBox->setEnabled( familyCheckbox->isChecked() ); + styleListBox->setEnabled( styleCheckbox->isChecked() ); + sizeListBox->setEnabled( sizeCheckbox->isChecked() ); + sizeOfFont->setEnabled( sizeCheckbox->isChecked() ); +} + +void TDEFontChooser::family_chosen_slot(const TQString& family) +{ + TQFontDatabase dbase; + TQStringList styles = TQStringList(dbase.styles(family)); + styleListBox->clear(); + currentStyles.clear(); + for ( TQStringList::Iterator it = styles.begin(); it != styles.end(); ++it ) { + TQString style = *it; + int pos = style.find("Plain"); + if(pos >=0) style = style.replace(pos,5,i18n("Regular")); + pos = style.find("Normal"); + if(pos >=0) style = style.replace(pos,6,i18n("Regular")); + pos = style.find("Oblique"); + if(pos >=0) style = style.replace(pos,7,i18n("Italic")); + if(!styleListBox->findItem(style)) { + styleListBox->insertItem(i18n(style.utf8())); + currentStyles.insert(i18n(style.utf8()), *it); + } + } + if(styleListBox->count()==0) { + styleListBox->insertItem(i18n("Regular")); + currentStyles.insert(i18n("Regular"), "Normal"); + } + + styleListBox->blockSignals(true); + TQListBoxItem *item = styleListBox->findItem(selectedStyle); + if (item) + styleListBox->setSelected(styleListBox->findItem(selectedStyle), true); + else + styleListBox->setSelected(0, true); + styleListBox->blockSignals(false); + + style_chosen_slot(TQString::null); +} + +void TDEFontChooser::size_chosen_slot(const TQString& size){ + + selectedSize=size.toInt(); + sizeOfFont->setValue(selectedSize); + selFont.setPointSize(selectedSize); + emit fontSelected(selFont); +} + +void TDEFontChooser::size_value_slot(int val) { + selFont.setPointSize(val); + emit fontSelected(selFont); +} + +void TDEFontChooser::style_chosen_slot(const TQString& style) +{ + TQString currentStyle; + if (style.isEmpty()) + currentStyle = styleListBox->currentText(); + else + currentStyle = style; + + int diff=0; // the difference between the font size requested and what we can show. + + sizeListBox->clear(); + TQFontDatabase dbase; + if(dbase.isSmoothlyScalable(familyListBox->currentText(), currentStyles[currentStyle])) { // is vector font + //sampleEdit->setPaletteBackgroundPixmap( VectorPixmap ); // TODO + fillSizeList(); + } else { // is bitmap font. + //sampleEdit->setPaletteBackgroundPixmap( BitmapPixmap ); // TODO + TQValueList sizes = dbase.smoothSizes(familyListBox->currentText(), currentStyles[currentStyle]); + if(sizes.count() > 0) { + TQValueList::iterator it; + diff=1000; + for ( it = sizes.begin(); it != sizes.end(); ++it ) { + if(*it <= selectedSize || diff > *it - selectedSize) diff = selectedSize - *it; + sizeListBox->insertItem(TQString::number(*it)); + } + } else // there are times QT does not provide the list.. + fillSizeList(); + } + sizeListBox->blockSignals(true); + sizeListBox->setSelected(sizeListBox->findItem(TQString::number(selectedSize)), true); + sizeListBox->blockSignals(false); + sizeListBox->ensureCurrentVisible(); + + //kdDebug() << "Showing: " << familyListBox->currentText() << ", " << currentStyles[currentStyle] << ", " << selectedSize-diff << endl; + selFont = dbase.font(familyListBox->currentText(), currentStyles[currentStyle], selectedSize-diff); + emit fontSelected(selFont); + if (!style.isEmpty()) + selectedStyle = style; +} + +void TDEFontChooser::displaySample(const TQFont& font) +{ + sampleEdit->setFont(font); + sampleEdit->setCursorPosition(0); + xlfdEdit->setText(font.rawName()); + xlfdEdit->setCursorPosition(0); + + //TQFontInfo a = TQFontInfo(font); + //kdDebug() << "font: " << a.family () << ", " << a.pointSize () << endl; + //kdDebug() << " (" << font.toString() << ")\n"; +} + +void TDEFontChooser::setupDisplay() +{ + // Calling familyListBox->setCurrentItem() causes the value of selFont + // to change, so we save the family, style and size beforehand. + TQString family = TQString(selFont.family()).lower(); + int style = (selFont.bold() ? 2 : 0) + (selFont.italic() ? 1 : 0); + int size = selFont.pointSize(); + if (size == -1) + size = TQFontInfo(selFont).pointSize(); + TQString sizeStr = TQString::number(size); + + int numEntries, i; + + numEntries = familyListBox->count(); + for (i = 0; i < numEntries; i++) { + if (family == familyListBox->text(i).lower()) { + familyListBox->setCurrentItem(i); + break; + } + } + + // 1st Fallback + if ( (i == numEntries) ) + { + if (family.contains('[')) + { + family = family.left(family.find('[')).stripWhiteSpace(); + for (i = 0; i < numEntries; i++) { + if (family == familyListBox->text(i).lower()) { + familyListBox->setCurrentItem(i); + break; + } + } + } + } + + // 2nd Fallback + if ( (i == numEntries) ) + { + TQString fallback = family+" ["; + for (i = 0; i < numEntries; i++) { + if (familyListBox->text(i).lower().startsWith(fallback)) { + familyListBox->setCurrentItem(i); + break; + } + } + } + + // 3rd Fallback + if ( (i == numEntries) ) + { + for (i = 0; i < numEntries; i++) { + if (familyListBox->text(i).lower().startsWith(family)) { + familyListBox->setCurrentItem(i); + break; + } + } + } + + // Fall back in case nothing matched. Otherwise, diff doesn't work + if ( i == numEntries ) + familyListBox->setCurrentItem( 0 ); + + styleListBox->setCurrentItem(style); + + numEntries = sizeListBox->count(); + for (i = 0; i < numEntries; i++){ + if (sizeStr == sizeListBox->text(i)) { + sizeListBox->setCurrentItem(i); + break; + } + } + + sizeOfFont->setValue(size); +} + + +void TDEFontChooser::getFontList( TQStringList &list, uint fontListCriteria) +{ + TQFontDatabase dbase; + TQStringList lstSys(dbase.families()); + + // if we have criteria; then check fonts before adding + if (fontListCriteria) + { + TQStringList lstFonts; + for (TQStringList::Iterator it = lstSys.begin(); it != lstSys.end(); ++it) + { + if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(*it)) continue; + if (((fontListCriteria & (SmoothScalableFonts | ScalableFonts)) == ScalableFonts) && + !dbase.isBitmapScalable(*it)) continue; + if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(*it)) continue; + lstFonts.append(*it); + } + + if((fontListCriteria & FixedWidthFonts) > 0) { + // Fallback.. if there are no fixed fonts found, it's probably a + // bug in the font server or Qt. In this case, just use 'fixed' + if (lstFonts.count() == 0) + lstFonts.append("fixed"); + } + + lstSys = lstFonts; + } + + lstSys.sort(); + + list = lstSys; +} + +void TDEFontChooser::addFont( TQStringList &list, const char *xfont ) +{ + const char *ptr = strchr( xfont, '-' ); + if ( !ptr ) + return; + + ptr = strchr( ptr + 1, '-' ); + if ( !ptr ) + return; + + TQString font = TQString::fromLatin1(ptr + 1); + + int pos; + if ( ( pos = font.find( '-' ) ) > 0 ) { + font.truncate( pos ); + + if ( font.find( TQString::fromLatin1("open look"), 0, false ) >= 0 ) + return; + + TQStringList::Iterator it = list.begin(); + + for ( ; it != list.end(); ++it ) + if ( *it == font ) + return; + list.append( font ); + } +} + +void TDEFontChooser::fillFamilyListBox(bool onlyFixedFonts) +{ + TQStringList fontList; + getFontList(fontList, onlyFixedFonts?FixedWidthFonts:0); + familyListBox->clear(); + familyListBox->insertStringList(fontList); +} + +void TDEFontChooser::showXLFDArea(bool show) +{ + if( show ) + { + xlfdEdit->parentWidget()->show(); + } + else + { + xlfdEdit->parentWidget()->hide(); + } +} + +/////////////////////////////////////////////////////////////////////////////// + +TDEFontDialog::TDEFontDialog( TQWidget *parent, const char* name, + bool onlyFixed, bool modal, + const TQStringList &fontList, bool makeFrame, bool diff, + TQButton::ToggleState *sizeIsRelativeState ) + : KDialogBase( parent, name, modal, i18n("Select Font"), Ok|Cancel, Ok ) +{ + chooser = new TDEFontChooser( this, "fontChooser", + onlyFixed, fontList, makeFrame, 8, + diff, sizeIsRelativeState ); + setMainWidget(chooser); +} + + +int TDEFontDialog::getFontDiff( TQFont &theFont, int &diffFlags, bool onlyFixed, + TQWidget *parent, bool makeFrame, + TQButton::ToggleState *sizeIsRelativeState ) +{ + TDEFontDialog dlg( parent, "Font Selector", onlyFixed, true, TQStringList(), + makeFrame, true, sizeIsRelativeState ); + dlg.setFont( theFont, onlyFixed ); + + int result = dlg.exec(); + if( result == Accepted ) + { + theFont = dlg.chooser->font(); + diffFlags = dlg.chooser->fontDiffFlags(); + if( sizeIsRelativeState ) + *sizeIsRelativeState = dlg.chooser->sizeIsRelative(); + } + return result; +} + +int TDEFontDialog::getFont( TQFont &theFont, bool onlyFixed, + TQWidget *parent, bool makeFrame, + TQButton::ToggleState *sizeIsRelativeState ) +{ + TDEFontDialog dlg( parent, "Font Selector", onlyFixed, true, TQStringList(), + makeFrame, false, sizeIsRelativeState ); + dlg.setFont( theFont, onlyFixed ); + + int result = dlg.exec(); + if( result == Accepted ) + { + theFont = dlg.chooser->font(); + if( sizeIsRelativeState ) + *sizeIsRelativeState = dlg.chooser->sizeIsRelative(); + } + return result; +} + + +int TDEFontDialog::getFontAndText( TQFont &theFont, TQString &theString, + bool onlyFixed, TQWidget *parent, + bool makeFrame, + TQButton::ToggleState *sizeIsRelativeState ) +{ + TDEFontDialog dlg( parent, "Font and Text Selector", onlyFixed, true, + TQStringList(), makeFrame, false, sizeIsRelativeState ); + dlg.setFont( theFont, onlyFixed ); + + int result = dlg.exec(); + if( result == Accepted ) + { + theFont = dlg.chooser->font(); + theString = dlg.chooser->sampleText(); + if( sizeIsRelativeState ) + *sizeIsRelativeState = dlg.chooser->sizeIsRelative(); + } + return result; +} + +void TDEFontChooser::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +void TDEFontDialog::virtual_hook( int id, void* data ) +{ KDialogBase::virtual_hook( id, data ); } diff --git a/tdeui/tdefontdialog.h b/tdeui/tdefontdialog.h new file mode 100644 index 000000000..cce427eba --- /dev/null +++ b/tdeui/tdefontdialog.h @@ -0,0 +1,504 @@ +/* + $Id$ + + Requires the Qt widget libraries, available at no cost at + http://www.troll.no + + Copyright (C) 1997 Bernd Johannes Wuebben + Copyright (c) 1999 Preston Brown + Copyright (c) 1999 Mario Weilguni + + This library 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. + + 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 _K_FONT_DIALOG_H_ +#define _K_FONT_DIALOG_H_ + +#include +#include +#include + +class TQComboBox; +class TQCheckBox; +class TQFont; +class TQGroupBox; +class TQLabel; +class TQStringList; +class TDEListBox; +class KIntNumInput; +/** + * @short A font selection widget. + * + * While TDEFontChooser as an ordinary widget can be embedded in + * custom dialogs and therefore is very flexible, in most cases + * it is preferable to use the convenience functions in + * TDEFontDialog. + * + * \image html kfontchooser.png "KDE Font Chooser" + * + * @author Preston Brown , Bernd Wuebben + * @version $Id$ + */ +class TDEUI_EXPORT TDEFontChooser : public TQWidget +{ + Q_OBJECT + TQ_PROPERTY( TQFont font READ font WRITE setFont ) + +public: + /** + * @li @p FamilyList - Identifies the family (leftmost) list. + * @li @p StyleList - Identifies the style (center) list. + * @li @p SizeList - Identifies the size (rightmost) list. + */ + enum FontColumn { FamilyList=0x01, StyleList=0x02, SizeList=0x04}; + + /** + * @li @p FontDiffFamily - Identifies a requested change in the font family. + * @li @p FontDiffStyle - Identifies a requested change in the font style. + * @li @p FontDiffSize - Identifies a requested change in the font size. + */ + enum FontDiff { FontDiffFamily=0x01, FontDiffStyle=0x02, FontDiffSize=0x04 }; + + /** + * Constructs a font picker widget. + * It normally comes up with all font families present on the system; the + * getFont method below does allow some more fine-tuning of the selection of fonts + * that will be displayed in the dialog. + *

Consider the following code snippet; + * \code + * TQStringList list; + * TDEFontChooser::getFontList(list,SmoothScalableFonts); + * TDEFontChooser chooseFont = new TDEFontChooser(0, "FontList", false, list); + * \endcode + *

+ * The above creates a font chooser dialog with only SmoothScaleble fonts. + * + * @param parent The parent widget. + * @param name The widget name. + * @param onlyFixed Only display fonts which have fixed-width + * character sizes. + * @param fontList A list of fonts to display, in XLFD format. If + * no list is formatted, the internal KDE font list is used. + * If that has not been created, X is queried, and all fonts + * available on the system are displayed. + * @param diff Display the difference version dialog. + * See TDEFontDialog::getFontDiff(). + * @param makeFrame Draws a frame with titles around the contents. + * @param visibleListSize The minimum number of visible entries in the + * fontlists. + * @param sizeIsRelativeState If not zero the widget will show a + * checkbox where the user may choose whether the font size + * is to be interpreted as relative size. + * Initial state of this checkbox will be set according to + * *sizeIsRelativeState, user choice may be retrieved by + * calling sizeIsRelative(). + */ + TDEFontChooser(TQWidget *parent = 0L, const char *name = 0L, + bool onlyFixed = false, + const TQStringList &fontList = TQStringList(), + bool makeFrame = true, int visibleListSize=8, + bool diff = false, TQButton::ToggleState *sizeIsRelativeState = 0L ); + + /** + * Destructs the font chooser. + */ + virtual ~TDEFontChooser(); + + /** + * Enables or disable a font column in the chooser. + * + * Use this + * function if your application does not need or supports all font + * properties. + * + * @param column Specify the columns. An or'ed combination of + * @p FamilyList, @p StyleList and @p SizeList is possible. + * @param state If @p false the columns are disabled. + */ + void enableColumn( int column, bool state ); + + /** + * Sets the currently selected font in the chooser. + * + * @param font The font to select. + * @param onlyFixed Readjust the font list to display only fixed + * width fonts if @p true, or vice-versa. + */ + void setFont( const TQFont &font, bool onlyFixed = false ); + + /** + * @return The bitmask corresponding to the attributes the user + * wishes to change. + */ + int fontDiffFlags(); + + /** + * @return The currently selected font in the chooser. + */ + TQFont font() const { return selFont; } + + /** + * Sets the color to use in the preview. + */ + void setColor( const TQColor & col ); + + /** + * @return The color currently used in the preview (default: the text + * color of the active color group) + */ + TQColor color() const; + + /** + * Sets the background color to use in the preview. + */ + void setBackgroundColor( const TQColor & col ); + + /** + * @return The background color currently used in the preview (default: + * the base color of the active colorgroup) + */ + TQColor backgroundColor() const; + + /** + * Sets the state of the checkbox indicating whether the font size + * is to be interpreted as relative size. + * NOTE: If parameter sizeIsRelative was not set in the constructor + * of the widget this setting will be ignored. + */ + void setSizeIsRelative( TQButton::ToggleState relative ); + + /** + * @return Whether the font size is to be interpreted as relative size + * (default: TQButton:Off) + */ + TQButton::ToggleState sizeIsRelative() const; + + + /** + * @return The current text in the sample text input area. + */ + TQString sampleText() const { return sampleEdit->text(); } + + /** + * Sets the sample text. + * + * Normally you should not change this + * text, but it can be better to do this if the default text is + * too large for the edit area when using the default font of your + * application. + * + * @param text The new sample text. The current will be removed. + */ + void setSampleText( const TQString &text ) + { + sampleEdit->setText( text ); + } + + /** + * Shows or hides the sample text box. + * + * @param visible Set it to true to show the box, to false to hide it. + * @since 3.5 + */ + void setSampleBoxVisible( bool visible ) + { + sampleEdit->setShown( visible ); + } + + /** + * Converts a TQFont into the corresponding X Logical Font + * Description (XLFD). + * + * @param theFont The font to convert. + * @return A string representing the given font in XLFD format. + */ + static TQString getXLFD( const TQFont &theFont ) + { return theFont.rawName(); } + + /** + * The selection criteria for the font families shown in the dialog. + * @li @p FixedWidthFont when included only fixed-width fonts are returned. + * The fonts where the width of every character is equal. + * @li @p ScalableFont when included only scalable fonts are returned; + * certain configurations allow bitmap fonts to remain unscaled and + * thus these fonts have limited number of sizes. + * @li @p SmoothScalableFont when included only return smooth scalable fonts. + * this will return only non-bitmap fonts which are scalable to any size requested. + * Setting this option to true will mean the "scalable" flag is irrelavant. + */ + enum FontListCriteria { FixedWidthFonts=0x01, ScalableFonts=0x02, SmoothScalableFonts=0x04 }; + + /** + * Creates a list of font strings. + * + * @param list The list is returned here. + * @param fontListCriteria should contain all the restrictions for font selection as OR-ed values + * @see TDEFontChooser::FontListCriteria for the individual values + */ + static void getFontList( TQStringList &list, uint fontListCriteria); + + /** + * Reimplemented for internal reasons. + */ + virtual TQSize sizeHint( void ) const; + +signals: + /** + * Emitted whenever the selected font changes. + */ + void fontSelected( const TQFont &font ); + +private slots: + void toggled_checkbox(); + void family_chosen_slot(const TQString&); + void size_chosen_slot(const TQString&); + void style_chosen_slot(const TQString&); + void displaySample(const TQFont &font); + void showXLFDArea(bool); + void size_value_slot(int); +private: + void fillFamilyListBox(bool onlyFixedFonts = false); + void fillSizeList(); + // This one must be static since getFontList( TQStringList, char*) is so + static void addFont( TQStringList &list, const char *xfont ); + + void setupDisplay(); + + // pointer to an optinally supplied list of fonts to + // inserted into the fontdialog font-family combo-box + TQStringList fontList; + + KIntNumInput *sizeOfFont; + + TQLineEdit *sampleEdit; + TQLineEdit *xlfdEdit; + + TQLabel *familyLabel; + TQLabel *styleLabel; + TQCheckBox *familyCheckbox; + TQCheckBox *styleCheckbox; + TQCheckBox *sizeCheckbox; + TQLabel *sizeLabel; + TDEListBox *familyListBox; + TDEListBox *styleListBox; + TDEListBox *sizeListBox; + TQComboBox *charsetsCombo; // BIC: remove in KDE4 + TQCheckBox *sizeIsRelativeCheckBox; + + TQFont selFont; + + TQString selectedStyle; + int selectedSize; + TQMap currentStyles; + + bool usingFixed; + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEFontChooserPrivate; + TDEFontChooserPrivate *d; +}; + +/** + * @short A font selection dialog. + * + * The TDEFontDialog provides a dialog for interactive font selection. + * It is basically a thin wrapper around the TDEFontChooser widget, + * which can also be used standalone. In most cases, the simplest + * use of this class is the static method TDEFontDialog::getFont(), + * which pops up the dialog, allows the user to select a font, and + * returns when the dialog is closed. + * + * Example: + * + * \code + * TQFont myFont; + * int result = TDEFontDialog::getFont( myFont ); + * if ( result == TDEFontDialog::Accepted ) + * ... + * \endcode + * + * \image html kfontdialog.png "KDE Font Dialog" + * + * @author Preston Brown , Bernd Wuebben + * @version $Id$ + */ +class TDEUI_EXPORT TDEFontDialog : public KDialogBase { + Q_OBJECT + +public: + /** + * Constructs a font selection dialog. + * + * @param parent The parent widget of the dialog, if any. + * @param name The name of the dialog. + * @param modal Specifies whether the dialog is modal or not. + * @param onlyFixed only display fonts which have fixed-width + * character sizes. + * @param fontlist a list of fonts to display, in XLFD format. If + * no list is formatted, the internal KDE font list is used. + * If that has not been created, X is queried, and all fonts + * available on the system are displayed. + * @param makeFrame Draws a frame with titles around the contents. + * @param diff Display the difference version dialog. See getFontDiff(). + * @param sizeIsRelativeState If not zero the widget will show a + * checkbox where the user may choose whether the font size + * is to be interpreted as relative size. + * Initial state of this checkbox will be set according to + * *sizeIsRelativeState, user choice may be retrieved by + * calling sizeIsRelative(). + * + */ + TDEFontDialog( TQWidget *parent = 0L, const char *name = 0, + bool onlyFixed = false, bool modal = false, + const TQStringList &fontlist = TQStringList(), + bool makeFrame = true, bool diff = false, + TQButton::ToggleState *sizeIsRelativeState = 0L ); + + /** + * Sets the currently selected font in the dialog. + * + * @param font The font to select. + * @param onlyFixed readjust the font list to display only fixed + * width fonts if true, or vice-versa + */ + void setFont( const TQFont &font, bool onlyFixed = false ) + { chooser->setFont(font, onlyFixed); } + + /** + * @return The currently selected font in the dialog. + */ + TQFont font() const { return chooser->font(); } + + /** + * Sets the state of the checkbox indicating whether the font size + * is to be interpreted as relative size. + * NOTE: If parameter sizeIsRelative was not set in the constructor + * of the dialog this setting will be ignored. + */ + void setSizeIsRelative( TQButton::ToggleState relative ) + { chooser->setSizeIsRelative( relative ); } + + /** + * @return Whether the font size is to be interpreted as relative size + * (default: false) + */ + TQButton::ToggleState sizeIsRelative() const + { return chooser->sizeIsRelative(); } + + /** + * Creates a modal font dialog, lets the user choose a font, + * and returns when the dialog is closed. + * + * @param theFont a reference to the font to write the chosen font + * into. + * @param onlyFixed if true, only select from fixed-width fonts. + * @param parent Parent widget of the dialog. Specifying a widget different + * from 0 (Null) improves centering (looks better). + * @param makeFrame Draws a frame with titles around the contents. + * @param sizeIsRelativeState If not zero the widget will show a + * checkbox where the user may choose whether the font size + * is to be interpreted as relative size. + * Initial state of this checkbox will be set according to + * *sizeIsRelativeState and user choice will be returned + * therein. + * + * @return TQDialog::result(). + */ + static int getFont( TQFont &theFont, bool onlyFixed = false, + TQWidget *parent = 0L, bool makeFrame = true, + TQButton::ToggleState *sizeIsRelativeState = 0L ); + + /** + * Creates a modal font difference dialog, lets the user choose a selection + * of changes that should be made to a set of fonts, and returns when the + * dialog is closed. Useful for choosing slight adjustments to the font set + * when the user would otherwise have to manually edit a number of fonts. + * + * @param theFont a reference to the font to write the chosen font + * into. + * @param diffFlags a reference to the int into which the chosen + * difference selection bitmask should be written. + * Check the returned bitmask like: + * \code + * if ( diffFlags & TDEFontChooser::FontDiffFamily ) + * [...] + * if ( diffFlags & TDEFontChooser::FontDiffStyle ) + * [...] + * if ( diffFlags & TDEFontChooser::FontDiffSize ) + * [...] + * \endcode + * @param onlyFixed if true, only select from fixed-width fonts. + * @param parent Parent widget of the dialog. Specifying a widget different + * from 0 (Null) improves centering (looks better). + * @param makeFrame Draws a frame with titles around the contents. + * @param sizeIsRelativeState If not zero the widget will show a + * checkbox where the user may choose whether the font size + * is to be interpreted as relative size. + * Initial state of this checkbox will be set according to + * *sizeIsRelativeState and user choice will be returned + * therein. + * + * @returns TQDialog::result(). + */ + static int getFontDiff( TQFont &theFont, int &diffFlags, bool onlyFixed = false, + TQWidget *parent = 0L, bool makeFrame = true, + TQButton::ToggleState *sizeIsRelativeState = 0L ); + + /** + * When you are not only interested in the font selected, but also + * in the example string typed in, you can call this method. + * + * @param theFont a reference to the font to write the chosen font + * into. + * @param theString a reference to the example text that was typed. + * @param onlyFixed if true, only select from fixed-width fonts. + * @param parent Parent widget of the dialog. Specifying a widget different + * from 0 (Null) improves centering (looks better). + * @param makeFrame Draws a frame with titles around the contents. + * @param sizeIsRelativeState If not zero the widget will show a + * checkbox where the user may choose whether the font size + * is to be interpreted as relative size. + * Initial state of this checkbox will be set according to + * *sizeIsRelativeState and user choice will be returned + * therein. + * @return The result of the dialog. + */ + static int getFontAndText( TQFont &theFont, TQString &theString, + bool onlyFixed = false, TQWidget *parent = 0L, + bool makeFrame = true, + TQButton::ToggleState *sizeIsRelativeState = 0L ); + +signals: + /** + * Emitted whenever the currently selected font changes. + * Connect to this to monitor the font as it is selected if you are + * not running modal. + */ + void fontSelected( const TQFont &font ); + +protected: + TDEFontChooser *chooser; + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEFontDialogPrivate; + TDEFontDialogPrivate *d; + +}; + +#endif diff --git a/tdeui/tdefontrequester.cpp b/tdeui/tdefontrequester.cpp new file mode 100644 index 000000000..8ae0d705d --- /dev/null +++ b/tdeui/tdefontrequester.cpp @@ -0,0 +1,127 @@ +/* + Copyright (C) 2003 Nadeem Hasan + + This library 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. + + 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. +*/ + +#include "kfontrequester.h" + +#include +#include +#include +#include +#include + +#include +#include + +TDEFontRequester::TDEFontRequester( TQWidget *parent, const char *name, + bool onlyFixed ) : TQWidget( parent, name ), + m_onlyFixed( onlyFixed ) +{ + TQHBoxLayout *layout = new TQHBoxLayout( this, 0, KDialog::spacingHint() ); + + m_sampleLabel = new TQLabel( this, "m_sampleLabel" ); + m_button = new TQPushButton( i18n( "Choose..." ), this, "m_button" ); + + m_sampleLabel->setFrameStyle( TQFrame::StyledPanel | TQFrame::Sunken ); + setFocusProxy( m_button ); + + layout->addWidget( m_sampleLabel, 1 ); + layout->addWidget( m_button ); + + connect( m_button, TQT_SIGNAL( clicked() ), TQT_SLOT( buttonClicked() ) ); + + displaySampleText(); + setToolTip(); +} + +void TDEFontRequester::setFont( const TQFont &font, bool onlyFixed ) +{ + m_selFont = font; + m_onlyFixed = onlyFixed; + + displaySampleText(); + emit fontSelected( m_selFont ); +} + +void TDEFontRequester::setSampleText( const TQString &text ) +{ + m_sampleText = text; + displaySampleText(); +} + +void TDEFontRequester::setTitle( const TQString &title ) +{ + m_title = title; + setToolTip(); +} + +void TDEFontRequester::buttonClicked() +{ + int result = TDEFontDialog::getFont( m_selFont, m_onlyFixed, parentWidget() ); + + if ( result == KDialog::Accepted ) + { + displaySampleText(); + emit fontSelected( m_selFont ); + } +} + +void TDEFontRequester::displaySampleText() +{ + m_sampleLabel->setFont( m_selFont ); + + int size = m_selFont.pointSize(); + if(size == -1) + size = m_selFont.pixelSize(); + + if ( m_sampleText.isEmpty() ) + m_sampleLabel->setText( TQString( "%1 %2" ).arg( m_selFont.family() ) + .arg( size ) ); + else + m_sampleLabel->setText( m_sampleText ); +} + +void TDEFontRequester::setToolTip() +{ + TQToolTip::remove( m_button ); + TQToolTip::add( m_button, i18n( "Click to select a font" ) ); + + TQToolTip::remove( m_sampleLabel ); + TQWhatsThis::remove( m_sampleLabel ); + + if ( m_title.isNull() ) + { + TQToolTip::add( m_sampleLabel, i18n( "Preview of the selected font" ) ); + TQWhatsThis::add( m_sampleLabel, + i18n( "This is a preview of the selected font. You can change it" + " by clicking the \"Choose...\" button." ) ); + } + else + { + TQToolTip::add( m_sampleLabel, + i18n( "Preview of the \"%1\" font" ).arg( m_title ) ); + TQWhatsThis::add( m_sampleLabel, + i18n( "This is a preview of the \"%1\" font. You can change it" + " by clicking the \"Choose...\" button." ).arg( m_title ) ); + } +} + +#include "kfontrequester.moc" + +/* vim: et sw=2 ts=2 +*/ diff --git a/tdeui/tdefontrequester.h b/tdeui/tdefontrequester.h new file mode 100644 index 000000000..b686cf178 --- /dev/null +++ b/tdeui/tdefontrequester.h @@ -0,0 +1,157 @@ +/* + Copyright (C) 2003 Nadeem Hasan + + This library 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. + + 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 KFONTREQUESTER_H +#define KFONTREQUESTER_H + +#include +#include +#include + +#include + +class TQLabel; +class TQPushButton; + +/** + * This class provides a widget with a lineedit and a button, which invokes + * a font dialog (TDEFontDialog). + * + * The lineedit provides a preview of the selected font. The preview text can + * be customized. You can also have the font dialog show only the fixed fonts. + * + * \image html kfontrequester.png "KDE Font Requester" + * + * @author Nadeem Hasan + * + */ +class TDEUI_EXPORT TDEFontRequester : public TQWidget +{ + Q_OBJECT + + TQ_PROPERTY( TQString title READ title WRITE setTitle ) + TQ_PROPERTY( TQString sampleText READ sampleText WRITE setSampleText ) + TQ_PROPERTY( TQFont font READ font WRITE setFont ) + + public: + + /** + * Constructs a font requester widget. + * + * @param parent The parent widget. + * @param name The widget name. + * @param onlyFixed Only display fonts which have fixed-width character + * sizes. + */ + TDEFontRequester( TQWidget *parent=0L, const char *name=0L, + bool onlyFixed=false ); + + /** + * @return The currently selected font in the requester. + */ + TQFont font() const { return m_selFont; } + + /** + * @return Returns true if only fixed fonts are displayed. + */ + bool isFixedOnly() const { return m_onlyFixed; } + + /** + * @return The current text in the sample text input area. + */ + TQString sampleText() const { return m_sampleText; } + + /** + * @return The current title of the widget. + */ + TQString title() const { return m_title; } + + /** + * @return Pointer to the label used for preview. + */ + TQLabel *label() const { return m_sampleLabel; } + + /** + * @return Pointer to the pushbutton in the widget. + */ + TQPushButton *button() const { return m_button; } + + /** + * Sets the currently selected font in the requester. + * + * @param font The font to select. + * @param onlyFixed Display only fixed-width fonts in the font dialog + * if @p true, or vice-versa. + */ + virtual void setFont( const TQFont &font, bool onlyFixed=false ); + + /** + * Sets the sample text. + * + * Normally you should not change this + * text, but it can be better to do this if the default text is + * too large for the edit area when using the default font of your + * application. Default text is current font name and size. Setting + * the text to TQString::null will restore the default. + * + * @param text The new sample text. The current will be removed. + */ + virtual void setSampleText( const TQString &text ); + + /** + * Set the title for the widget that will be used in the tooltip and + * what's this text. + * + * @param title The title to be set. + */ + virtual void setTitle( const TQString & title ); + + signals: + /** + * Emitted when a new @p font has been selected in the underlying dialog + */ + void fontSelected( const TQFont &font ); + + protected: + + void displaySampleText(); + void setToolTip(); + + protected slots: + + virtual void buttonClicked(); + + protected: + + bool m_onlyFixed; + TQString m_sampleText, m_title; + TQLabel *m_sampleLabel; + TQPushButton *m_button; + TQFont m_selFont; + + private: + + class TDEFontRequesterPrivate; + TDEFontRequesterPrivate *d; +}; + +#endif // KFONTREQUESTER_H + +/* vim: et sw=2 ts=2 +*/ diff --git a/tdeui/tdelistbox.cpp b/tdeui/tdelistbox.cpp new file mode 100644 index 000000000..bc31f020d --- /dev/null +++ b/tdeui/tdelistbox.cpp @@ -0,0 +1,266 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 Reginald Stadlbauer + + 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. +*/ +#include "config.h" + +#include + +#include +#include +#include +#include +#include + +#include "klistbox.h" + +TDEListBox::TDEListBox( TQWidget *parent, const char *name, WFlags f ) + : TQListBox( parent, name, f ), d(0) +{ + connect( this, TQT_SIGNAL( onViewport() ), + this, TQT_SLOT( slotOnViewport() ) ); + connect( this, TQT_SIGNAL( onItem( TQListBoxItem * ) ), + this, TQT_SLOT( slotOnItem( TQListBoxItem * ) ) ); + slotSettingsChanged(TDEApplication::SETTINGS_MOUSE); + if (kapp) + { + connect( kapp, TQT_SIGNAL( settingsChanged(int) ), TQT_SLOT( slotSettingsChanged(int) ) ); + kapp->addKipcEventMask( KIPC::SettingsChanged ); + } + + m_pCurrentItem = 0L; + + m_pAutoSelect = new TQTimer( this ); + connect( m_pAutoSelect, TQT_SIGNAL( timeout() ), + this, TQT_SLOT( slotAutoSelect() ) ); +} + +void TDEListBox::slotOnItem( TQListBoxItem *item ) +{ + if ( item && m_bChangeCursorOverItem && m_bUseSingle ) + viewport()->setCursor( KCursor().handCursor() ); + + if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) { + m_pAutoSelect->start( m_autoSelectDelay, true ); + m_pCurrentItem = item; + } +} + +void TDEListBox::slotOnViewport() +{ + if ( m_bChangeCursorOverItem ) + viewport()->unsetCursor(); + + m_pAutoSelect->stop(); + m_pCurrentItem = 0L; +} + + +void TDEListBox::slotSettingsChanged(int category) +{ + if (category != TDEApplication::SETTINGS_MOUSE) + return; + m_bUseSingle = TDEGlobalSettings::singleClick(); + + disconnect( this, TQT_SIGNAL( mouseButtonClicked( int, TQListBoxItem *, + const TQPoint & ) ), + this, TQT_SLOT( slotMouseButtonClicked( int, TQListBoxItem *, + const TQPoint & ) ) ); +// disconnect( this, TQT_SIGNAL( doubleClicked( TQListBoxItem *, +// const TQPoint & ) ), +// this, TQT_SLOT( slotExecute( TQListBoxItem *, +// const TQPoint & ) ) ); + + if( m_bUseSingle ) + { + connect( this, TQT_SIGNAL( mouseButtonClicked( int, TQListBoxItem *, + const TQPoint & ) ), + this, TQT_SLOT( slotMouseButtonClicked( int, TQListBoxItem *, + const TQPoint & ) ) ); + } + else + { +// connect( this, TQT_SIGNAL( doubleClicked( TQListBoxItem *, +// const TQPoint & ) ), +// this, TQT_SLOT( slotExecute( TQListBoxItem *, +// const TQPoint & ) ) ); + } + + m_bChangeCursorOverItem = TDEGlobalSettings::changeCursorOverIcon(); + m_autoSelectDelay = TDEGlobalSettings::autoSelectDelay(); + + if( !m_bUseSingle || !m_bChangeCursorOverItem ) + viewport()->unsetCursor(); +} + +void TDEListBox::slotAutoSelect() +{ + // check that the item still exists + if( index( m_pCurrentItem ) == -1 ) + return; + + //Give this widget the keyboard focus. + if( !hasFocus() ) + setFocus(); + + ButtonState keybstate = TDEApplication::keyboardMouseState(); + + TQListBoxItem* previousItem = item( currentItem() ); + setCurrentItem( m_pCurrentItem ); + + if( m_pCurrentItem ) { + //Shift pressed? + if( (keybstate & ShiftButton) ) { + bool block = signalsBlocked(); + blockSignals( true ); + + //No Ctrl? Then clear before! + if( !(keybstate & ControlButton) ) + clearSelection(); + + bool select = !m_pCurrentItem->isSelected(); + bool update = viewport()->isUpdatesEnabled(); + viewport()->setUpdatesEnabled( false ); + + bool down = index( previousItem ) < index( m_pCurrentItem ); + TQListBoxItem* it = down ? previousItem : m_pCurrentItem; + for (;it ; it = it->next() ) { + if ( down && it == m_pCurrentItem ) { + setSelected( m_pCurrentItem, select ); + break; + } + if ( !down && it == previousItem ) { + setSelected( previousItem, select ); + break; + } + setSelected( it, select ); + } + + blockSignals( block ); + viewport()->setUpdatesEnabled( update ); + triggerUpdate( false ); + + emit selectionChanged(); + + if( selectionMode() == TQListBox::Single ) + emit selectionChanged( m_pCurrentItem ); + } + else if( (keybstate & ControlButton) ) + setSelected( m_pCurrentItem, !m_pCurrentItem->isSelected() ); + else { + bool block = signalsBlocked(); + blockSignals( true ); + + if( !m_pCurrentItem->isSelected() ) + clearSelection(); + + blockSignals( block ); + + setSelected( m_pCurrentItem, true ); + } + } + else + kdDebug() << "That´s not supposed to happen!!!!" << endl; +} + +void TDEListBox::emitExecute( TQListBoxItem *item, const TQPoint &pos ) +{ + ButtonState keybstate = TDEApplication::keyboardMouseState(); + + m_pAutoSelect->stop(); + + //Don´t emit executed if in SC mode and Shift or Ctrl are pressed + if( !( m_bUseSingle && ((keybstate & ShiftButton) || (keybstate & ControlButton)) ) ) { + emit executed( item ); + emit executed( item, pos ); + } +} + +// +// 2000-16-01 Espen Sand +// This widget is used in dialogs. It should ignore +// F1 (and combinations) and Escape since these are used +// to start help or close the dialog. This functionality +// should be done in TQListView but it is not (at least now) +// +void TDEListBox::keyPressEvent(TQKeyEvent *e) +{ + if( e->key() == Key_Escape ) + { + e->ignore(); + } + else if( e->key() == Key_F1 ) + { + e->ignore(); + } + else + { + TQListBox::keyPressEvent(e); + } +} + +void TDEListBox::focusOutEvent( TQFocusEvent *fe ) +{ + m_pAutoSelect->stop(); + + TQListBox::focusOutEvent( fe ); +} + +void TDEListBox::leaveEvent( TQEvent *e ) +{ + m_pAutoSelect->stop(); + + TQListBox::leaveEvent( e ); +} + +void TDEListBox::contentsMousePressEvent( TQMouseEvent *e ) +{ + if( (selectionMode() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) { + bool block = signalsBlocked(); + blockSignals( true ); + + clearSelection(); + + blockSignals( block ); + } + + TQListBox::contentsMousePressEvent( e ); +} + +void TDEListBox::contentsMouseDoubleClickEvent ( TQMouseEvent * e ) +{ + TQListBox::contentsMouseDoubleClickEvent( e ); + + TQListBoxItem* item = itemAt( contentsToViewport( e->pos() ) ); + + if( item ) { + emit doubleClicked( item, e->globalPos() ); + + if( (e->button() == Qt::LeftButton) && !m_bUseSingle ) + emitExecute( item, e->globalPos() ); + } +} + +void TDEListBox::slotMouseButtonClicked( int btn, TQListBoxItem *item, const TQPoint &pos ) +{ + if( (btn == Qt::LeftButton) && item ) + emitExecute( item, pos ); +} + +void TDEListBox::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +#include "klistbox.moc" diff --git a/tdeui/tdelistbox.h b/tdeui/tdelistbox.h new file mode 100644 index 000000000..8ef949527 --- /dev/null +++ b/tdeui/tdelistbox.h @@ -0,0 +1,128 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 Reginald Stadlbauer + + 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 KLISTBOX_H +#define KLISTBOX_H + +#include + +#include + +/** + * @short A variant of TQListBox that honors KDE's system-wide settings. + * + * Extends the functionality of TQListBox to honor the system + * wide settings for Single Click/Double Click mode, Auto Selection and + * Change Cursor over Link. + * + * There is a new signal executed(). It gets connected to either + * TQListBox::clicked() or TQListBox::doubleClicked() + * depending on the KDE wide Single Click/Double Click settings. It is + * strongly recommended that you use this signal instead of the above + * mentioned. This way you don't need to care about the current + * settings. If you want to get informed when the user selects + * something connect to the TQListBox::selectionChanged() signal. + **/ +class TDEUI_EXPORT TDEListBox : public TQListBox +{ + Q_OBJECT + +public: + TDEListBox( TQWidget *parent = 0, const char *name = 0, WFlags f = 0 ); + +signals: + + /** + * Emitted whenever the user executes an listbox item. + * + * That means depending on the KDE wide Single Click/Double Click + * setting the user clicked or double clicked on that item. + * @param item is the pointer to the executed listbox item. + * + * Note that you may not delete any TQListBoxItem objects in slots + * connected to this signal. + */ + void executed( TQListBoxItem *item ); + + /** + * Emitted whenever the user executes an listbox item. + * + * That means depending on the KDE wide Single Click/Double Click + * setting the user clicked or double clicked on that item. + * @param item is the pointer to the executed listbox item. + * @param pos is the position where the user has clicked + * + * Note that you may not delete any TQListBoxItem objects in slots + * connected to this signal. + */ + void executed( TQListBoxItem *item, const TQPoint &pos ); + + /** + * This signal gets emitted whenever the user double clicks into the + * listbox. + * + * @param item The pointer to the clicked listbox item. + * @param pos The position where the user has clicked. + * + * Note that you may not delete any TQListBoxItem objects in slots + * connected to this signal. + * + * This signal is more or less here for the sake of completeness. + * You should normally not need to use this. In most cases it's better + * to use executed() instead. + */ + void doubleClicked( TQListBoxItem *item, const TQPoint &pos ); + +protected slots: + void slotOnItem( TQListBoxItem *item ); + void slotOnViewport(); + + void slotSettingsChanged(int); + + /** + * Auto selection happend. + */ + void slotAutoSelect(); + +protected: + void emitExecute( TQListBoxItem *item, const TQPoint &pos ); + + virtual void keyPressEvent(TQKeyEvent *e); + virtual void focusOutEvent( TQFocusEvent *fe ); + virtual void leaveEvent( TQEvent *e ); + virtual void contentsMousePressEvent( TQMouseEvent *e ); + virtual void contentsMouseDoubleClickEvent ( TQMouseEvent *e ); + + bool m_bUseSingle; + bool m_bChangeCursorOverItem; + + TQListBoxItem* m_pCurrentItem; + + TQTimer* m_pAutoSelect; + int m_autoSelectDelay; + +private slots: + void slotMouseButtonClicked( int btn, TQListBoxItem *item, const TQPoint &pos ); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEListBoxPrivate; + TDEListBoxPrivate* const d; +}; + +#endif diff --git a/tdeui/tdelistview.cpp b/tdeui/tdelistview.cpp new file mode 100644 index 000000000..b3eb2222c --- /dev/null +++ b/tdeui/tdelistview.cpp @@ -0,0 +1,2411 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 Reginald Stadlbauer + Copyright (C) 2000,2003 Charles Samuels + Copyright (C) 2000 Peter Putzer + + 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. +*/ +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "klistview.h" +#include "klistviewlineedit.h" + +class TDEListView::Tooltip : public TQToolTip +{ +public: + Tooltip (TDEListView* parent, TQToolTipGroup* group = 0L); + virtual ~Tooltip () {} + +protected: + /** + * Reimplemented from TQToolTip for internal reasons. + */ + virtual void maybeTip (const TQPoint&); + +private: + TDEListView* mParent; +}; + +TDEListView::Tooltip::Tooltip (TDEListView* parent, TQToolTipGroup* group) + : TQToolTip (parent, group), + mParent (parent) +{ +} + +void TDEListView::Tooltip::maybeTip (const TQPoint&) +{ + // FIXME +} + +class TDEListView::TDEListViewPrivate +{ +public: + TDEListViewPrivate (TDEListView* listview) + : pCurrentItem (0), + autoSelectDelay(0), + dragOverItem(0), + dragDelay (TDEGlobalSettings::dndEventDelay()), + editor (new TDEListViewLineEdit (listview)), + cursorInExecuteArea(false), + itemsMovable (true), + selectedBySimpleMove(false), + selectedUsingMouse(false), + itemsRenameable (false), + validDrag (false), + dragEnabled (false), + autoOpen (true), + disableAutoSelection (false), + dropVisualizer (true), + dropHighlighter (false), + createChildren (true), + pressedOnSelected (false), + wasShiftEvent (false), + fullWidth (false), + sortAscending(true), + tabRename(true), + sortColumn(0), + selectionDirection(0), + tooltipColumn (0), + selectionMode (Single), + contextMenuKey (TDEGlobalSettings::contextMenuKey()), + showContextMenusOnPress (TDEGlobalSettings::showContextMenusOnPress()), + mDropVisualizerWidth (4), + paintAbove (0), + paintCurrent (0), + paintBelow (0), + painting (false), + shadeSortColumn(TDEGlobalSettings::shadeSortColumn()) + { + renameable.append(0); + connect(editor, TQT_SIGNAL(done(TQListViewItem*,int)), listview, TQT_SLOT(doneEditing(TQListViewItem*,int))); + } + + ~TDEListViewPrivate () + { + delete editor; + } + + TQListViewItem* pCurrentItem; + + TQTimer autoSelect; + int autoSelectDelay; + + TQTimer dragExpand; + TQListViewItem* dragOverItem; + TQPoint dragOverPoint; + + TQPoint startDragPos; + int dragDelay; + + TDEListViewLineEdit *editor; + TQValueList renameable; + + bool cursorInExecuteArea:1; + bool bUseSingle:1; + bool bChangeCursorOverItem:1; + bool itemsMovable:1; + bool selectedBySimpleMove : 1; + bool selectedUsingMouse:1; + bool itemsRenameable:1; + bool validDrag:1; + bool dragEnabled:1; + bool autoOpen:1; + bool disableAutoSelection:1; + bool dropVisualizer:1; + bool dropHighlighter:1; + bool createChildren:1; + bool pressedOnSelected:1; + bool wasShiftEvent:1; + bool fullWidth:1; + bool sortAscending:1; + bool tabRename:1; + + int sortColumn; + + //+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX + int selectionDirection; + int tooltipColumn; + + SelectionModeExt selectionMode; + int contextMenuKey; + bool showContextMenusOnPress; + + TQRect mOldDropVisualizer; + int mDropVisualizerWidth; + TQRect mOldDropHighlighter; + TQListViewItem *afterItemDrop; + TQListViewItem *parentItemDrop; + + TQListViewItem *paintAbove; + TQListViewItem *paintCurrent; + TQListViewItem *paintBelow; + bool painting:1; + bool shadeSortColumn:1; + + TQColor alternateBackground; +}; + + +TDEListViewLineEdit::TDEListViewLineEdit(TDEListView *parent) + : KLineEdit(parent->viewport()), item(0), col(0), p(parent) +{ + setFrame( false ); + hide(); + connect( parent, TQT_SIGNAL( selectionChanged() ), TQT_SLOT( slotSelectionChanged() )); + connect( parent, TQT_SIGNAL( itemRemoved( TQListViewItem * ) ), + TQT_SLOT( slotItemRemoved( TQListViewItem * ) )); +} + +TDEListViewLineEdit::~TDEListViewLineEdit() +{ +} + +TQListViewItem *TDEListViewLineEdit::currentItem() const +{ + return item; +} + +void TDEListViewLineEdit::load(TQListViewItem *i, int c) +{ + item=i; + col=c; + + TQRect rect(p->itemRect(i)); + setText(item->text(c)); + home( true ); + + int fieldX = rect.x() - 1; + int fieldW = p->columnWidth(col) + 2; + + TQHeader* const pHeader = p->header(); + + const int pos = pHeader->mapToIndex(col); + for ( int index = 0; index < pos; ++index ) + fieldX += p->columnWidth( pHeader->mapToSection( index )); + + if ( col == 0 ) { + int d = i->depth() + (p->rootIsDecorated() ? 1 : 0); + d *= p->treeStepSize(); + fieldX += d; + fieldW -= d; + } + + if ( i->pixmap( col ) ) {// add width of pixmap + int d = i->pixmap( col )->width(); + fieldX += d; + fieldW -= d; + } + + setGeometry(fieldX, rect.y() - 1, fieldW, rect.height() + 2); + show(); + setFocus(); +} + +/* Helper functions to for + * tabOrderedRename functionality. + */ + +static int nextCol (TDEListView *pl, TQListViewItem *pi, int start, int dir) +{ + if (pi) + { + // Find the next renameable column in the current row + for (; ((dir == +1) ? (start < pl->columns()) : (start >= 0)); start += dir) + if (pl->isRenameable(start)) + return start; + } + + return -1; +} + +static TQListViewItem *prevItem (TQListViewItem *pi) +{ + TQListViewItem *pa = pi->itemAbove(); + + /* Does what the TQListViewItem::previousSibling() + * of my dreams would do. + */ + if (pa && pa->parent() == pi->parent()) + return pa; + + return 0; +} + +static TQListViewItem *lastQChild (TQListViewItem *pi) +{ + if (pi) + { + /* Since there's no TQListViewItem::lastChild(). + * This finds the last sibling for the given + * item. + */ + for (TQListViewItem *pt = pi->nextSibling(); pt; pt = pt->nextSibling()) + pi = pt; + } + + return pi; +} + +void TDEListViewLineEdit::selectNextCell (TQListViewItem *pitem, int column, bool forward) +{ + const int ncols = p->columns(); + const int dir = forward ? +1 : -1; + const int restart = forward ? 0 : (ncols - 1); + TQListViewItem *top = (pitem && pitem->parent()) + ? pitem->parent()->firstChild() + : p->firstChild(); + TQListViewItem *pi = pitem; + + terminate(); // Save current changes + + do + { + /* Check the rest of the current row for an editable column, + * if that fails, check the entire next/previous row. The + * last case goes back to the first item in the current branch + * or the last item in the current branch depending on the + * direction. + */ + if ((column = nextCol(p, pi, column + dir, dir)) != -1 || + (column = nextCol(p, (pi = (forward ? pi->nextSibling() : prevItem(pi))), restart, dir)) != -1 || + (column = nextCol(p, (pi = (forward ? top : lastQChild(pitem))), restart, dir)) != -1) + { + if (pi) + { + p->setCurrentItem(pi); // Calls terminate + p->rename(pi, column); + + /* Some listviews may override rename() to + * prevent certain items from being renamed, + * if this is done, [m_]item will be NULL + * after the rename() call... try again. + */ + if (!item) + continue; + + break; + } + } + } + while (pi && !item); +} + +#ifdef KeyPress +#undef KeyPress +#endif + +bool TDEListViewLineEdit::event (TQEvent *pe) +{ + if (pe->type() == TQEvent::KeyPress) + { + TQKeyEvent *k = (TQKeyEvent *) pe; + + if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) && + p->tabOrderedRenaming() && p->itemsRenameable() && + !(k->state() & ControlButton || k->state() & AltButton)) + { + selectNextCell(item, col, + (k->key() == Key_Tab && !(k->state() & ShiftButton))); + return true; + } + } + + return KLineEdit::event(pe); +} + +void TDEListViewLineEdit::keyPressEvent(TQKeyEvent *e) +{ + if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) + terminate(true); + else if(e->key() == Qt::Key_Escape) + terminate(false); + else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up) + { + terminate(true); + KLineEdit::keyPressEvent(e); + } + else + KLineEdit::keyPressEvent(e); +} + +void TDEListViewLineEdit::terminate() +{ + terminate(true); +} + +void TDEListViewLineEdit::terminate(bool commit) +{ + if ( item ) + { + //kdDebug() << "TDEListViewLineEdit::terminate " << commit << endl; + if (commit) + item->setText(col, text()); + int c=col; + TQListViewItem *i=item; + col=0; + item=0; + p->setFocus();// will call focusOutEvent, that's why we set item=0 before + hide(); + if (commit) + emit done(i,c); + } +} + +void TDEListViewLineEdit::focusOutEvent(TQFocusEvent *ev) +{ + TQFocusEvent * focusEv = static_cast(ev); + // Don't let a RMB close the editor + if (focusEv->reason() != TQFocusEvent::Popup && focusEv->reason() != TQFocusEvent::ActiveWindow) + terminate(true); + else + KLineEdit::focusOutEvent(ev); +} + +void TDEListViewLineEdit::paintEvent( TQPaintEvent *e ) +{ + KLineEdit::paintEvent( e ); + + if ( !frame() ) { + TQPainter p( this ); + p.setClipRegion( e->region() ); + p.drawRect( rect() ); + } +} + +// selection changed -> terminate. As our "item" can be already deleted, +// we can't call terminate(false), because that would emit done() with +// a dangling pointer to "item". +void TDEListViewLineEdit::slotSelectionChanged() +{ + item = 0; + col = 0; + hide(); +} + +// if the current item was removed -> terminate. Can't call terminate(false) +// due to same reason as slotSelectionChanged(). +void TDEListViewLineEdit::slotItemRemoved(TQListViewItem *i) +{ + if (currentItem() != i) + return; + + item = 0; + col = 0; + hide(); +} + + +TDEListView::TDEListView( TQWidget *parent, const char *name ) + : TQListView( parent, name ), + d (new TDEListViewPrivate (this)) +{ + setDragAutoScroll(true); + + connect( this, TQT_SIGNAL( onViewport() ), + this, TQT_SLOT( slotOnViewport() ) ); + connect( this, TQT_SIGNAL( onItem( TQListViewItem * ) ), + this, TQT_SLOT( slotOnItem( TQListViewItem * ) ) ); + + connect (this, TQT_SIGNAL(contentsMoving(int,int)), + this, TQT_SLOT(cleanDropVisualizer())); + connect (this, TQT_SIGNAL(contentsMoving(int,int)), + this, TQT_SLOT(cleanItemHighlighter())); + + slotSettingsChanged(TDEApplication::SETTINGS_MOUSE); + if (kapp) + { + connect( kapp, TQT_SIGNAL( settingsChanged(int) ), TQT_SLOT( slotSettingsChanged(int) ) ); + kapp->addKipcEventMask( KIPC::SettingsChanged ); + } + + connect(&d->autoSelect, TQT_SIGNAL( timeout() ), + this, TQT_SLOT( slotAutoSelect() ) ); + connect(&d->dragExpand, TQT_SIGNAL( timeout() ), + this, TQT_SLOT( slotDragExpand() ) ); + + // context menu handling + if (d->showContextMenusOnPress) + { + connect (this, TQT_SIGNAL (rightButtonPressed (TQListViewItem*, const TQPoint&, int)), + this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); + } + else + { + connect (this, TQT_SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint&, int)), + this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); + } + + connect (this, TQT_SIGNAL (menuShortCutPressed (TDEListView*, TQListViewItem*)), + this, TQT_SLOT (emitContextMenu (TDEListView*, TQListViewItem*))); + d->alternateBackground = TDEGlobalSettings::alternateBackgroundColor(); +} + +TDEListView::~TDEListView() +{ + delete d; +} + +bool TDEListView::isExecuteArea( const TQPoint& point ) +{ + TQListViewItem* item = itemAt( point ); + if ( item ) { + return isExecuteArea( point.x(), item ); + } + + return false; +} + +bool TDEListView::isExecuteArea( int x ) +{ + return isExecuteArea( x, 0 ); +} + +bool TDEListView::isExecuteArea( int x, TQListViewItem* item ) +{ + if( allColumnsShowFocus() ) + return true; + else { + int offset = 0; + + + int width = columnWidth( 0 ); + + TQHeader* const thisHeader = header(); + const int pos = thisHeader->mapToIndex( 0 ); + + for ( int index = 0; index < pos; ++index ) + offset += columnWidth( thisHeader->mapToSection( index ) ); + + x += contentsX(); // in case of a horizontal scrollbar + + if ( item ) + { + width = treeStepSize()*( item->depth() + ( rootIsDecorated() ? 1 : 0 ) ); + width += itemMargin(); + int ca = AlignHorizontal_Mask & columnAlignment( 0 ); + if ( ca == AlignLeft || ca == AlignAuto ) { + width += item->width( fontMetrics(), this, 0 ); + if ( width > columnWidth( 0 ) ) + width = columnWidth( 0 ); + } + } + + return ( x > offset && x < ( offset + width ) ); + } +} + +void TDEListView::slotOnItem( TQListViewItem *item ) +{ + TQPoint vp = viewport()->mapFromGlobal( TQCursor::pos() ); + if ( item && isExecuteArea( vp.x() ) && (d->autoSelectDelay > -1) && d->bUseSingle ) { + d->autoSelect.start( d->autoSelectDelay, true ); + d->pCurrentItem = item; + } +} + +void TDEListView::slotOnViewport() +{ + if ( d->bChangeCursorOverItem ) + viewport()->unsetCursor(); + + d->autoSelect.stop(); + d->pCurrentItem = 0L; +} + +void TDEListView::slotSettingsChanged(int category) +{ + switch (category) + { + case TDEApplication::SETTINGS_MOUSE: + d->dragDelay = TDEGlobalSettings::dndEventDelay(); + d->bUseSingle = TDEGlobalSettings::singleClick(); + + disconnect(this, TQT_SIGNAL (mouseButtonClicked (int, TQListViewItem*, const TQPoint &, int)), + this, TQT_SLOT (slotMouseButtonClicked (int, TQListViewItem*, const TQPoint &, int))); + + if( d->bUseSingle ) + connect (this, TQT_SIGNAL (mouseButtonClicked (int, TQListViewItem*, const TQPoint &, int)), + this, TQT_SLOT (slotMouseButtonClicked( int, TQListViewItem*, const TQPoint &, int))); + + d->bChangeCursorOverItem = TDEGlobalSettings::changeCursorOverIcon(); + if ( !d->disableAutoSelection ) + d->autoSelectDelay = TDEGlobalSettings::autoSelectDelay(); + + if( !d->bUseSingle || !d->bChangeCursorOverItem ) + viewport()->unsetCursor(); + + break; + + case TDEApplication::SETTINGS_POPUPMENU: + d->contextMenuKey = TDEGlobalSettings::contextMenuKey (); + d->showContextMenusOnPress = TDEGlobalSettings::showContextMenusOnPress (); + + if (d->showContextMenusOnPress) + { + disconnect (0L, 0L, this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); + + connect(this, TQT_SIGNAL (rightButtonPressed (TQListViewItem*, const TQPoint&, int)), + this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); + } + else + { + disconnect (0L, 0L, this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); + + connect(this, TQT_SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint&, int)), + this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); + } + break; + + default: + break; + } +} + +void TDEListView::slotAutoSelect() +{ + // check that the item still exists + if( itemIndex( d->pCurrentItem ) == -1 ) + return; + + if (!isActiveWindow()) + { + d->autoSelect.stop(); + return; + } + + //Give this widget the keyboard focus. + if( !hasFocus() ) + setFocus(); + + ButtonState keybstate = TDEApplication::keyboardMouseState(); + + TQListViewItem* previousItem = currentItem(); + setCurrentItem( d->pCurrentItem ); + + if( d->pCurrentItem ) { + //Shift pressed? + if( (keybstate & TQt::ShiftButton) ) { + bool block = signalsBlocked(); + blockSignals( true ); + + //No Ctrl? Then clear before! + if( !(keybstate & TQt::ControlButton) ) + clearSelection(); + + bool select = !d->pCurrentItem->isSelected(); + bool update = viewport()->isUpdatesEnabled(); + viewport()->setUpdatesEnabled( false ); + + bool down = previousItem->itemPos() < d->pCurrentItem->itemPos(); + TQListViewItemIterator lit( down ? previousItem : d->pCurrentItem ); + for ( ; lit.current(); ++lit ) { + if ( down && lit.current() == d->pCurrentItem ) { + d->pCurrentItem->setSelected( select ); + break; + } + if ( !down && lit.current() == previousItem ) { + previousItem->setSelected( select ); + break; + } + lit.current()->setSelected( select ); + } + + blockSignals( block ); + viewport()->setUpdatesEnabled( update ); + triggerUpdate(); + + emit selectionChanged(); + + if( selectionMode() == TQListView::Single ) + emit selectionChanged( d->pCurrentItem ); + } + else if( (keybstate & TDEApplication::ControlModifier) ) + setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() ); + else { + bool block = signalsBlocked(); + blockSignals( true ); + + if( !d->pCurrentItem->isSelected() ) + clearSelection(); + + blockSignals( block ); + + setSelected( d->pCurrentItem, true ); + } + } + else + kdDebug() << "TDEListView::slotAutoSelect: That�s not supposed to happen!!!!" << endl; +} + +void TDEListView::slotHeaderChanged() +{ + + const int colCount = columns(); + if (d->fullWidth && colCount) + { + int w = 0; + const int lastColumn = colCount - 1; + for (int i = 0; i < lastColumn; ++i) w += columnWidth(i); + setColumnWidth( lastColumn, viewport()->width() - w - 1 ); + } +} + +void TDEListView::emitExecute( TQListViewItem *item, const TQPoint &pos, int c ) +{ + if( isExecuteArea( viewport()->mapFromGlobal(pos) ) ) { + d->validDrag=false; + + // Double click mode ? + if ( !d->bUseSingle ) + { + viewport()->unsetCursor(); + emit executed( item ); + emit executed( item, pos, c ); + } + else + { + ButtonState keybstate = TDEApplication::keyboardMouseState(); + + d->autoSelect.stop(); + + //Don't emit executed if in SC mode and Shift or Ctrl are pressed + if( !( ((keybstate & TQt::ShiftButton) || (keybstate & TQt::ControlButton)) ) ) { + viewport()->unsetCursor(); + emit executed( item ); + emit executed( item, pos, c ); + } + } + } +} + +void TDEListView::focusInEvent( TQFocusEvent *fe ) +{ + // kdDebug()<<"TDEListView::focusInEvent()"<selectedBySimpleMove) + && (d->selectionMode == FileManager) + && (fe->reason()!=TQFocusEvent::Popup) + && (fe->reason()!=TQFocusEvent::ActiveWindow) + && (currentItem())) + { + currentItem()->setSelected(true); + currentItem()->repaint(); + emit selectionChanged(); + }; +} + +void TDEListView::focusOutEvent( TQFocusEvent *fe ) +{ + cleanDropVisualizer(); + cleanItemHighlighter(); + + d->autoSelect.stop(); + + if ((d->selectedBySimpleMove) + && (d->selectionMode == FileManager) + && (fe->reason()!=TQFocusEvent::Popup) + && (fe->reason()!=TQFocusEvent::ActiveWindow) + && (currentItem()) + && (!d->editor->isVisible())) + { + currentItem()->setSelected(false); + currentItem()->repaint(); + emit selectionChanged(); + }; + + TQListView::focusOutEvent( fe ); +} + +void TDEListView::leaveEvent( TQEvent *e ) +{ + d->autoSelect.stop(); + + TQListView::leaveEvent( e ); +} + +bool TDEListView::event( TQEvent *e ) +{ + if (e->type() == TQEvent::ApplicationPaletteChange) + d->alternateBackground=TDEGlobalSettings::alternateBackgroundColor(); + + return TQListView::event(e); +} + +void TDEListView::contentsMousePressEvent( TQMouseEvent *e ) +{ + if( (selectionModeExt() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) + { + bool block = signalsBlocked(); + blockSignals( true ); + + clearSelection(); + + blockSignals( block ); + } + else if ((selectionModeExt()==FileManager) && (d->selectedBySimpleMove)) + { + d->selectedBySimpleMove=false; + d->selectedUsingMouse=true; + if (currentItem()) + { + currentItem()->setSelected(false); + currentItem()->repaint(); +// emit selectionChanged(); + } + } + + TQPoint p( contentsToViewport( e->pos() ) ); + TQListViewItem *at = itemAt (p); + + // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) + bool rootDecoClicked = at + && ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + + treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) + && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); + + if (e->button() == Qt::LeftButton && !rootDecoClicked) + { + //Start a drag + d->startDragPos = e->pos(); + + if (at) + { + d->validDrag = true; + d->pressedOnSelected = at->isSelected(); + } + } + + TQListView::contentsMousePressEvent( e ); +} + +void TDEListView::contentsMouseMoveEvent( TQMouseEvent *e ) +{ + if (!dragEnabled() || d->startDragPos.isNull() || !d->validDrag) + TQListView::contentsMouseMoveEvent (e); + + TQPoint vp = contentsToViewport(e->pos()); + TQListViewItem *item = itemAt( vp ); + + //do we process cursor changes at all? + if ( item && d->bChangeCursorOverItem && d->bUseSingle ) + { + //Cursor moved on a new item or in/out the execute area + if( (item != d->pCurrentItem) || + (isExecuteArea(vp) != d->cursorInExecuteArea) ) + { + d->cursorInExecuteArea = isExecuteArea(vp); + + if( d->cursorInExecuteArea ) //cursor moved in execute area + viewport()->setCursor( KCursor::handCursor() ); + else //cursor moved out of execute area + viewport()->unsetCursor(); + } + } + + bool dragOn = dragEnabled(); + TQPoint newPos = e->pos(); + if (dragOn && d->validDrag && + (newPos.x() > d->startDragPos.x()+d->dragDelay || + newPos.x() < d->startDragPos.x()-d->dragDelay || + newPos.y() > d->startDragPos.y()+d->dragDelay || + newPos.y() < d->startDragPos.y()-d->dragDelay)) + //(d->startDragPos - e->pos()).manhattanLength() > TQApplication::startDragDistance()) + { + TQListView::contentsMouseReleaseEvent( 0 ); + startDrag(); + d->startDragPos = TQPoint(); + d->validDrag = false; + } +} + +void TDEListView::contentsMouseReleaseEvent( TQMouseEvent *e ) +{ + if (e->button() == Qt::LeftButton) + { + // If the row was already selected, maybe we want to start an in-place editing + if ( d->pressedOnSelected && itemsRenameable() ) + { + TQPoint p( contentsToViewport( e->pos() ) ); + TQListViewItem *at = itemAt (p); + if ( at ) + { + // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) + bool rootDecoClicked = + ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + + treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) + && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); + + if (!rootDecoClicked) + { + int col = header()->mapToLogical( header()->cellAt( p.x() ) ); + if ( d->renameable.contains(col) ) + rename(at, col); + } + } + } + + d->pressedOnSelected = false; + d->validDrag = false; + d->startDragPos = TQPoint(); + } + TQListView::contentsMouseReleaseEvent( e ); +} + +void TDEListView::contentsMouseDoubleClickEvent ( TQMouseEvent *e ) +{ + // We don't want to call the parent method because it does setOpen, + // whereas we don't do it in single click mode... (David) + //TQListView::contentsMouseDoubleClickEvent( e ); + if ( !e || e->button() != Qt::LeftButton ) + return; + + TQPoint vp = contentsToViewport(e->pos()); + TQListViewItem *item = itemAt( vp ); + emit TQListView::doubleClicked( item ); // we do it now + + int col = item ? header()->mapToLogical( header()->cellAt( vp.x() ) ) : -1; + + if( item ) { + emit doubleClicked( item, e->globalPos(), col ); + + if( (e->button() == Qt::LeftButton) && !d->bUseSingle ) + emitExecute( item, e->globalPos(), col ); + } +} + +void TDEListView::slotMouseButtonClicked( int btn, TQListViewItem *item, const TQPoint &pos, int c ) +{ + if( (btn == Qt::LeftButton) && item ) + emitExecute(item, pos, c); +} + +void TDEListView::contentsDropEvent(TQDropEvent* e) +{ + cleanDropVisualizer(); + cleanItemHighlighter(); + d->dragExpand.stop(); + + if (acceptDrag (e)) + { + e->acceptAction(); + TQListViewItem *afterme; + TQListViewItem *parent; + + findDrop(e->pos(), parent, afterme); + + if (e->source() == viewport() && itemsMovable()) + movableDropEvent(parent, afterme); + else + { + emit dropped(e, afterme); + emit dropped(this, e, afterme); + emit dropped(e, parent, afterme); + emit dropped(this, e, parent, afterme); + } + } +} + +void TDEListView::movableDropEvent (TQListViewItem* parent, TQListViewItem* afterme) +{ + TQPtrList items, afterFirsts, afterNows; + TQListViewItem *current=currentItem(); + bool hasMoved=false; + for (TQListViewItem *i = firstChild(), *iNext=0; i; i = iNext) + { + iNext=i->itemBelow(); + if (!i->isSelected()) + continue; + + // don't drop an item after itself, or else + // it moves to the top of the list + if (i==afterme) + continue; + + i->setSelected(false); + + TQListViewItem *afterFirst = i->itemAbove(); + + if (!hasMoved) + { + emit aboutToMove(); + hasMoved=true; + } + + moveItem(i, parent, afterme); + + // ###### This should include the new parent !!! -> KDE 3.0 + // If you need this right now, have a look at keditbookmarks. + emit moved(i, afterFirst, afterme); + + items.append (i); + afterFirsts.append (afterFirst); + afterNows.append (afterme); + + afterme = i; + } + clearSelection(); + for (TQListViewItem *i=items.first(); i; i=items.next() ) + i->setSelected(true); + if (current) + setCurrentItem(current); + + emit moved(items,afterFirsts,afterNows); + + if (firstChild()) + emit moved(); +} + +void TDEListView::contentsDragMoveEvent(TQDragMoveEvent *event) +{ + if (acceptDrag(event)) + { + event->acceptAction(); + //Clean up the view + + findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop); + TQPoint vp = contentsToViewport( event->pos() ); + TQListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L; + + if ( item != d->dragOverItem ) + { + d->dragExpand.stop(); + d->dragOverItem = item; + d->dragOverPoint = vp; + if ( d->dragOverItem && d->dragOverItem->isExpandable() && !d->dragOverItem->isOpen() ) + d->dragExpand.start( TQApplication::startDragTime(), true ); + } + if (dropVisualizer()) + { + TQRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, d->afterItemDrop); + if (tmpRect != d->mOldDropVisualizer) + { + cleanDropVisualizer(); + d->mOldDropVisualizer=tmpRect; + viewport()->repaint(tmpRect); + } + } + if (dropHighlighter()) + { + TQRect tmpRect = drawItemHighlighter(0, itemAt( vp )); + if (tmpRect != d->mOldDropHighlighter) + { + cleanItemHighlighter(); + d->mOldDropHighlighter=tmpRect; + viewport()->repaint(tmpRect); + } + } + } + else + event->ignore(); +} + +void TDEListView::slotDragExpand() +{ + if ( itemAt( d->dragOverPoint ) == d->dragOverItem ) + d->dragOverItem->setOpen( true ); +} + +void TDEListView::contentsDragLeaveEvent (TQDragLeaveEvent*) +{ + d->dragExpand.stop(); + cleanDropVisualizer(); + cleanItemHighlighter(); +} + +void TDEListView::cleanDropVisualizer() +{ + if (d->mOldDropVisualizer.isValid()) + { + TQRect rect=d->mOldDropVisualizer; + d->mOldDropVisualizer = TQRect(); + viewport()->repaint(rect, true); + } +} + +int TDEListView::depthToPixels( int depth ) +{ + return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin(); +} + +void TDEListView::findDrop(const TQPoint &pos, TQListViewItem *&parent, TQListViewItem *&after) +{ + TQPoint p (contentsToViewport(pos)); + + // Get the position to put it in + TQListViewItem *atpos = itemAt(p); + + TQListViewItem *above; + if (!atpos) // put it at the end + above = lastItem(); + else + { + // Get the closest item before us ('atpos' or the one above, if any) + if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2)) + above = atpos->itemAbove(); + else + above = atpos; + } + + if (above) + { + // if above has children, I might need to drop it as the first item there + + if (above->firstChild() && above->isOpen()) + { + parent = above; + after = 0; + return; + } + + // Now, we know we want to go after "above". But as a child or as a sibling ? + // We have to ask the "above" item if it accepts children. + if (above->isExpandable()) + { + // The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children + if (p.x() >= depthToPixels( above->depth() + 1 ) || + (above->isOpen() && above->childCount() > 0) ) + { + parent = above; + after = 0L; + return; + } + } + + // Ok, there's one more level of complexity. We may want to become a new + // sibling, but of an upper-level group, rather than the "above" item + TQListViewItem * betterAbove = above->parent(); + TQListViewItem * last = above; + while ( betterAbove ) + { + // We are allowed to become a sibling of "betterAbove" only if we are + // after its last child + if ( !last->nextSibling() ) + { + if (p.x() < depthToPixels ( betterAbove->depth() + 1 )) + above = betterAbove; // store this one, but don't stop yet, there may be a better one + else + break; // not enough on the left, so stop + last = betterAbove; + betterAbove = betterAbove->parent(); // up one level + } else + break; // we're among the child of betterAbove, not after the last one + } + } + // set as sibling + after = above; + parent = after ? after->parent() : 0L ; +} + +TQListViewItem* TDEListView::lastChild () const +{ + TQListViewItem* lastchild = firstChild(); + + if (lastchild) + for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling()); + + return lastchild; +} + +TQListViewItem *TDEListView::lastItem() const +{ + TQListViewItem* last = lastChild(); + + for (TQListViewItemIterator it (last); it.current(); ++it) + last = it.current(); + + return last; +} + +KLineEdit *TDEListView::renameLineEdit() const +{ + return d->editor; +} + +void TDEListView::startDrag() +{ + TQDragObject *drag = dragObject(); + + if (!drag) + return; + + if (drag->drag() && drag->target() != viewport()) + emit moved(); +} + +TQDragObject *TDEListView::dragObject() +{ + if (!currentItem()) + return 0; + + + return new TQStoredDrag("application/x-qlistviewitem", viewport()); +} + +void TDEListView::setItemsMovable(bool b) +{ + d->itemsMovable=b; +} + +bool TDEListView::itemsMovable() const +{ + return d->itemsMovable; +} + +void TDEListView::setItemsRenameable(bool b) +{ + d->itemsRenameable=b; +} + +bool TDEListView::itemsRenameable() const +{ + return d->itemsRenameable; +} + + +void TDEListView::setDragEnabled(bool b) +{ + d->dragEnabled=b; +} + +bool TDEListView::dragEnabled() const +{ + return d->dragEnabled; +} + +void TDEListView::setAutoOpen(bool b) +{ + d->autoOpen=b; +} + +bool TDEListView::autoOpen() const +{ + return d->autoOpen; +} + +bool TDEListView::dropVisualizer() const +{ + return d->dropVisualizer; +} + +void TDEListView::setDropVisualizer(bool b) +{ + d->dropVisualizer=b; +} + +TQPtrList TDEListView::selectedItems() const +{ + return selectedItems(true); +} + +TQPtrList TDEListView::selectedItems(bool includeHiddenItems) const +{ + TQPtrList list; + + // Using selectionMode() instead of selectionModeExt() since for the cases that + // we're interested in selectionMode() should work for either variety of the + // setSelectionMode(). + + switch(selectionMode()) + { + case NoSelection: + break; + case Single: + if(selectedItem() && (includeHiddenItems || selectedItem()->isVisible())) + list.append(selectedItem()); + break; + default: + { + int flags = TQListViewItemIterator::Selected; + if (!includeHiddenItems) + { + flags |= TQListViewItemIterator::Visible; + } + + TQListViewItemIterator it(const_cast(this), flags); + + for(; it.current(); ++it) + list.append(it.current()); + + break; + } + } + + return list; +} + + +void TDEListView::moveItem(TQListViewItem *item, TQListViewItem *parent, TQListViewItem *after) +{ + // sanity check - don't move a item into its own child structure + TQListViewItem *i = parent; + while(i) + { + if(i == item) + return; + i = i->parent(); + } + + if (after) + { + item->moveItem(after); + return; + } + + // Basically reimplementing the TQListViewItem(TQListViewItem*, TQListViewItem*) constructor + // in here, without ever deleting the item. + if (item->parent()) + item->parent()->takeItem(item); + else + takeItem(item); + + if (parent) + parent->insertItem(item); + else + insertItem(item); +} + +void TDEListView::contentsDragEnterEvent(TQDragEnterEvent *event) +{ + if (acceptDrag (event)) + event->accept(); +} + +void TDEListView::setDropVisualizerWidth (int w) +{ + d->mDropVisualizerWidth = w > 0 ? w : 1; +} + +TQRect TDEListView::drawDropVisualizer(TQPainter *p, TQListViewItem *parent, + TQListViewItem *after) +{ + TQRect insertmarker; + + if (!after && !parent) + insertmarker = TQRect (0, 0, viewport()->width(), d->mDropVisualizerWidth/2); + else + { + int level = 0; + if (after) + { + TQListViewItem* it = 0L; + if (after->isOpen()) + { + // Look for the last child (recursively) + it = after->firstChild(); + if (it) + while (it->nextSibling() || it->firstChild()) + if ( it->nextSibling() ) + it = it->nextSibling(); + else + it = it->firstChild(); + } + + insertmarker = itemRect (it ? it : after); + level = after->depth(); + } + else if (parent) + { + insertmarker = itemRect (parent); + level = parent->depth() + 1; + } + insertmarker.setLeft( treeStepSize() * ( level + (rootIsDecorated() ? 1 : 0) ) + itemMargin() ); + insertmarker.setRight (viewport()->width()); + insertmarker.setTop (insertmarker.bottom() - d->mDropVisualizerWidth/2 + 1); + insertmarker.setBottom (insertmarker.bottom() + d->mDropVisualizerWidth/2); + } + + // This is not used anymore, at least by TDEListView itself (see viewportPaintEvent) + // Remove for KDE 4.0. + if (p) + p->fillRect(insertmarker, Dense4Pattern); + + return insertmarker; +} + +TQRect TDEListView::drawItemHighlighter(TQPainter *painter, TQListViewItem *item) +{ + TQRect r; + + if (item) + { + r = itemRect(item); + r.setLeft(r.left()+(item->depth()+(rootIsDecorated() ? 1 : 0))*treeStepSize()); + if (painter) + style().tqdrawPrimitive(TQStyle::PE_FocusRect, painter, r, colorGroup(), + TQStyle::Style_FocusAtBorder, colorGroup().highlight()); + } + + return r; +} + +void TDEListView::cleanItemHighlighter () +{ + if (d->mOldDropHighlighter.isValid()) + { + TQRect rect=d->mOldDropHighlighter; + d->mOldDropHighlighter = TQRect(); + viewport()->repaint(rect, true); + } +} + +void TDEListView::rename(TQListViewItem *item, int c) +{ + if (d->renameable.contains(c)) + { + ensureItemVisible(item); + d->editor->load(item,c); + } +} + +bool TDEListView::isRenameable (int col) const +{ + return d->renameable.contains(col); +} + +void TDEListView::setRenameable (int col, bool renameable) +{ + if (col>=header()->count()) return; + + d->renameable.remove(col); + if (renameable) + d->renameable+=col; +} + +void TDEListView::doneEditing(TQListViewItem *item, int row) +{ + emit itemRenamed(item, item->text(row), row); + emit itemRenamed(item); +} + +bool TDEListView::acceptDrag(TQDropEvent* e) const +{ + return acceptDrops() && itemsMovable() && (e->source()==viewport()); +} + +void TDEListView::setCreateChildren(bool b) +{ + d->createChildren=b; +} + +bool TDEListView::createChildren() const +{ + return d->createChildren; +} + + +int TDEListView::tooltipColumn() const +{ + return d->tooltipColumn; +} + +void TDEListView::setTooltipColumn(int column) +{ + d->tooltipColumn=column; +} + +void TDEListView::setDropHighlighter(bool b) +{ + d->dropHighlighter=b; +} + +bool TDEListView::dropHighlighter() const +{ + return d->dropHighlighter; +} + +bool TDEListView::showTooltip(TQListViewItem *item, const TQPoint &, int column) const +{ + return ((column==tooltipColumn()) && !tooltip(item, column).isEmpty()); +} + +TQString TDEListView::tooltip(TQListViewItem *item, int column) const +{ + return item->text(column); +} + +void TDEListView::setTabOrderedRenaming(bool b) +{ + d->tabRename = b; +} + +bool TDEListView::tabOrderedRenaming() const +{ + return d->tabRename; +} + +void TDEListView::keyPressEvent (TQKeyEvent* e) +{ + //don't we need a contextMenuModifier too ? (aleXXX) + if (e->key() == d->contextMenuKey) + { + emit menuShortCutPressed (this, currentItem()); + return; + } + + if (d->selectionMode != FileManager) + TQListView::keyPressEvent (e); + else + fileManagerKeyPressEvent (e); +} + +void TDEListView::activateAutomaticSelection() +{ + d->selectedBySimpleMove=true; + d->selectedUsingMouse=false; + if (currentItem()) + { + currentItem()->setSelected(true); + currentItem()->repaint(); + emit selectionChanged(); + }; +} + +void TDEListView::deactivateAutomaticSelection() +{ + d->selectedBySimpleMove=false; +} + +bool TDEListView::automaticSelection() const +{ + return d->selectedBySimpleMove; +} + +void TDEListView::fileManagerKeyPressEvent (TQKeyEvent* e) +{ + //don't care whether it's on the keypad or not + int e_state=(e->state() & ~Keypad); + + int oldSelectionDirection(d->selectionDirection); + + if ((e->key()!=Key_Shift) && (e->key()!=Key_Control) + && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)) + { + if ((e_state==ShiftButton) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove)) + selectAll(false); + d->selectionDirection=0; + d->wasShiftEvent = (e_state == ShiftButton); + }; + + //d->wasShiftEvent = (e_state == ShiftButton); + + + TQListViewItem* item = currentItem(); + if (!item) return; + + TQListViewItem* repaintItem1 = item; + TQListViewItem* repaintItem2 = 0L; + TQListViewItem* visItem = 0L; + + TQListViewItem* nextItem = 0L; + int items = 0; + + bool shiftOrCtrl((e_state==ControlButton) || (e_state==ShiftButton)); + int selectedItems(0); + for (TQListViewItem *tmpItem=firstChild(); tmpItem; tmpItem=tmpItem->nextSibling()) + if (tmpItem->isSelected()) selectedItems++; + + if (((!selectedItems) || ((selectedItems==1) && (d->selectedUsingMouse))) + && (e_state==Qt::NoButton) + && ((e->key()==Key_Down) + || (e->key()==Key_Up) + || (e->key()==Key_Next) + || (e->key()==Key_Prior) + || (e->key()==Key_Home) + || (e->key()==Key_End))) + { + d->selectedBySimpleMove=true; + d->selectedUsingMouse=false; + } + else if (selectedItems>1) + d->selectedBySimpleMove=false; + + bool emitSelectionChanged(false); + + switch (e->key()) + { + case Key_Escape: + selectAll(false); + emitSelectionChanged=true; + break; + + case Key_Space: + //toggle selection of current item + if (d->selectedBySimpleMove) + d->selectedBySimpleMove=false; + item->setSelected(!item->isSelected()); + emitSelectionChanged=true; + break; + + case Key_Insert: + //toggle selection of current item and move to the next item + if (d->selectedBySimpleMove) + { + d->selectedBySimpleMove=false; + if (!item->isSelected()) item->setSelected(true); + } + else + { + item->setSelected(!item->isSelected()); + }; + + nextItem=item->itemBelow(); + + if (nextItem) + { + repaintItem2=nextItem; + visItem=nextItem; + setCurrentItem(nextItem); + }; + d->selectionDirection=1; + emitSelectionChanged=true; + break; + + case Key_Down: + nextItem=item->itemBelow(); + //toggle selection of current item and move to the next item + if (shiftOrCtrl) + { + d->selectionDirection=1; + if (d->selectedBySimpleMove) + d->selectedBySimpleMove=false; + else + { + if (oldSelectionDirection!=-1) + { + item->setSelected(!item->isSelected()); + emitSelectionChanged=true; + }; + }; + } + else if ((d->selectedBySimpleMove) && (nextItem)) + { + item->setSelected(false); + emitSelectionChanged=true; + }; + + if (nextItem) + { + if (d->selectedBySimpleMove) + nextItem->setSelected(true); + repaintItem2=nextItem; + visItem=nextItem; + setCurrentItem(nextItem); + }; + break; + + case Key_Up: + nextItem=item->itemAbove(); + d->selectionDirection=-1; + //move to the prev. item and toggle selection of this one + // => No, can't select the last item, with this. For symmetry, let's + // toggle selection and THEN move up, just like we do in down (David) + if (shiftOrCtrl) + { + if (d->selectedBySimpleMove) + d->selectedBySimpleMove=false; + else + { + if (oldSelectionDirection!=1) + { + item->setSelected(!item->isSelected()); + emitSelectionChanged=true; + }; + } + } + else if ((d->selectedBySimpleMove) && (nextItem)) + { + item->setSelected(false); + emitSelectionChanged=true; + }; + + if (nextItem) + { + if (d->selectedBySimpleMove) + nextItem->setSelected(true); + repaintItem2=nextItem; + visItem=nextItem; + setCurrentItem(nextItem); + }; + break; + + case Key_End: + //move to the last item and toggle selection of all items inbetween + nextItem=item; + if (d->selectedBySimpleMove) + item->setSelected(false); + if (shiftOrCtrl) + d->selectedBySimpleMove=false; + + while(nextItem) + { + if (shiftOrCtrl) + nextItem->setSelected(!nextItem->isSelected()); + if (!nextItem->itemBelow()) + { + if (d->selectedBySimpleMove) + nextItem->setSelected(true); + repaintItem2=nextItem; + visItem=nextItem; + setCurrentItem(nextItem); + } + nextItem=nextItem->itemBelow(); + } + emitSelectionChanged=true; + break; + + case Key_Home: + // move to the first item and toggle selection of all items inbetween + nextItem = firstChild(); + visItem = nextItem; + repaintItem2 = visItem; + if (d->selectedBySimpleMove) + item->setSelected(false); + if (shiftOrCtrl) + { + d->selectedBySimpleMove=false; + + while ( nextItem != item ) + { + nextItem->setSelected( !nextItem->isSelected() ); + nextItem = nextItem->itemBelow(); + } + item->setSelected( !item->isSelected() ); + } + setCurrentItem( firstChild() ); + emitSelectionChanged=true; + break; + + case Key_Next: + items=visibleHeight()/item->height(); + nextItem=item; + if (d->selectedBySimpleMove) + item->setSelected(false); + if (shiftOrCtrl) + { + d->selectedBySimpleMove=false; + d->selectionDirection=1; + }; + + for (int i=0; isetSelected(!nextItem->isSelected()); + //the end + if ((i==items-1) || (!nextItem->itemBelow())) + + { + if (shiftOrCtrl) + nextItem->setSelected(!nextItem->isSelected()); + if (d->selectedBySimpleMove) + nextItem->setSelected(true); + ensureItemVisible(nextItem); + setCurrentItem(nextItem); + update(); + if ((shiftOrCtrl) || (d->selectedBySimpleMove)) + { + emit selectionChanged(); + } + return; + } + nextItem=nextItem->itemBelow(); + } + break; + + case Key_Prior: + items=visibleHeight()/item->height(); + nextItem=item; + if (d->selectedBySimpleMove) + item->setSelected(false); + if (shiftOrCtrl) + { + d->selectionDirection=-1; + d->selectedBySimpleMove=false; + }; + + for (int i=0; isetSelected(!nextItem->isSelected()); + //the end + if ((i==items-1) || (!nextItem->itemAbove())) + + { + if (d->selectedBySimpleMove) + nextItem->setSelected(true); + ensureItemVisible(nextItem); + setCurrentItem(nextItem); + update(); + if ((shiftOrCtrl) || (d->selectedBySimpleMove)) + { + emit selectionChanged(); + } + return; + } + nextItem=nextItem->itemAbove(); + } + break; + + case Key_Minus: + if ( item->isOpen() ) + setOpen( item, false ); + break; + case Key_Plus: + if ( !item->isOpen() && (item->isExpandable() || item->childCount()) ) + setOpen( item, true ); + break; + default: + bool realKey = ((e->key()!=Key_Shift) && (e->key()!=Key_Control) + && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)); + + bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected()); + if (realKey && selectCurrentItem) + item->setSelected(false); + //this is mainly for the "goto filename beginning with pressed char" feature (aleXXX) + TQListView::SelectionMode oldSelectionMode = selectionMode(); + setSelectionMode (TQListView::Multi); + TQListView::keyPressEvent (e); + setSelectionMode (oldSelectionMode); + if (realKey && selectCurrentItem) + { + currentItem()->setSelected(true); + emitSelectionChanged=true; + } + repaintItem2=currentItem(); + if (realKey) + visItem=currentItem(); + break; + } + + if (visItem) + ensureItemVisible(visItem); + + TQRect ir; + if (repaintItem1) + ir = ir.unite( itemRect(repaintItem1) ); + if (repaintItem2) + ir = ir.unite( itemRect(repaintItem2) ); + + if ( !ir.isEmpty() ) + { // rectangle to be repainted + if ( ir.x() < 0 ) + ir.moveBy( -ir.x(), 0 ); + viewport()->repaint( ir, false ); + } + /*if (repaintItem1) + repaintItem1->repaint(); + if (repaintItem2) + repaintItem2->repaint();*/ + update(); + if (emitSelectionChanged) + emit selectionChanged(); +} + +void TDEListView::setSelectionModeExt (SelectionModeExt mode) +{ + d->selectionMode = mode; + + switch (mode) + { + case Single: + case Multi: + case Extended: + case NoSelection: + setSelectionMode (static_cast(static_cast(mode))); + break; + + case FileManager: + setSelectionMode (TQListView::Extended); + break; + + default: + kdWarning () << "Warning: illegal selection mode " << int(mode) << " set!" << endl; + break; + } +} + +TDEListView::SelectionModeExt TDEListView::selectionModeExt () const +{ + return d->selectionMode; +} + +int TDEListView::itemIndex( const TQListViewItem *item ) const +{ + if ( !item ) + return -1; + + if ( item == firstChild() ) + return 0; + else { + TQListViewItemIterator it(firstChild()); + uint j = 0; + for (; it.current() && it.current() != item; ++it, ++j ); + + if( !it.current() ) + return -1; + + return j; + } +} + +TQListViewItem* TDEListView::itemAtIndex(int index) +{ + if (index<0) + return 0; + + int j(0); + for (TQListViewItemIterator it=firstChild(); it.current(); ++it) + { + if (j==index) + return it.current(); + ++j; + }; + return 0; +} + + +void TDEListView::emitContextMenu (TDEListView*, TQListViewItem* i) +{ + TQPoint p; + + if (i) + p = viewport()->mapToGlobal(itemRect(i).center()); + else + p = mapToGlobal(rect().center()); + + emit contextMenu (this, i, p); +} + +void TDEListView::emitContextMenu (TQListViewItem* i, const TQPoint& p, int) +{ + emit contextMenu (this, i, p); +} + +void TDEListView::setAcceptDrops (bool val) +{ + TQListView::setAcceptDrops (val); + viewport()->setAcceptDrops (val); +} + +int TDEListView::dropVisualizerWidth () const +{ + return d->mDropVisualizerWidth; +} + + +void TDEListView::viewportPaintEvent(TQPaintEvent *e) +{ + d->paintAbove = 0; + d->paintCurrent = 0; + d->paintBelow = 0; + d->painting = true; + + TQListView::viewportPaintEvent(e); + + if (d->mOldDropVisualizer.isValid() && e->rect().intersects(d->mOldDropVisualizer)) + { + TQPainter painter(viewport()); + + // This is where we actually draw the drop-visualizer + painter.fillRect(d->mOldDropVisualizer, Dense4Pattern); + } + if (d->mOldDropHighlighter.isValid() && e->rect().intersects(d->mOldDropHighlighter)) + { + TQPainter painter(viewport()); + + // This is where we actually draw the drop-highlighter + style().tqdrawPrimitive(TQStyle::PE_FocusRect, &painter, d->mOldDropHighlighter, colorGroup(), + TQStyle::Style_FocusAtBorder); + } + d->painting = false; +} + +void TDEListView::setFullWidth() +{ + setFullWidth(true); +} + +void TDEListView::setFullWidth(bool fullWidth) +{ + d->fullWidth = fullWidth; + header()->setStretchEnabled(fullWidth, columns()-1); +} + +bool TDEListView::fullWidth() const +{ + return d->fullWidth; +} + +int TDEListView::addColumn(const TQString& label, int width) +{ + int result = TQListView::addColumn(label, width); + if (d->fullWidth) { + header()->setStretchEnabled(false, columns()-2); + header()->setStretchEnabled(true, columns()-1); + } + return result; +} + +int TDEListView::addColumn(const TQIconSet& iconset, const TQString& label, int width) +{ + int result = TQListView::addColumn(iconset, label, width); + if (d->fullWidth) { + header()->setStretchEnabled(false, columns()-2); + header()->setStretchEnabled(true, columns()-1); + } + return result; +} + +void TDEListView::removeColumn(int index) +{ + TQListView::removeColumn(index); + if (d->fullWidth && index == columns()) header()->setStretchEnabled(true, columns()-1); +} + +void TDEListView::viewportResizeEvent(TQResizeEvent* e) +{ + TQListView::viewportResizeEvent(e); +} + +const TQColor &TDEListView::alternateBackground() const +{ + return d->alternateBackground; +} + +void TDEListView::setAlternateBackground(const TQColor &c) +{ + d->alternateBackground = c; + repaint(); +} + +void TDEListView::setShadeSortColumn(bool shadeSortColumn) +{ + d->shadeSortColumn = shadeSortColumn; + repaint(); +} + +bool TDEListView::shadeSortColumn() const +{ + return d->shadeSortColumn; +} + +void TDEListView::saveLayout(TDEConfig *config, const TQString &group) const +{ + TDEConfigGroupSaver saver(config, group); + TQStringList widths, order; + + const int colCount = columns(); + TQHeader* const thisHeader = header(); + for (int i = 0; i < colCount; ++i) + { + widths << TQString::number(columnWidth(i)); + order << TQString::number(thisHeader->mapToIndex(i)); + } + config->writeEntry("ColumnWidths", widths); + config->writeEntry("ColumnOrder", order); + config->writeEntry("SortColumn", d->sortColumn); + config->writeEntry("SortAscending", d->sortAscending); +} + +void TDEListView::restoreLayout(TDEConfig *config, const TQString &group) +{ + TDEConfigGroupSaver saver(config, group); + TQStringList cols = config->readListEntry("ColumnWidths"); + int i = 0; + { // scope the iterators + TQStringList::ConstIterator it = cols.constBegin(); + const TQStringList::ConstIterator itEnd = cols.constEnd(); + for (; it != itEnd; ++it) + setColumnWidth(i++, (*it).toInt()); + } + + // move sections in the correct sequence: from lowest to highest index position + // otherwise we move a section from an index, which modifies + // all index numbers to the right of the moved one + cols = config->readListEntry("ColumnOrder"); + const int colCount = columns(); + for (i = 0; i < colCount; ++i) // final index positions from lowest to highest + { + TQStringList::ConstIterator it = cols.constBegin(); + const TQStringList::ConstIterator itEnd = cols.constEnd(); + + int section = 0; + for (; (it != itEnd) && ((*it).toInt() != i); ++it, ++section) ; + + if ( it != itEnd ) { + // found the section to move to position i + header()->moveSection(section, i); + } + } + + if (config->hasKey("SortColumn")) + setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true)); +} + +void TDEListView::setSorting(int column, bool ascending) +{ + TQListViewItem *selected = 0; + + if (selectionMode() == TQListView::Single) { + selected = selectedItem(); + if (selected && !selected->isVisible()) + selected = 0; + } + else if (selectionMode() != TQListView::NoSelection) { + TQListViewItem *item = firstChild(); + while (item && !selected) { + if (item->isSelected() && item->isVisible()) + selected = item; + item = item->itemBelow(); + } + } + + d->sortColumn = column; + d->sortAscending = ascending; + TQListView::setSorting(column, ascending); + + if (selected) + ensureItemVisible(selected); + + TQListViewItem* item = firstChild(); + while ( item ) { + TDEListViewItem *kItem = dynamic_cast(item); + if (kItem) kItem->m_known = false; + item = item->itemBelow(); + } +} + +int TDEListView::columnSorted(void) const +{ + return d->sortColumn; +} + +bool TDEListView::ascendingSort(void) const +{ + return d->sortAscending; +} + +void TDEListView::takeItem(TQListViewItem *item) +{ + if(item && item == d->editor->currentItem()) + d->editor->terminate(); + + TQListView::takeItem(item); +} + +void TDEListView::disableAutoSelection() +{ + if ( d->disableAutoSelection ) + return; + + d->disableAutoSelection = true; + d->autoSelect.stop(); + d->autoSelectDelay = -1; +} + +void TDEListView::resetAutoSelection() +{ + if ( !d->disableAutoSelection ) + return; + + d->disableAutoSelection = false; + d->autoSelectDelay = TDEGlobalSettings::autoSelectDelay(); +} + +void TDEListView::doubleClicked( TQListViewItem *item, const TQPoint &pos, int c ) +{ + emit TQListView::doubleClicked( item, pos, c ); +} + +TDEListViewItem::TDEListViewItem(TQListView *parent) + : TQListViewItem(parent) +{ + init(); +} + +TDEListViewItem::TDEListViewItem(TQListViewItem *parent) + : TQListViewItem(parent) +{ + init(); +} + +TDEListViewItem::TDEListViewItem(TQListView *parent, TQListViewItem *after) + : TQListViewItem(parent, after) +{ + init(); +} + +TDEListViewItem::TDEListViewItem(TQListViewItem *parent, TQListViewItem *after) + : TQListViewItem(parent, after) +{ + init(); +} + +TDEListViewItem::TDEListViewItem(TQListView *parent, + TQString label1, TQString label2, TQString label3, TQString label4, + TQString label5, TQString label6, TQString label7, TQString label8) + : TQListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) +{ + init(); +} + +TDEListViewItem::TDEListViewItem(TQListViewItem *parent, + TQString label1, TQString label2, TQString label3, TQString label4, + TQString label5, TQString label6, TQString label7, TQString label8) + : TQListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) +{ + init(); +} + +TDEListViewItem::TDEListViewItem(TQListView *parent, TQListViewItem *after, + TQString label1, TQString label2, TQString label3, TQString label4, + TQString label5, TQString label6, TQString label7, TQString label8) + : TQListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) +{ + init(); +} + +TDEListViewItem::TDEListViewItem(TQListViewItem *parent, TQListViewItem *after, + TQString label1, TQString label2, TQString label3, TQString label4, + TQString label5, TQString label6, TQString label7, TQString label8) + : TQListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) +{ + init(); +} + +TDEListViewItem::~TDEListViewItem() +{ + if(listView()) + emit static_cast(listView())->itemRemoved(this); +} + +void TDEListViewItem::init() +{ + m_odd = m_known = false; + TDEListView *lv = static_cast(listView()); + setDragEnabled( dragEnabled() || lv->dragEnabled() ); + emit lv->itemAdded(this); +} + +void TDEListViewItem::insertItem(TQListViewItem *item) +{ + TQListViewItem::insertItem(item); + if(listView()) + emit static_cast(listView())->itemAdded(item); +} + +void TDEListViewItem::takeItem(TQListViewItem *item) +{ + TQListViewItem::takeItem(item); + if(listView()) + emit static_cast(listView())->itemRemoved(item); +} + +const TQColor &TDEListViewItem::backgroundColor() +{ + if (isAlternate()) + return static_cast< TDEListView* >(listView())->alternateBackground(); + return listView()->viewport()->colorGroup().base(); +} + +TQColor TDEListViewItem::backgroundColor(int column) +{ + TDEListView* view = static_cast< TDEListView* >(listView()); + TQColor color = isAlternate() ? + view->alternateBackground() : + view->viewport()->colorGroup().base(); + + // calculate a different color if the current column is sorted (only if more than 1 column) + if ( (view->columns() > 1) && view->shadeSortColumn() && (column == view->columnSorted()) ) + { + if ( color == Qt::black ) + color = TQColor(55, 55, 55); // dark gray + else + { + int h,s,v; + color.hsv(&h, &s, &v); + if ( v > 175 ) + color = color.dark(104); + else + color = color.light(120); + } + } + + return color; +} + +bool TDEListViewItem::isAlternate() +{ + TDEListView* const lv = static_cast(listView()); + if (lv && lv->alternateBackground().isValid()) + { + TDEListViewItem *above; + + TDEListView::TDEListViewPrivate* const lvD = lv->d; + + // Ok, there's some weirdness here that requires explanation as this is a + // speed hack. itemAbove() is a O(n) operation (though this isn't + // immediately clear) so we want to call it as infrequently as possible -- + // especially in the case of painting a cell. + // + // So, in the case that we *are* painting a cell: (1) we're assuming that + // said painting is happening top to bottem -- this assumption is present + // elsewhere in the implementation of this class, (2) itemBelow() is fast -- + // roughly constant time. + // + // Given these assumptions we can do a mixture of caching and telling the + // next item that the when that item is the current item that the now + // current item will be the item above it. + // + // Ideally this will make checking to see if the item above the current item + // is the alternate color a constant time operation rather than 0(n). + + if (lvD->painting) { + if (lvD->paintCurrent != this) + { + lvD->paintAbove = lvD->paintBelow == this ? lvD->paintCurrent : itemAbove(); + lvD->paintCurrent = this; + lvD->paintBelow = itemBelow(); + } + + above = dynamic_cast(lvD->paintAbove); + } + else + { + above = dynamic_cast(itemAbove()); + } + + m_known = above ? above->m_known : true; + if (m_known) + { + m_odd = above ? !above->m_odd : false; + } + else + { + TDEListViewItem *item; + bool previous = true; + if (parent()) + { + item = dynamic_cast(parent()); + if (item) + previous = item->m_odd; + item = dynamic_cast(parent()->firstChild()); + } + else + { + item = dynamic_cast(lv->firstChild()); + } + + while(item) + { + previous = !previous; + item->m_odd = previous; + item->m_known = true; + item = dynamic_cast(item->nextSibling()); + } + } + return m_odd; + } + return false; +} + +void TDEListViewItem::paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment) +{ + TQColorGroup _cg = cg; + TQListView* lv = listView(); + const TQPixmap *pm = lv->viewport()->backgroundPixmap(); + + if (pm && !pm->isNull()) + { + _cg.setBrush(TQColorGroup::Base, TQBrush(backgroundColor(column), *pm)); + TQPoint o = p->brushOrigin(); + p->setBrushOrigin( o.x()-lv->contentsX(), o.y()-lv->contentsY() ); + } + else + { + _cg.setColor((lv->viewport()->backgroundMode() == TQt::FixedColor) ? + TQColorGroup::Background : TQColorGroup::Base, + backgroundColor(column)); + } + TQListViewItem::paintCell(p, _cg, column, width, alignment); +} + +/*! + If \a select is TRUE, all the items get selected; otherwise all + the items get unselected. This only works in the selection modes \c + Multi and \c Extended. In \c Single and \c NoSelection mode the + selection of the current item is just set to \a select. +*/ + +void TDEListView::selectAll( bool select ) +{ + if ( selectionMode() == Multi || selectionMode() == Extended ) { + bool b = signalsBlocked(); + blockSignals( TRUE ); + bool anything = FALSE; + TQListViewItemIterator it( this ); + while ( it.current() ) { + TQListViewItem *i = it.current(); + if ( select == TRUE ) { + if ( (bool)i->isVisible() == TRUE ) { + i->setSelected( TRUE ); + anything = TRUE; + } + if ( (bool)i->isVisible() == FALSE ) { + i->setSelected( FALSE ); + anything = TRUE; + } + } + else { + if ( (bool)i->isSelected() != select ) { + i->setSelected( select ); + anything = TRUE; + } + } + ++it; + } + blockSignals( b ); + if ( anything ) { + emit selectionChanged(); +// d->useDoubleBuffer = TRUE; + triggerUpdate(); + } + } else if ( currentItem() ) { + TQListViewItem * i = currentItem(); + setSelected( i, select ); + } +} + +void TDEListView::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +#include "klistview.moc" +#include "klistviewlineedit.moc" + +// vim: noet diff --git a/tdeui/tdelistview.h b/tdeui/tdelistview.h new file mode 100644 index 000000000..7c01b6c29 --- /dev/null +++ b/tdeui/tdelistview.h @@ -0,0 +1,1095 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 Reginald Stadlbauer + Copyright (C) 2000 Charles Samuels + Copyright (C) 2000 Peter Putzer + + 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 KLISTVIEW_H +#define KLISTVIEW_H + +#include +#include + +#include +#include + +class TQDragObject; +class TDEConfig; +class KLineEdit; +/** + * This Widget extends the functionality of TQListView to honor the system + * wide settings for Single Click/Double Click mode, AutoSelection and + * ChangeCursorOverLink (TM). + * + * There is a new signal executed(). It gets connected to either + * TQListView::clicked() or TQListView::doubleClicked() depending on the KDE + * wide Single Click/Double Click settings. It is strongly recommended that + * you use this signal instead of the above mentioned. This way you don´t + * need to care about the current settings. + * If you want to get informed when the user selects something connect to the + * TQListView::selectionChanged() signal. + * + * Drag-and-Drop is supported with the signal dropped(), just setAcceptDrops(true) + * and connect it to a suitable slot. + * To see where you are dropping, setDropVisualizer(true). + * And also you'll need acceptDrag(TQDropEvent*) + * + * TDEListView is drag-enabled, too: to benefit from that you have to derive from it. + * Reimplement dragObject() and (possibly) startDrag(), + * and setDragEnabled(true). + */ +class TDEUI_EXPORT TDEListView : public TQListView +{ + friend class TDEListViewItem; + + Q_OBJECT + + TQ_ENUMS( SelectionModeExt ) + TQ_PROPERTY( bool fullWidth READ fullWidth WRITE setFullWidth ) + TQ_PROPERTY( bool itemsMovable READ itemsMovable WRITE setItemsMovable ) + TQ_PROPERTY( bool itemsRenameable READ itemsRenameable WRITE setItemsRenameable ) + TQ_PROPERTY( bool dragEnabled READ dragEnabled WRITE setDragEnabled ) + TQ_PROPERTY( bool autoOpen READ autoOpen WRITE setAutoOpen ) + TQ_PROPERTY( bool dropVisualizer READ dropVisualizer WRITE setDropVisualizer ) + TQ_PROPERTY( int tooltipColumn READ tooltipColumn WRITE setTooltipColumn ) + TQ_PROPERTY( int dropVisualizerWidth READ dropVisualizerWidth WRITE setDropVisualizerWidth ) + TQ_PROPERTY( TQColor alternateBackground READ alternateBackground WRITE setAlternateBackground ) + TQ_PROPERTY( bool shadeSortColumn READ shadeSortColumn WRITE setShadeSortColumn ) + + TQ_OVERRIDE( SelectionModeExt selectionMode READ selectionModeExt WRITE setSelectionModeExt ) + +public: + /** + * Possible selection modes. + * + * The first four correspond directly to TQListView::SelectionMode, while + * the FileManager selection mode is defined as follows: + * @li home: move to the first + * @li end: move to the last + * @li PgUp/PgDn: move one page up/down + * @li up/down: move one item up/down + * @li insert: toggle selection of current and move to the next + * @li space: toggle selection of the current + * @li CTRL+up: move to the previous item and toggle selection of this one + * @li CTRL+down: toggle selection of the current item and move to the next + * @li CTRL+end: toggle selection from (including) the current + * item to (including) the last item + * @li CTRL+home: toggle selection from (including) the current + * item to the (including) the first item + * @li CTRL+PgDn: toggle selection from (including) the current + * item to (excluding) the item one page down + * @li CTRL+PgUp: toggle selection from (excluding) the current + * item to (including) the item one page up + * + * The combinations work the same with SHIFT instead of CTRL, except + * that if you start selecting something using SHIFT everything selected + * before will be deselected first. + * + * Additionally the current item is always selected automatically when + * navigating using the keyboard, except other items were selected explicitly. + * + * This way e.g. SHIFT+up/PgUp then SHIFT+down/PgDn leaves no item selected + */ + enum SelectionModeExt { + Single = TQListView::Single, + Multi = TQListView::Multi, + Extended = TQListView::Extended, + NoSelection = TQListView::NoSelection, + FileManager + }; + + /** + * Constructor. + * + * The parameters @p parent and @p name are handled by + * TQListView, as usual. + */ + TDEListView (TQWidget *parent = 0, const char *name = 0); + + /** + * Destructor. + */ + virtual ~TDEListView(); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void setAcceptDrops (bool); + + /** + * This function determines whether the given coordinates are within the + * execute area. The execute area is the part of a TQListViewItem where mouse + * clicks or double clicks respectively generate a executed() signal. + * Depending on TQListView::allColumnsShowFocus() this is either the + * whole item or only the first column. + * @return true if point is inside execute area of an item, false in all + * other cases including the case that it is over the viewport. + */ + virtual bool isExecuteArea( const TQPoint& point ); + + /** + * Same thing, but from an x coordinate only. This only checks if x is in + * the first column (if all columns don't show focus), without testing if + * the y coordinate is over an item or not. + */ + bool isExecuteArea( int x ); + + /** + * @return a list containing the currently selected items. + * + * @deprecated + */ + TQPtrList selectedItems() const; + + /** + * @return a list containing the currently selected items. + * + * @param includeHiddenItems Set to true to return all items regardless of + * visibility. Set to false to only return items that are isVisible(). + * + * @return a list of all selected listview items + * + * @since 3.4 + */ + TQPtrList selectedItems(bool includeHiddenItems) const; // ### BIC: KDE 4: use an implicitly shared class! (QValutList?) and merge with above, default to true + + /** + * Arbitrarily move @p item to @p parent, positioned immediately after item @p after. + * If after is 0, @p item is made the first child of @p parent. + * + * (Un-deprecated in kde-3.4) + */ + void moveItem(TQListViewItem *item, TQListViewItem *parent, TQListViewItem *after); + + /** + * @return the last item (not child!) of this listview. + * + * @see lastChild() + */ + TQListViewItem *lastItem() const; + + /** + * @return the last child of this listview. + * + * @see lastItem() + */ + TQListViewItem* lastChild () const; + + /** + * @return the lineedit used for inline renaming. + * Use that to setup a KCompletion or TQValidator for the lineedit + * + * @since 3.2 + */ + KLineEdit* renameLineEdit() const; + + /** + * @returns if it is legal to move items in the list view. True by default. + * + * @see setDragEnabled() + * @see setItemsMovable() + */ + bool itemsMovable() const; + + /** + * @return whether inplace-renaming has been enabled. False by default. + * + * @see setItemsRenameable() + */ + bool itemsRenameable() const; + + /** + * @return whether dragging is enabled. False by default. + * + * @see setDragEnabled() + */ + bool dragEnabled() const; + + /** + * @return true if AutoOpen is enabled (not implemented currently). + * + * @see setAutoOpen() + */ + bool autoOpen() const; + + /** + * @return true if @p column is renamable. + * + * @see setRenameable() + */ + bool isRenameable (int column) const; + + /** + * @return true if drawing of the drop-visualizer has been enabled. True by default. + * + * @see setDropVisualizer() + */ + bool dropVisualizer() const; + + /** + * @return the column for which tooltips are displayed (or -1 if none set). + * + * @see setTooltipColumn() + */ + int tooltipColumn() const; + + /** + * For future expansions. + * + * Do not use. + * @deprecated + */ + bool createChildren() const KDE_DEPRECATED; + + /** + * @return true if drawing of the drop-highlighter has been enabled. False by default. + * + * @see setDropHighlighter() + */ + bool dropHighlighter() const; + + /** + * The dropVisualizerWidth defaults to 4. + * + * @see setDropVisualizerWidth() + * @return the current width of the drop-visualizer. + */ + int dropVisualizerWidth () const; + + /** + * @return the "extended" selection mode of this listview. + * + * @see SelectionModeExt + * @see setSelectionModeExt + */ + SelectionModeExt selectionModeExt () const; + + /** + * Returns the index of @p item within the item tree or -1 if + * @p item doesn't exist in this list view. This function takes + * all items into account not only the visible ones. + */ + int itemIndex( const TQListViewItem *item ) const; + + /** + * Returns the item of @p index within the item tree or 0 if + * @p index doesn't exist in this list view. This function takes + * all items into account not only the visible ones. + */ + TQListViewItem* itemAtIndex(int index); + + /** + * @deprecated + * @see setFullWidth() + */ + void setFullWidth() KDE_DEPRECATED; + + /** + * Let the last column fit exactly all the available width. + * + * @see fullWidth() + */ + void setFullWidth(bool fullWidth); + + /** + * Returns whether the last column is set to fit the available width. + * + * @see setFullWidth() + */ + bool fullWidth() const; + + /** + * Reimplemented for full width support + * + * @see removeColumn() + */ + virtual int addColumn(const TQString& label, int width = -1); + /** + * Reimplemented for full width support + */ + virtual int addColumn(const TQIconSet& iconset, const TQString& label, int width = -1); + /** + * Reimplemented for full width support + * + * @see addColumn() + */ + virtual void removeColumn(int index); + + /** + * sets the alternate background background color. + * This only has an effect if the items are TDEListViewItems + * + * @param c the color to use for every other item. Set to an invalid + * color to disable alternate colors. + * + * @see alternateBackground() + **/ + void setAlternateBackground(const TQColor &c); + /** + * @return the alternate background color + * + * @see setAlternateBackground() + */ + const TQColor &alternateBackground() const; + + /** + * Saves the list view's layout (column widtsh, column order, sort column) + * to a TDEConfig group + * + * @param config the TDEConfig object to write to + * @param group the config group to use + */ + void saveLayout(TDEConfig *config, const TQString &group) const; + /** + * Reads the list view's layout from a TDEConfig group as stored with + * saveLayout + * + * @param config the TDEConfig object to read from + * @param group the config group to use + */ + void restoreLayout(TDEConfig *config, const TQString &group); + /** + * Reimplemented to remember the current sort column and order. + * @param column is the column to be sorted, or -1 to sort in order of + * insertion + * @param ascending whether to sort ascending (or descending) + */ + virtual void setSorting(int column, bool ascending = true); + + /** + * @return the currently sorted column, or -1 if none is sorted + */ + int columnSorted(void) const; + + /** + * @return whether the current sort is ascending (or descending) + */ + bool ascendingSort(void) const; + + /** + * Reimplemented for internal reasons. + */ + virtual void takeItem(TQListViewItem *i); + + /** + * Set to true if the currently sorted column should be drawn shaded. Defaults to true + * @param shadeSortColumn True if sort column should be shaded. + * + * @since 3.4 + */ + void setShadeSortColumn(bool shadeSortColumn); + + /** + * See if the sort column should be drawn shaded + * @return true if the sort column should be shaded + * + * @since 3.4 + */ + bool shadeSortColumn(void) const; +signals: + + /** + * This signal is emitted whenever the user executes an listview item. + * That means depending on the KDE wide Single Click/Double Click + * setting the user clicked or double clicked on that item. + * @param item is the pointer to the executed listview item. + * + * Note that you may not delete any TQListViewItem objects in slots + * connected to this signal. + */ + void executed( TQListViewItem *item ); + + /** + * This signal is emitted whenever the user executes an listview item. + * That means depending on the KDE wide Single Click/Double Click + * setting the user clicked or double clicked on that item. + * @param item is the pointer to the executed listview item. + * @param pos is the position where the user has clicked + * @param c is the column into which the user clicked. + * + * Note that you may not delete any TQListViewItem objects in slots + * connected to this signal. + */ + void executed( TQListViewItem *item, const TQPoint &pos, int c ); + + /** + * This signal gets emitted whenever something acceptable is + * dropped onto the listview. + * + * @param e is the drop event itself (it has already been accepted) + * @param after is the item after which the drop occurred (or 0L, if + * the drop was above all items) + * + * @see acceptDrop() + */ + void dropped (TQDropEvent * e, TQListViewItem *after); + + /** + * This signal gets emitted whenever something acceptable is + * dropped onto the listview. + * + * This is an overloaded version of the above (provided to simplify + * processing drops outside of the class). + * + * @param list is the listview + * @param e is the drop event itself (it has already been accepted) + * @param after is the item after which the drop occurred (or 0L, if + * the drop was above all items + */ + void dropped (TDEListView* list, TQDropEvent* e, TQListViewItem* after); + + /** + * This signal gets emitted whenever something acceptable is + * dropped onto the listview. + * + * This function also provides a parent, in the event that your listview + * is a tree + * @param list is the listview + * @param e is the drop event itself (it has already been accepted) + * @param parent the item that is to be the parent of the new item + * @param after is the item after which the drop occurred (or 0L, if + * the drop was above all items + */ + void dropped (TDEListView* list, TQDropEvent* e, TQListViewItem* parent, TQListViewItem* after); + + /** + * This signal gets emitted whenever something acceptable is + * dropped onto the listview. + * + * This function also provides a parent, in the event that your listview + * is a tree + * @param e is the drop event itself (it has already been accepted) + * @param parent the item that is to be the parent of the new item + * @param after is the item after which the drop occurred (or 0L, if + * the drop was above all items + */ + void dropped (TQDropEvent* e, TQListViewItem* parent, TQListViewItem* after); + + /** + * This signal is emitted when ever the user moves an item in the list via + * DnD. + * If more than one item is moved at the same time, this signal is only emitted + * once. + */ + void moved(); + + /** + * Connect to this signal if you want to do some preprocessing before + * a move is made, for example, to disable sorting + * + * This is sent only once per each groups of moves. That is, for each + * drop that is a move this will be emitted once, before TDEListView calls + * @see moveItem() + */ + void aboutToMove(); + + /** + * This signal is emitted when ever the user moves an item in the list via + * DnD. + * If more than one item is moved at the same time, @p afterFirst and + * @p afterNow will reflect what was true before the move. + * This differs from moved(), so be careful. All the items will have been + * moved before moved() is emitted, which is not true in this method. // FIXME + * @param item the item that was moved + * @param afterFirst the item that parameter item was in before the move, in the list + * @param afterNow the item it's currently after. + */ + void moved (TQListViewItem *item, TQListViewItem *afterFirst, TQListViewItem *afterNow); + + + /** + * This signal is emitted after all the items have been moved. It reports info for + * each and every item moved, in order. The first element in @p items associates + * with the first of afterFirst and afterNow. + */ + void moved(TQPtrList &items, TQPtrList &afterFirst, TQPtrList &afterNow); + + /** + * This signal gets emitted when an item is renamed via in-place renaming. + * + * @param item is the renamed item. + * @param str is the new value of column @p col. + * @param col is the renamed column. + */ + void itemRenamed(TQListViewItem* item, const TQString &str, int col); + + /** + * Same as above, but without the extra information. + */ + void itemRenamed(TQListViewItem* item); + + /** + * This signal is emitted when the shortcut key for popup-menus is pressed. + * + * Normally you should not use this, just connect a slot to signal + * contextMenu (TDEListView*, TQListViewItem*, const TQPoint&) to correctly + * handle showing context menus regardless of settings. + * + * @param list is this listview. + * @param item is the currentItem() at the time the key was pressed. May be 0L. + */ + void menuShortCutPressed (TDEListView* list, TQListViewItem* item); + + /** + * This signal is emitted whenever a context-menu should be shown for item @p i. + * It automatically adjusts for all settings involved (Menu key, showMenuOnPress/Click). + * + * @param l is this listview. + * @param i is the item for which the menu should be shown. May be 0L. + * @param p is the point at which the menu should be shown. + */ + void contextMenu (TDEListView* l, TQListViewItem* i, const TQPoint& p); + + void itemAdded(TQListViewItem *item); + void itemRemoved(TQListViewItem *item); + +public slots: + /** + * Rename column @p c of @p item. + */ + virtual void rename(TQListViewItem *item, int c); + + /** + * By default, if you called setItemsRenameable(true), + * only the first column is renameable. + * Use this function to enable the feature on other columns. + * + * If you want more intelligent (dynamic) selection, + * you'll have to derive from TDEListView, + * and override rename() and call only call it + * if you want the item to be renamed. + */ + void setRenameable (int column, bool yesno=true); + + /** + * Set whether items in the list view can be moved. + * It is enabled by default. + * + * @see itemsMovable() + */ + virtual void setItemsMovable(bool b); + + /** + * Enables inplace-renaming of items. + * It is disabled by default. + * + * @see itemsRenameable() + * @see setRenameable() + */ + virtual void setItemsRenameable(bool b); + + /** + * Enable/Disable the dragging of items. + * It is disabled by default. + */ + virtual void setDragEnabled(bool b); + + /** + * Enable/Disable AutoOpen (not implemented currently). + */ + virtual void setAutoOpen(bool b); + + /** + * Enable/Disable the drawing of a drop-visualizer + * (a bar that shows where a dropped item would be inserted). + * It is enabled by default, if dragging is enabled + */ + virtual void setDropVisualizer(bool b); + + /** + * Set the width of the (default) drop-visualizer. + * If you don't call this method, the width is set to 4. + */ + void setDropVisualizerWidth (int w); + + /** + * Set which column should be used for automatic tooltips. + * + * @param column is the column for which tooltips will be shown. + * Set -1 to disable this feature. + */ + virtual void setTooltipColumn(int column); + + /** + * Enable/Disable the drawing of a drop-highlighter + * (a rectangle around the item under the mouse cursor). + * It is disabled by default. + */ + virtual void setDropHighlighter(bool b); + + /** + * For future expansions. + * + * Do not use. + * @deprecated + */ + virtual void setCreateChildren(bool b) KDE_DEPRECATED; + + /** + * Set the selection mode. + * + * A different name was chosen to avoid API-clashes with TQListView::setSelectionMode(). + */ + void setSelectionModeExt (SelectionModeExt mode); + + /** + * Enable/disable tabbing between editable cells + * @since 3.1 + */ + void setTabOrderedRenaming(bool b); + + /** + * Returns whether tab ordered renaming is enabled + * @since 3.1 + */ + bool tabOrderedRenaming() const; + + /** + * Override TQListView selectAll() so that filtered + * items are not selected + * + * @since 14.0 + */ + virtual void selectAll( bool select ); + +protected: + /** + * Determine whether a drop on position @p p would count as + * being above or below the TQRect @p rect. + * + * @param rect is the rectangle we examine. + * @param p is the point located in the rectangle, p is assumed to be in + * viewport coordinates. + */ + inline bool below (const TQRect& rect, const TQPoint& p) + { + return (p.y() > (rect.top() + (rect.bottom() - rect.top())/2)); + } + + /** + * An overloaded version of below(const TQRect&, const TQPoint&). + * + * It differs from the above only in what arguments it takes. + * + * @param i the item whose rect() is passed to the above function. + * @param p is translated from contents coordinates to viewport coordinates + * before being passed to the above function. + */ + inline bool below (TQListViewItem* i, const TQPoint& p) + { + return below (itemRect(i), contentsToViewport(p)); + } + + /** + * Reimplemented to reload the alternate background in palette changes. + * @internal + */ + virtual bool event( TQEvent * ); + + /** + * Emit signal executed. + * @internal + */ + void emitExecute( TQListViewItem *item, const TQPoint &pos, int c ); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void focusInEvent(TQFocusEvent* fe); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void focusOutEvent( TQFocusEvent *fe ); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void leaveEvent( TQEvent *e ); + + /** + * @return the tooltip for @p column of @p item. + */ + virtual TQString tooltip(TQListViewItem* item, int column) const; + + /** + * @return whether the tooltip for @p column of @p item shall be shown at point @p pos. + */ + virtual bool showTooltip(TQListViewItem *item, const TQPoint &pos, int column) const; + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void contentsDragMoveEvent (TQDragMoveEvent *event); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void contentsMousePressEvent( TQMouseEvent *e ); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void contentsMouseMoveEvent( TQMouseEvent *e ); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void contentsMouseDoubleClickEvent ( TQMouseEvent *e ); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void contentsDragLeaveEvent (TQDragLeaveEvent *event); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void contentsMouseReleaseEvent (TQMouseEvent*); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void contentsDropEvent (TQDropEvent*); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void contentsDragEnterEvent (TQDragEnterEvent *); + + /** + * @return a dragobject encoding the current selection. + * + * @see setDragEnabled() + */ + virtual TQDragObject *dragObject(); + + /** + * @return true if the @p event provides some acceptable + * format. + * A common mistake is to forget the "const" in your reimplementation + */ + virtual bool acceptDrag (TQDropEvent* event) const; + + /** + * Paint the drag line. If painter is null, don't try to :) + * + * If after == 0 then the marker should be drawn at the top. + * + * @return the rectangle that you painted to. + */ + virtual TQRect drawDropVisualizer (TQPainter *p, TQListViewItem *parent, TQListViewItem *after); + + /** + * Paint the drag rectangle. If painter is null, don't try to :) + * + * + * @return the rectangle that you painted to. + */ + virtual TQRect drawItemHighlighter(TQPainter *painter, TQListViewItem *item); + + /** + * This method calls dragObject() and starts the drag. + * + * Reimplement it to do fancy stuff like setting a pixmap or + * using a non-default DragMode + */ + virtual void startDrag(); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void keyPressEvent (TQKeyEvent*); + + /** + * Reimplemented for internal reasons. + * Further reimplementations should call this function or else + * some features may not work correctly. + * + * The API is unaffected. + */ + virtual void viewportPaintEvent(TQPaintEvent*); + + /** + * In FileManager selection mode: explicitly activate the mode + * in which the current item is automatically selected. + */ + void activateAutomaticSelection(); + /** + * In FileManager selection mode: explicitly deactivate the mode + * in which the current item is automatically selected. + */ + void deactivateAutomaticSelection(); + /** + * In FileManager selection mode: return whether it is currently in the mode + * where the current item is selected automatically. + * Returns false if items were selected explicitly, e.g. using the mouse. + */ + bool automaticSelection() const; + + /** + * Reimplemented for setFullWidth() + */ + virtual void viewportResizeEvent(TQResizeEvent* e); + + /** + * Disable AutoSelection. This overrides the system wide setting for + * AutoSelection. Please don't call this unless you have good reasons to + * override the system wide setting for AutoSelection. + * @see resetAutoSelection() + * @since 3.2 + */ + void disableAutoSelection(); + + /** + * Reset AutoSelection to the system wide setting. + * @see disableAutoSelection() + * @since 3.2 + */ + void resetAutoSelection(); + + /** + * @deprecated This is just here for binary compatibility. Use the signal + * in TQListView instead. + */ + // KDE 4: remove + void doubleClicked( TQListViewItem *item, const TQPoint &pos, int c ); + +protected slots: + /** + * Update internal settings whenever the global ones change. + * @internal + */ + void slotSettingsChanged(int); + + void slotMouseButtonClicked( int btn, TQListViewItem *item, const TQPoint &pos, int c ); + void doneEditing(TQListViewItem *item, int row); + + /** + * Repaint the rect where I was drawing the drop line. + */ + void cleanDropVisualizer(); + + /** + * Repaint the rect where I was drawing the drop rectangle. + */ + void cleanItemHighlighter(); + + /** + * Emit the contextMenu signal. This slot is for mouse actions. + */ + void emitContextMenu (TQListViewItem*, const TQPoint&, int); + + /** + * Emit the contextMenu signal. This slot is for key presses. + */ + void emitContextMenu (TDEListView*, TQListViewItem*); + + /** + * Accessory slot for AutoSelect + * @internal + */ + void slotOnItem( TQListViewItem *item ); + + /** + * Accessory slot for AutoSelect/ChangeCursorOverItem + * @internal + */ + void slotOnViewport(); + + /** + * Process AutoSelection. + * @internal + */ + void slotAutoSelect(); + + void slotDragExpand(); + + /** + * Reacts to header changes in full width mode + * @internal + */ + void slotHeaderChanged(); + +protected: + /** + * Handle dropEvent when itemsMovable() is set to true. + */ + virtual void movableDropEvent (TQListViewItem* parent, TQListViewItem* afterme); + + /** + * Where is the nearest TQListViewItem that I'm going to drop? + * + * FIXME KDE 4.0: Make this method const so it can be called from an + * acceptDrag method without ugly casts + */ + virtual void findDrop(const TQPoint &pos, TQListViewItem *&parent, TQListViewItem *&after); + + /** + * A special keyPressEvent (for FileManager selection mode). + */ + void fileManagerKeyPressEvent (TQKeyEvent*); + + /** + * Convert the depth of an item into its indentation in pixels + */ + int depthToPixels( int depth ); + +private: + class Tooltip; +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEListViewPrivate; + TDEListViewPrivate* const d; + bool isExecuteArea( int x, TQListViewItem* item ); +}; + +/** + * A listview item with support for alternate background colors. It is + * a drop-in replacement for QListViewItem + * + * @short listview item with alternate background color support + */ +class TDEUI_EXPORT TDEListViewItem : public TQListViewItem +{ + friend class TDEListView; +public: + /** + * constructors. The semantics remain as in TQListViewItem. + * Although they accept a TQListViewItem as parent, please + * don't mix TDEListViewItem (or subclasses) with QListViewItem + * (or subclasses). + */ + TDEListViewItem(TQListView *parent); + TDEListViewItem(TQListViewItem *parent); + TDEListViewItem(TQListView *parent, TQListViewItem *after); + TDEListViewItem(TQListViewItem *parent, TQListViewItem *after); + + TDEListViewItem(TQListView *parent, + TQString, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null); + + TDEListViewItem(TQListViewItem *parent, + TQString, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null); + + TDEListViewItem(TQListView *parent, TQListViewItem *after, + TQString, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null); + + TDEListViewItem(TQListViewItem *parent, TQListViewItem *after, + TQString, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null, + TQString = TQString::null, TQString = TQString::null); + + virtual ~TDEListViewItem(); + + virtual void insertItem(TQListViewItem *item); + virtual void takeItem(TQListViewItem *item); + /** + * returns true if this item is to be drawn with the alternate background + */ + bool isAlternate(); + /** + * returns the background color for this item + */ + const TQColor &backgroundColor() KDE_DEPRECATED; // #### should be removed in 4.0; use below instead + + /** + * returns the background color for this item at given column + * This can be different in the column which is sorted due to shading + * ### could be merged with above (column = -1) to be source compatible + * ### but will only work if sort-shading is not used or the listView has + * ### only 1 column + * @since 3.4 + */ + TQColor backgroundColor(int column); + + virtual void paintCell(TQPainter *p, const TQColorGroup &cg, + int column, int width, int alignment); + +private: + void init(); + +private: + uint m_odd : 1; + uint m_known : 1; + uint m_unused : 30; +}; + +#endif + +// vim: ts=2 sw=2 et diff --git a/tdeui/tdelistviewlineedit.h b/tdeui/tdelistviewlineedit.h new file mode 100644 index 000000000..d0019698e --- /dev/null +++ b/tdeui/tdelistviewlineedit.h @@ -0,0 +1,65 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 Charles Samuels + + 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 KLISTVIEWLINEEDIT_H +#define KLISTVIEWLINEEDIT_H + +#include +#include + +/** + * the editor for a TDEListView. please don't use this. + * @internal + **/ +class TDEUI_EXPORT TDEListViewLineEdit : public KLineEdit +{ +Q_OBJECT +public: + TDEListViewLineEdit(TDEListView *parent); + ~TDEListViewLineEdit(); + + TQListViewItem *currentItem() const; + +signals: + void done(TQListViewItem*, int); + +public slots: + void terminate(); + void load(TQListViewItem *i, int c); + +protected: + virtual void focusOutEvent(TQFocusEvent *); + virtual void keyPressEvent(TQKeyEvent *e); + virtual void paintEvent(TQPaintEvent *e); + virtual bool event (TQEvent *pe); + + /// @since 3.1 + void selectNextCell (TQListViewItem *pi, int column, bool forward); + void terminate(bool commit); + TQListViewItem *item; + int col; + TDEListView* const p; + +protected slots: + void slotSelectionChanged(); + + /// @since 3.5.4 + void slotItemRemoved(TQListViewItem *i); + +}; + +#endif diff --git a/tdeui/tdelistviewsearchline.cpp b/tdeui/tdelistviewsearchline.cpp new file mode 100644 index 000000000..96bf82370 --- /dev/null +++ b/tdeui/tdelistviewsearchline.cpp @@ -0,0 +1,501 @@ +/* This file is part of the KDE libraries + Copyright (c) 2003 Scott Wheeler + + 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. +*/ + +#include "klistviewsearchline.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID 2004 + +class TDEListViewSearchLine::TDEListViewSearchLinePrivate +{ +public: + TDEListViewSearchLinePrivate() : + listView(0), + caseSensitive(false), + activeSearch(false), + keepParentsVisible(true), + queuedSearches(0) {} + + TDEListView *listView; + bool caseSensitive; + bool activeSearch; + bool keepParentsVisible; + TQString search; + int queuedSearches; + TQValueList searchColumns; +}; + +//////////////////////////////////////////////////////////////////////////////// +// public methods +//////////////////////////////////////////////////////////////////////////////// + +TDEListViewSearchLine::TDEListViewSearchLine(TQWidget *parent, TDEListView *listView, const char *name) : + KLineEdit(parent, name) +{ + d = new TDEListViewSearchLinePrivate; + + d->listView = listView; + + connect(this, TQT_SIGNAL(textChanged(const TQString &)), + this, TQT_SLOT(queueSearch(const TQString &))); + + if(listView) { + connect(listView, TQT_SIGNAL(destroyed()), + this, TQT_SLOT(listViewDeleted())); + + connect(listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), + this, TQT_SLOT(itemAdded(TQListViewItem *))); + } + else + setEnabled(false); +} + +TDEListViewSearchLine::TDEListViewSearchLine(TQWidget *parent, const char *name) : + KLineEdit(parent, name) +{ + d = new TDEListViewSearchLinePrivate; + + d->listView = 0; + + connect(this, TQT_SIGNAL(textChanged(const TQString &)), + this, TQT_SLOT(queueSearch(const TQString &))); + + setEnabled(false); +} + +TDEListViewSearchLine::~TDEListViewSearchLine() +{ + delete d; +} + +bool TDEListViewSearchLine::caseSensitive() const +{ + return d->caseSensitive; +} + +TQValueList TDEListViewSearchLine::searchColumns() const +{ + return d->searchColumns; +} + +bool TDEListViewSearchLine::keepParentsVisible() const +{ + return d->keepParentsVisible; +} + +TDEListView *TDEListViewSearchLine::listView() const +{ + return d->listView; +} + +//////////////////////////////////////////////////////////////////////////////// +// public slots +//////////////////////////////////////////////////////////////////////////////// + +void TDEListViewSearchLine::updateSearch(const TQString &s) +{ + if(!d->listView) + return; + + d->search = s.isNull() ? text() : s; + + // If there's a selected item that is visible, make sure that it's visible + // when the search changes too (assuming that it still matches). + + TQListViewItem *currentItem = 0; + + switch(d->listView->selectionMode()) + { + case TDEListView::NoSelection: + break; + case TDEListView::Single: + currentItem = d->listView->selectedItem(); + break; + default: + { + int flags = TQListViewItemIterator::Selected | TQListViewItemIterator::Visible; + for(TQListViewItemIterator it(d->listView, flags); + it.current() && !currentItem; + ++it) + { + if(d->listView->itemRect(it.current()).isValid()) + currentItem = it.current(); + } + } + } + + if(d->keepParentsVisible) + checkItemParentsVisible(d->listView->firstChild()); + else + checkItemParentsNotVisible(); + + if(currentItem) + d->listView->ensureItemVisible(currentItem); +} + +void TDEListViewSearchLine::setCaseSensitive(bool cs) +{ + d->caseSensitive = cs; +} + +void TDEListViewSearchLine::setKeepParentsVisible(bool v) +{ + d->keepParentsVisible = v; +} + +void TDEListViewSearchLine::setSearchColumns(const TQValueList &columns) +{ + d->searchColumns = columns; +} + +void TDEListViewSearchLine::setListView(TDEListView *lv) +{ + if(d->listView) { + disconnect(d->listView, TQT_SIGNAL(destroyed()), + this, TQT_SLOT(listViewDeleted())); + + disconnect(d->listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), + this, TQT_SLOT(itemAdded(TQListViewItem *))); + } + + d->listView = lv; + + if(lv) { + connect(d->listView, TQT_SIGNAL(destroyed()), + this, TQT_SLOT(listViewDeleted())); + + connect(d->listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), + this, TQT_SLOT(itemAdded(TQListViewItem *))); + } + + setEnabled(bool(lv)); +} + +//////////////////////////////////////////////////////////////////////////////// +// protected members +//////////////////////////////////////////////////////////////////////////////// + +bool TDEListViewSearchLine::itemMatches(const TQListViewItem *item, const TQString &s) const +{ + if(s.isEmpty()) + return true; + + // If the search column list is populated, search just the columns + // specifified. If it is empty default to searching all of the columns. + + if(!d->searchColumns.isEmpty()) { + TQValueList::ConstIterator it = d->searchColumns.begin(); + for(; it != d->searchColumns.end(); ++it) { + if(*it < item->listView()->columns() && + item->text(*it).find(s, 0, d->caseSensitive) >= 0) + return true; + } + } + else { + for(int i = 0; i < item->listView()->columns(); i++) { + if(item->listView()->columnWidth(i) > 0 && + item->text(i).find(s, 0, d->caseSensitive) >= 0) + { + return true; + } + } + } + + return false; +} + +TQPopupMenu *TDEListViewSearchLine::createPopupMenu() +{ + TQPopupMenu *popup = KLineEdit::createPopupMenu(); + + if (d->listView->columns()>1) { + TQPopupMenu *subMenu = new TQPopupMenu(popup); + connect(subMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(searchColumnsMenuActivated(int))); + + popup->insertSeparator(); + popup->insertItem(i18n("Search Columns"), subMenu); + + subMenu->insertItem(i18n("All Visible Columns"), KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID); + subMenu->insertSeparator(); + + bool allColumnsAreSearchColumns = true; + // TODO Make the entry order match the actual column order + TQHeader* const header = d->listView->header(); + int visibleColumns = 0; + for(int i = 0; i < d->listView->columns(); i++) { + if(d->listView->columnWidth(i)>0) { + TQString columnText = d->listView->columnText(i); + if(columnText.isEmpty()) { + int visiblePosition=1; + for(int j = 0; j < header->mapToIndex(i); j++) + if(d->listView->columnWidth(header->mapToSection(j))>0) + visiblePosition++; + columnText = i18n("Column number %1","Column No. %1").arg(visiblePosition); + } + subMenu->insertItem(columnText, visibleColumns); + if(d->searchColumns.isEmpty() || d->searchColumns.find(i) != d->searchColumns.end()) + subMenu->setItemChecked(visibleColumns, true); + else + allColumnsAreSearchColumns = false; + visibleColumns++; + } + } + subMenu->setItemChecked(KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID, allColumnsAreSearchColumns); + + // searchColumnsMenuActivated() relies on one possible "all" representation + if(allColumnsAreSearchColumns && !d->searchColumns.isEmpty()) + d->searchColumns.clear(); + } + + return popup; +} + +//////////////////////////////////////////////////////////////////////////////// +// protected slots +//////////////////////////////////////////////////////////////////////////////// + +void TDEListViewSearchLine::queueSearch(const TQString &search) +{ + d->queuedSearches++; + d->search = search; + TQTimer::singleShot(200, this, TQT_SLOT(activateSearch())); +} + +void TDEListViewSearchLine::activateSearch() +{ + --(d->queuedSearches); + + if(d->queuedSearches == 0) + updateSearch(d->search); +} + +//////////////////////////////////////////////////////////////////////////////// +// private slots +//////////////////////////////////////////////////////////////////////////////// + +void TDEListViewSearchLine::itemAdded(TQListViewItem *item) const +{ + item->setVisible(itemMatches(item, text())); +} + +void TDEListViewSearchLine::listViewDeleted() +{ + d->listView = 0; + setEnabled(false); +} + +void TDEListViewSearchLine::searchColumnsMenuActivated(int id) +{ + if(id == KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID) { + if(d->searchColumns.isEmpty()) + d->searchColumns.append(0); + else + d->searchColumns.clear(); + } + else { + if(d->searchColumns.find(id) != d->searchColumns.end()) + d->searchColumns.remove(id); + else { + if(d->searchColumns.isEmpty()) { + for(int i = 0; i < d->listView->columns(); i++) { + if(i != id) + d->searchColumns.append(i); + } + } + else + d->searchColumns.append(id); + } + } + updateSearch(); +} + +//////////////////////////////////////////////////////////////////////////////// +// private methods +//////////////////////////////////////////////////////////////////////////////// + +void TDEListViewSearchLine::checkItemParentsNotVisible() +{ + TQListViewItemIterator it(d->listView); + for(; it.current(); ++it) + { + TQListViewItem *item = it.current(); + if(itemMatches(item, d->search)) + item->setVisible(true); + else + item->setVisible(false); + } +} + +#include + +/** Check whether \p item, its siblings and their descendents should be shown. Show or hide the items as necessary. + * + * \p item The list view item to start showing / hiding items at. Typically, this is the first child of another item, or the + * the first child of the list view. + * \p highestHiddenParent The highest (closest to root) ancestor of \p item which is hidden. If 0, all parents of + * \p item must be visible. + * \return \c true if an item which should be visible is found, \c false if all items found should be hidden. If this function + * returns true and \p highestHiddenParent was not 0, highestHiddenParent will have been shown. + */ +bool TDEListViewSearchLine::checkItemParentsVisible(TQListViewItem *item, TQListViewItem *highestHiddenParent) +{ + bool visible = false; + TQListViewItem * first = item; + for(; item; item = item->nextSibling()) + { + //What we pass to our children as highestHiddenParent: + TQListViewItem * hhp = highestHiddenParent ? highestHiddenParent : item->isVisible() ? 0L : item; + bool childMatch = false; + if(item->firstChild() && checkItemParentsVisible(item->firstChild(), hhp)) + childMatch = true; + // Should this item be shown? It should if any children should be, or if it matches. + if(childMatch || itemMatches(item, d->search)) + { + visible = true; + if (highestHiddenParent) + { + highestHiddenParent->setVisible(true); + // Calling setVisible on our ancestor will unhide all its descendents. Hide the ones + // before us that should not be shown. + for(TQListViewItem *hide = first; hide != item; hide = hide->nextSibling()) + hide->setVisible(false); + highestHiddenParent = 0; + // If we matched, than none of our children matched, yet the setVisible() call on our + // ancestor unhid them, undo the damage: + if(!childMatch) + for(TQListViewItem *hide = item->firstChild(); hide; hide = hide->nextSibling()) + hide->setVisible(false); + } + else + item->setVisible(true); + } + else + item->setVisible(false); + } + return visible; +} + +//////////////////////////////////////////////////////////////////////////////// +// TDEListViewSearchLineWidget +//////////////////////////////////////////////////////////////////////////////// + +class TDEListViewSearchLineWidget::TDEListViewSearchLineWidgetPrivate +{ +public: + TDEListViewSearchLineWidgetPrivate() : listView(0), searchLine(0), clearButton(0) {} + TDEListView *listView; + TDEListViewSearchLine *searchLine; + TQToolButton *clearButton; +}; + +TDEListViewSearchLineWidget::TDEListViewSearchLineWidget(TDEListView *listView, + TQWidget *parent, + const char *name) : + TQHBox(parent, name) +{ + d = new TDEListViewSearchLineWidgetPrivate; + d->listView = listView; + + setSpacing(5); + + TQTimer::singleShot(0, this, TQT_SLOT(createWidgets())); +} + +TDEListViewSearchLineWidget::~TDEListViewSearchLineWidget() +{ + delete d; +} + +TDEListViewSearchLine *TDEListViewSearchLineWidget::createSearchLine(TDEListView *listView) +{ + if(!d->searchLine) + d->searchLine = new TDEListViewSearchLine(this, listView); + return d->searchLine; +} + +void TDEListViewSearchLineWidget::createWidgets() +{ + positionInToolBar(); + + if(!d->clearButton) { + d->clearButton = new TQToolButton(this); + TQIconSet icon = SmallIconSet(TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase"); + d->clearButton->setIconSet(icon); + } + + d->clearButton->show(); + + TQLabel *label = new TQLabel(i18n("S&earch:"), this, "kde toolbar widget"); + + d->searchLine = createSearchLine(d->listView); + d->searchLine->show(); + + label->setBuddy(d->searchLine); + label->show(); + + connect(d->clearButton, TQT_SIGNAL(clicked()), d->searchLine, TQT_SLOT(clear())); +} + +TDEListViewSearchLine *TDEListViewSearchLineWidget::searchLine() const +{ + return d->searchLine; +} + +void TDEListViewSearchLineWidget::positionInToolBar() +{ + TDEToolBar *toolBar = tqt_dynamic_cast(parent()); + + if(toolBar) { + + // Here we have The Big Ugly. Figure out how many widgets are in the + // and do a hack-ish iteration over them to find this widget so that we + // can insert the clear button before it. + + int widgetCount = toolBar->count(); + + for(int index = 0; index < widgetCount; index++) { + int id = toolBar->idAt(index); + if(toolBar->getWidget(id) == this) { + toolBar->setItemAutoSized(id); + if(!d->clearButton) { + TQString icon = TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase"; + d->clearButton = new TDEToolBarButton(icon, 2005, toolBar); + } + toolBar->insertWidget(2005, d->clearButton->width(), d->clearButton, index); + break; + } + } + } + + if(d->searchLine) + d->searchLine->show(); +} + +#include "klistviewsearchline.moc" diff --git a/tdeui/tdelistviewsearchline.h b/tdeui/tdelistviewsearchline.h new file mode 100644 index 000000000..4c278a9d9 --- /dev/null +++ b/tdeui/tdelistviewsearchline.h @@ -0,0 +1,264 @@ +/* This file is part of the KDE libraries + Copyright (c) 2003 Scott Wheeler + + 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 KLISTVIEWSEARCHLINE_H +#define KLISTVIEWSEARCHLINE_H + +#include +#include + +class TDEListView; +class TQListViewItem; +class TQToolButton; + +/** + * This class makes it easy to add a search line for filtering the items in a + * listview based on a simple text search. + * + * No changes to the application other than instantiating this class with an + * appropriate TDEListView should be needed. + * + * If you want the clear button and the search label, you should take a look at + * the TDEListViewSearchLineWidget + * + * @note { When iterating over items in the TDEListView, make sure that + * the iterator only includes visible items (for example, by adding + * TQListViewItemIterator::Visible to the iterator flags). Otherwise, + * actions (such as deletion) may be taken on items that have been + * hidden by the search function. } + * @since 3.3 + */ + +class TDEUI_EXPORT TDEListViewSearchLine : public KLineEdit +{ + Q_OBJECT + +public: + + /** + * Constructs a TDEListViewSearchLine with \a listView being the TDEListView to + * be filtered. + * + * If \a listView is null then the widget will be disabled until a listview + * is set with setListView(). + */ + TDEListViewSearchLine(TQWidget *parent = 0, TDEListView *listView = 0, const char *name = 0); + + /** + * Constructs a TDEListViewSearchLine without any TDEListView to filter. The + * TDEListView object has to be set later with setListView(). + */ + TDEListViewSearchLine(TQWidget *parent, const char *name); + + /** + * Destroys the TDEListViewSearchLine. + */ + virtual ~TDEListViewSearchLine(); + + /** + * Returns true if the search is case sensitive. This defaults to false. + * + * @see setCaseSensitive() + */ + bool caseSensitive() const; + + /** + * Returns the current list of columns that will be searched. If the + * returned list is empty all visible columns will be searched. + * + * @see setSearchColumns + */ + TQValueList searchColumns() const; + + /** + * If this is true (the default) then the parents of matched items will also + * be shown. + * + * @see setKeepParentsVisible() + */ + bool keepParentsVisible() const; + + /** + * Returns the listview that is currently filtered by the search. + * + * @see setListView() + */ + TDEListView *listView() const; + +public slots: + /** + * Updates search to only make visible the items that match \a s. If + * \a s is null then the line edit's text will be used. + */ + virtual void updateSearch(const TQString &s = TQString::null); + + /** + * Make the search case sensitive or case insensitive. + * + * @see caseSenstive() + */ + void setCaseSensitive(bool cs); + + /** + * When a search is active on a list that's organized into a tree view if + * a parent or ancesestor of an item is does not match the search then it + * will be hidden and as such so too will any children that match. + * + * If this is set to true (the default) then the parents of matching items + * will be shown. + * + * @see keepParentsVisible + */ + void setKeepParentsVisible(bool v); + + /** + * Sets the list of columns to be searched. The default is to search all, + * visible columns which can be restored by passing \a columns as an empty + * list. + * + * @see searchColumns + */ + void setSearchColumns(const TQValueList &columns); + + /** + * Sets the TDEListView that is filtered by this search line. If \a lv is null + * then the widget will be disabled. + * + * @see listView() + */ + void setListView(TDEListView *lv); + +protected: + + /** + * Returns true if \a item matches the search \a s. This will be evaluated + * based on the value of caseSensitive(). This can be overridden in + * subclasses to implement more complicated matching schemes. + */ + virtual bool itemMatches(const TQListViewItem *item, const TQString &s) const; + + /** + * Re-implemented for internal reasons. API not affected. + * + * See TQLineEdit::mousePressEvent(). + */ + virtual TQPopupMenu *createPopupMenu(); + +protected slots: + /** + * When keys are pressed a new search string is created and a timer is + * activated. The most recent search is activated when this timer runs out + * if another key has not yet been pressed. + * + * This method makes @param search the most recent search and starts the + * timer. + * + * Together with activateSearch() this makes it such that searches are not + * started until there is a short break in the users typing. + * + * @see activateSearch() + */ + void queueSearch(const TQString &search); + + /** + * When the timer started with queueSearch() expires this slot is called. + * If there has been another timer started then this slot does nothing. + * However if there are no other pending searches this starts the list view + * search. + * + * @see queueSearch() + */ + void activateSearch(); + +private: + + /** + * This is used in case parent items of matching items shouldn't be + * visible. It hides all items that don't match the search string. + */ + void checkItemParentsNotVisible(); + + /** + * This is used in case parent items of matching items should be visible. + * It makes a recursive call to all children. It returns true if at least + * one item in the subtree with the given root item is visible. + */ + bool checkItemParentsVisible(TQListViewItem *item, TQListViewItem *highestHiddenParent = 0); + +private slots: + void itemAdded(TQListViewItem *item) const; + void listViewDeleted(); + void searchColumnsMenuActivated(int); + +private: + class TDEListViewSearchLinePrivate; + TDEListViewSearchLinePrivate *d; +}; + +/** + * Creates a widget featuring a TDEListViewSearchLine, a label with the text + * "Search" and a button to clear the search. + * + * @since 3.4 + */ +class TDEUI_EXPORT TDEListViewSearchLineWidget : public TQHBox +{ + Q_OBJECT + +public: + /** + * Creates a TDEListViewSearchLineWidget for \a listView with \a parent as the + * parent with and \a name. + */ + TDEListViewSearchLineWidget(TDEListView *listView = 0, TQWidget *parent = 0, + const char *name = 0); + + /** + * Destroys the TDEListViewSearchLineWidget + */ + ~TDEListViewSearchLineWidget(); + + /** + * Creates the search line. This can be useful to reimplement in cases where + * a TDEListViewSearchLine subclass is used. + */ + virtual TDEListViewSearchLine *createSearchLine(TDEListView *listView); + + /** + * Returns a pointer to the search line. + */ + TDEListViewSearchLine *searchLine() const; + +protected slots: + /** + * Creates the widgets inside of the widget. This is called from the + * constructor via a single shot timer so that it it guaranteed to run + * after construction is complete. This makes it suitable for overriding in + * subclasses. + */ + virtual void createWidgets(); + +private slots: + void positionInToolBar(); + +private: + class TDEListViewSearchLineWidgetPrivate; + TDEListViewSearchLineWidgetPrivate *d; +}; + +#endif diff --git a/tdeui/tdemainwindow.cpp b/tdeui/tdemainwindow.cpp new file mode 100644 index 000000000..743c273cc --- /dev/null +++ b/tdeui/tdemainwindow.cpp @@ -0,0 +1,1249 @@ + /* This file is part of the KDE libraries + Copyright + (C) 2000 Reginald Stadlbauer (reggie@kde.org) + (C) 1997 Stephan Kulow (coolo@kde.org) + (C) 1997-2000 Sven Radej (radej@kde.org) + (C) 1997-2000 Matthias Ettrich (ettrich@kde.org) + (C) 1999 Chris Schlaeger (cs@kde.org) + (C) 2002 Joseph Wenninger (jowenn@kde.org) + + 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. + */ +#include "config.h" + +#include "kmainwindow.h" +#include "kmainwindowiface.h" +#include "ktoolbarhandler.h" +#include "kwhatsthismanager_p.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#if defined Q_WS_X11 +#include +#endif + +#include +#include +#include + +class TDEMainWindowPrivate { +public: + bool showHelpMenu:1; + + bool autoSaveSettings:1; + bool settingsDirty:1; + bool autoSaveWindowSize:1; + bool care_about_geometry:1; + bool shuttingDown:1; + TQString autoSaveGroup; + TDEAccel * kaccel; + TDEMainWindowInterface *m_interface; + KDEPrivate::ToolBarHandler *toolBarHandler; + TQTimer* settingsTimer; + TDEToggleAction *showStatusBarAction; + TQRect defaultWindowSize; + TQPtrList hiddenDockWindows; +}; + +TQPtrList* TDEMainWindow::memberList = 0L; +static bool no_query_exit = false; +static KMWSessionManaged* ksm = 0; +static KStaticDeleter ksmd; + +class KMWSessionManaged : public KSessionManaged +{ +public: + KMWSessionManaged() + { + } + ~KMWSessionManaged() + { + } + bool saveState( TQSessionManager& ) + { + TDEConfig* config = TDEApplication::kApplication()->sessionConfig(); + if ( TDEMainWindow::memberList->first() ){ + // According to Jochen Wilhelmy , this + // hook is useful for better document orientation + TDEMainWindow::memberList->first()->saveGlobalProperties(config); + } + + TQPtrListIterator it(*TDEMainWindow::memberList); + int n = 0; + for (it.toFirst(); it.current(); ++it){ + n++; + it.current()->savePropertiesInternal(config, n); + } + config->setGroup(TQString::fromLatin1("Number")); + config->writeEntry(TQString::fromLatin1("NumberOfWindows"), n ); + return true; + } + + bool commitData( TQSessionManager& sm ) + { + // not really a fast method but the only compatible one + if ( sm.allowsInteraction() ) { + bool canceled = false; + TQPtrListIterator it(*TDEMainWindow::memberList); + ::no_query_exit = true; + for (it.toFirst(); it.current() && !canceled;){ + TDEMainWindow *window = *it; + ++it; // Update now, the current window might get deleted + if ( !window->testWState( TQt::WState_ForceHide ) ) { + TQCloseEvent e; + TQApplication::sendEvent( window, &e ); + canceled = !e.isAccepted(); + /* Don't even think_about deleting widgets with + Qt::WDestructiveClose flag set at this point. We + are faking a close event, but we are *not*_ + closing the window. The purpose of the faked + close event is to prepare the application so it + can safely be quit without the user losing data + (possibly showing a message box "do you want to + save this or that?"). It is possible that the + session manager quits the application later + (emitting TQApplication::aboutToQuit() when this + happens), but it is also possible that the user + cancels the shutdown, so the application will + continue to run. + */ + } + } + ::no_query_exit = false; + if (canceled) + return false; + + TDEMainWindow* last = 0; + for (it.toFirst(); it.current() && !canceled; ++it){ + TDEMainWindow *window = *it; + if ( !window->testWState( TQt::WState_ForceHide ) ) { + last = window; + } + } + if ( last ) + return last->queryExit(); + // else + return true; + } + + // the user wants it, the user gets it + return true; + } +}; + +static bool being_first = true; + +TDEMainWindow::TDEMainWindow( TQWidget* parent, const char *name, WFlags f ) + : TQMainWindow( parent, name, f ), KXMLGUIBuilder( this ), helpMenu2( 0 ), factory_( 0 ) +{ + initTDEMainWindow(name, 0); +} + +TDEMainWindow::TDEMainWindow( int cflags, TQWidget* parent, const char *name, WFlags f ) + : TQMainWindow( parent, name, f ), KXMLGUIBuilder( this ), helpMenu2( 0 ), factory_( 0 ) +{ + initTDEMainWindow(name, cflags); +} + +void TDEMainWindow::initTDEMainWindow(const char *name, int cflags) +{ + KWhatsThisManager::init (); + setDockMenuEnabled( false ); + mHelpMenu = 0; + kapp->setTopWidget( this ); + actionCollection()->setWidget( this ); + connect(kapp, TQT_SIGNAL(shutDown()), this, TQT_SLOT(shuttingDown())); + if( !memberList ) + memberList = new TQPtrList; + + if ( !ksm ) + ksm = ksmd.setObject(ksm, new KMWSessionManaged()); + // set a unique object name. Required by session management. + TQCString objname; + TQCString s; + int unusedNumber; + if ( !name ) + { // no name given + objname = kapp->instanceName() + "-mainwindow#"; + s = objname + '1'; // start adding number immediately + unusedNumber = 1; + } + else if( name[0] != '\0' && name[ strlen( name ) - 1 ] == '#' ) + { // trailing # - always add a number + objname = name; + s = objname + '1'; // start adding number immediately + unusedNumber = 1; + } + else + { + objname = name; + s = objname; + unusedNumber = 0; // add numbers only when needed + } + for(;;) { + TQWidgetList* list = kapp->topLevelWidgets(); + TQWidgetListIt it( *list ); + bool found = false; + for( TQWidget* w = it.current(); + w != NULL; + ++it, w = it.current()) + if( w != this && w->name() == s ) + { + found = true; + break; + } + delete list; + if( !found ) + break; + s.setNum( ++unusedNumber ); + s = objname + s; + } + setName( s ); + + memberList->append( this ); + + d = new TDEMainWindowPrivate; + d->showHelpMenu = true; + d->settingsDirty = false; + d->autoSaveSettings = false; + d->autoSaveWindowSize = true; // for compatibility + d->kaccel = actionCollection()->kaccel(); + d->toolBarHandler = 0; + d->settingsTimer = 0; + d->showStatusBarAction = NULL; + d->shuttingDown = false; + if ((d->care_about_geometry = being_first)) { + being_first = false; + if ( kapp->geometryArgument().isNull() ) // if there is no geometry, it doesn't mater + d->care_about_geometry = false; + else + parseGeometry(false); + } + + setCaption( kapp->caption() ); + if ( cflags & NoDCOPObject) + d->m_interface = 0; + else + d->m_interface = new TDEMainWindowInterface(this); + + if (!kapp->authorize("movable_toolbars")) + setDockWindowsMovable(false); +} + +TDEAction *TDEMainWindow::toolBarMenuAction() +{ + if ( !d->toolBarHandler ) + return 0; + + return d->toolBarHandler->toolBarMenuAction(); +} + + +void TDEMainWindow::setupToolbarMenuActions() +{ + if ( d->toolBarHandler ) + d->toolBarHandler->setupActions(); +} + +void TDEMainWindow::parseGeometry(bool parsewidth) +{ + assert ( !kapp->geometryArgument().isNull() ); + assert ( d->care_about_geometry ); + +#if defined Q_WS_X11 + int x, y; + int w, h; + int m = XParseGeometry( kapp->geometryArgument().latin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h); + if (parsewidth) { + TQSize minSize = minimumSize(); + TQSize maxSize = maximumSize(); + if ( !(m & WidthValue) ) + w = width(); + if ( !(m & HeightValue) ) + h = height(); + w = QMIN(w,maxSize.width()); + h = QMIN(h,maxSize.height()); + w = QMAX(w,minSize.width()); + h = QMAX(h,minSize.height()); + resize(w, h); + } else { + if ( parsewidth && !(m & XValue) ) + x = geometry().x(); + if ( parsewidth && !(m & YValue) ) + y = geometry().y(); + if ( (m & XNegative) ) + x = TDEApplication::desktop()->width() + x - w; + if ( (m & YNegative) ) + y = TDEApplication::desktop()->height() + y - h; + move(x, y); + } +#endif +} + +TDEMainWindow::~TDEMainWindow() +{ + delete d->settingsTimer; + TQMenuBar* mb = internalMenuBar(); + delete mb; + delete d->m_interface; + delete d; + memberList->remove( this ); +} + +TDEPopupMenu* TDEMainWindow::helpMenu( const TQString &aboutAppText, bool showWhatsThis ) +{ + if( !mHelpMenu ) { + if ( aboutAppText.isEmpty() ) + mHelpMenu = new KHelpMenu( this, instance()->aboutData(), showWhatsThis); + else + mHelpMenu = new KHelpMenu( this, aboutAppText, showWhatsThis ); + + if ( !mHelpMenu ) + return 0; + connect( mHelpMenu, TQT_SIGNAL( showAboutApplication() ), + this, TQT_SLOT( showAboutApplication() ) ); + } + + return mHelpMenu->menu(); +} + +TDEPopupMenu* TDEMainWindow::customHelpMenu( bool showWhatsThis ) +{ + if( !mHelpMenu ) { + mHelpMenu = new KHelpMenu( this, TQString::null, showWhatsThis ); + connect( mHelpMenu, TQT_SIGNAL( showAboutApplication() ), + this, TQT_SLOT( showAboutApplication() ) ); + } + + return mHelpMenu->menu(); +} + +bool TDEMainWindow::canBeRestored( int number ) +{ + if ( !kapp->isRestored() ) + return false; + TDEConfig *config = kapp->sessionConfig(); + if ( !config ) + return false; + config->setGroup( TQString::fromLatin1("Number") ); + int n = config->readNumEntry( TQString::fromLatin1("NumberOfWindows") , 1 ); + return number >= 1 && number <= n; +} + +const TQString TDEMainWindow::classNameOfToplevel( int number ) +{ + if ( !kapp->isRestored() ) + return TQString::null; + TDEConfig *config = kapp->sessionConfig(); + if ( !config ) + return TQString::null; + TQString s; + s.setNum( number ); + s.prepend( TQString::fromLatin1("WindowProperties") ); + config->setGroup( s ); + if ( !config->hasKey( TQString::fromLatin1("ClassName") ) ) + return TQString::null; + else + return config->readEntry( TQString::fromLatin1("ClassName") ); +} + +void TDEMainWindow::show() +{ + TQMainWindow::show(); + + for ( TQPtrListIterator it( d->hiddenDockWindows ); it.current(); ++it ) + it.current()->show(); + + d->hiddenDockWindows.clear(); +} + +void TDEMainWindow::hide() +{ + if ( isVisible() ) { + + d->hiddenDockWindows.clear(); + + TQObjectList *list = queryList( TQDOCKWINDOW_OBJECT_NAME_STRING ); + for( TQObjectListIt it( *list ); it.current(); ++it ) { + TQDockWindow *dw = (TQDockWindow*)it.current(); + if ( dw->isTopLevel() && dw->isVisible() ) { + d->hiddenDockWindows.append( dw ); + dw->hide(); + } + } + delete list; + } + + TQWidget::hide(); +} + +bool TDEMainWindow::restore( int number, bool show ) +{ + if ( !canBeRestored( number ) ) + return false; + TDEConfig *config = kapp->sessionConfig(); + if ( readPropertiesInternal( config, number ) ){ + if ( show ) + TDEMainWindow::show(); + return false; + } + return false; +} + +KXMLGUIFactory *TDEMainWindow::guiFactory() +{ + if ( !factory_ ) + factory_ = new KXMLGUIFactory( this, TQT_TQOBJECT(this), "guifactory" ); + return factory_; +} + +int TDEMainWindow::configureToolbars() +{ + saveMainWindowSettings(TDEGlobal::config()); + KEditToolbar dlg(actionCollection(), xmlFile(), true, this); + connect(&dlg, TQT_SIGNAL(newToolbarConfig()), TQT_SLOT(saveNewToolbarConfig())); + return dlg.exec(); +} + +void TDEMainWindow::saveNewToolbarConfig() +{ + createGUI(xmlFile()); + applyMainWindowSettings( TDEGlobal::config() ); +} + +void TDEMainWindow::setupGUI( int options, const TQString & xmlfile ) { + setupGUI(TQSize(), options, xmlfile); +} + +void TDEMainWindow::setupGUI( TQSize defaultSize, int options, const TQString & xmlfile ) { + if( options & Keys ){ + KStdAction::keyBindings(guiFactory(), + TQT_SLOT(configureShortcuts()), actionCollection()); + } + + if( (options & StatusBar) && internalStatusBar() ){ + createStandardStatusBarAction(); + } + + if( options & ToolBar ){ + setStandardToolBarMenuEnabled( true ); + KStdAction::configureToolbars(TQT_TQOBJECT(this), + TQT_SLOT(configureToolbars() ), actionCollection()); + } + + if( options & Create ){ + createGUI(xmlfile,false); + } + + if( options & Save ){ + // setupGUI() is typically called in the constructor before show(), + // so the default window size will be incorrect unless the application + // hard coded the size which they should try not to do (i.e. use + // size hints). + if(initialGeometrySet()) + { + // Do nothing... + } + else if(defaultSize.isValid()) + { + resize(defaultSize); + } + else if(!isShown()) + { + adjustSize(); + } + setAutoSaveSettings(); + } + +} + +void TDEMainWindow::createGUI( const TQString &xmlfile, bool _conserveMemory ) +{ + // disabling the updates prevents unnecessary redraws + setUpdatesEnabled( false ); + + // just in case we are rebuilding, let's remove our old client + guiFactory()->removeClient( this ); + + // make sure to have an empty GUI + TQMenuBar* mb = internalMenuBar(); + if ( mb ) + mb->clear(); + + (void)toolBarIterator(); // make sure toolbarList is most-up-to-date + toolbarList.setAutoDelete( true ); + toolbarList.clear(); + toolbarList.setAutoDelete( false ); + + // don't build a help menu unless the user ask for it + if (d->showHelpMenu) { + // we always want a help menu + if (!helpMenu2) + helpMenu2 = new KHelpMenu(this, instance()->aboutData(), true, + actionCollection()); + } + + // we always want to load in our global standards file + setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) ); + + // now, merge in our local xml file. if this is null, then that + // means that we will be only using the global file + if ( !xmlfile.isNull() ) { + setXMLFile( xmlfile, true ); + } else { + TQString auto_file(instance()->instanceName() + "ui.rc"); + setXMLFile( auto_file, true ); + } + + // make sure we don't have any state saved already + setXMLGUIBuildDocument( TQDomDocument() ); + + // do the actual GUI building + guiFactory()->addClient( this ); + + // try and get back *some* of our memory + if ( _conserveMemory ) + { + // before freeing the memory allocated by the DOM document we also + // free all memory allocated internally in the KXMLGUIFactory for + // the menubar and the toolbars . This however implies that we + // have to take care of deleting those widgets ourselves. For + // destruction this is no problem, but when rebuilding we have + // to take care of that (and we want to rebuild the GUI when + // using stuff like the toolbar editor ). + // In addition we have to take care of not removing containers + // like popupmenus, defined in the XML document. + // this code should probably go into a separate method in TDEMainWindow. + // there's just one problem: I'm bad in finding names ;-) , so + // I skipped this ;-) + + TQDomDocument doc = domDocument(); + + for( TQDomNode n = doc.documentElement().firstChild(); + !n.isNull(); n = n.nextSibling()) + { + TQDomElement e = n.toElement(); + + if ( e.tagName().lower() == "toolbar" ) + factory_->resetContainer( e.attribute( "name" ) ); + else if ( e.tagName().lower() == "menubar" ) + factory_->resetContainer( e.tagName(), true ); + } + + conserveMemory(); + } + + setUpdatesEnabled( true ); + updateGeometry(); +} + +void TDEMainWindow::setHelpMenuEnabled(bool showHelpMenu) +{ + d->showHelpMenu = showHelpMenu; +} + +bool TDEMainWindow::isHelpMenuEnabled() +{ + return d->showHelpMenu; +} + +void TDEMainWindow::setCaption( const TQString &caption ) +{ + setPlainCaption( kapp->makeStdCaption(caption) ); +} + +void TDEMainWindow::setCaption( const TQString &caption, bool modified ) +{ + setPlainCaption( kapp->makeStdCaption(caption, true, modified) ); +} + +void TDEMainWindow::setPlainCaption( const TQString &caption ) +{ + TQMainWindow::setCaption( caption ); +#if defined Q_WS_X11 + NETWinInfo info( tqt_xdisplay(), winId(), tqt_xrootwin(), 0 ); + info.setName( caption.utf8().data() ); +#endif +} + +void TDEMainWindow::appHelpActivated( void ) +{ + if( !mHelpMenu ) { + mHelpMenu = new KHelpMenu( this ); + if ( !mHelpMenu ) + return; + } + mHelpMenu->appHelpActivated(); +} + +void TDEMainWindow::slotStateChanged(const TQString &newstate) +{ + stateChanged(newstate, KXMLGUIClient::StateNoReverse); +} + +/* + * Get rid of this for KDE 4.0 + */ +void TDEMainWindow::slotStateChanged(const TQString &newstate, + KXMLGUIClient::ReverseStateChange reverse) +{ + stateChanged(newstate, reverse); +} + +/* + * Enable this for KDE 4.0 + */ +// void TDEMainWindow::slotStateChanged(const TQString &newstate, +// bool reverse) +// { +// stateChanged(newstate, +// reverse ? KXMLGUIClient::StateReverse : KXMLGUIClient::StateNoReverse); +// } + +void TDEMainWindow::closeEvent ( TQCloseEvent *e ) +{ + // Save settings if auto-save is enabled, and settings have changed + if (d->settingsDirty && d->autoSaveSettings) + saveAutoSaveSettings(); + + if (queryClose()) { + e->accept(); + + int not_withdrawn = 0; + TQPtrListIterator it(*TDEMainWindow::memberList); + for (it.toFirst(); it.current(); ++it){ + if ( !it.current()->isHidden() && it.current()->isTopLevel() && it.current() != this ) + not_withdrawn++; + } + + if ( !no_query_exit && not_withdrawn <= 0 ) { // last window close accepted? + if ( queryExit() && !kapp->sessionSaving() && !d->shuttingDown ) { // Yes, Quit app? + // don't call queryExit() twice + disconnect(kapp, TQT_SIGNAL(shutDown()), this, TQT_SLOT(shuttingDown())); + d->shuttingDown = true; + kapp->deref(); // ...and quit application. + } else { + // cancel closing, it's stupid to end up with no windows at all.... + e->ignore(); + } + } + } +} + +bool TDEMainWindow::queryExit() +{ + return true; +} + +bool TDEMainWindow::queryClose() +{ + return true; +} + +void TDEMainWindow::saveGlobalProperties( TDEConfig* ) +{ +} + +void TDEMainWindow::readGlobalProperties( TDEConfig* ) +{ +} + +#if defined(KDE_COMPAT) +void TDEMainWindow::updateRects() +{ +} +#endif + +void TDEMainWindow::showAboutApplication() +{ +} + +void TDEMainWindow::savePropertiesInternal( TDEConfig *config, int number ) +{ + bool oldASWS = d->autoSaveWindowSize; + d->autoSaveWindowSize = true; // make saveMainWindowSettings save the window size + + TQString s; + s.setNum(number); + s.prepend(TQString::fromLatin1("WindowProperties")); + config->setGroup(s); + + // store objectName, className, Width and Height for later restoring + // (Only useful for session management) + config->writeEntry(TQString::fromLatin1("ObjectName"), name()); + config->writeEntry(TQString::fromLatin1("ClassName"), className()); + + saveMainWindowSettings(config); // Menubar, statusbar and Toolbar settings. + + s.setNum(number); + config->setGroup(s); + saveProperties(config); + + d->autoSaveWindowSize = oldASWS; +} + +void TDEMainWindow::saveMainWindowSettings(TDEConfig *config, const TQString &configGroup) +{ + kdDebug(200) << "TDEMainWindow::saveMainWindowSettings " << configGroup << endl; + TQString oldGroup; + + if (!configGroup.isEmpty()) + { + oldGroup = config->group(); + config->setGroup(configGroup); + } + + // Called by session management - or if we want to save the window size anyway + if ( d->autoSaveWindowSize ) + saveWindowSize( config ); + + TQStatusBar* sb = internalStatusBar(); + if (sb) { + if(!config->hasDefault("StatusBar") && !sb->isHidden() ) + config->revertToDefault("StatusBar"); + else + config->writeEntry("StatusBar", sb->isHidden() ? "Disabled" : "Enabled"); + } + + TQMenuBar* mb = internalMenuBar(); + if (mb) { + TQString MenuBar = TQString::fromLatin1("MenuBar"); + if(!config->hasDefault("MenuBar") && !mb->isHidden() ) + config->revertToDefault("MenuBar"); + else + config->writeEntry("MenuBar", mb->isHidden() ? "Disabled" : "Enabled"); + } + + int n = 1; // Toolbar counter. toolbars are counted from 1, + TDEToolBar *toolbar = 0; + TQPtrListIterator it( toolBarIterator() ); + while ( ( toolbar = it.current() ) ) { + ++it; + TQString group; + if (!configGroup.isEmpty()) + { + // Give a number to the toolbar, but prefer a name if there is one, + // because there's no real guarantee on the ordering of toolbars + group = (!::qstrcmp(toolbar->name(), "unnamed") ? TQString::number(n) : TQString(" ")+toolbar->name()); + group.prepend(" Toolbar"); + group.prepend(configGroup); + } + toolbar->saveSettings(config, group); + n++; + } + if (!configGroup.isEmpty()) + config->setGroup(oldGroup); +} + +void TDEMainWindow::setStandardToolBarMenuEnabled( bool enable ) +{ + if ( enable ) { + if ( d->toolBarHandler ) + return; + + d->toolBarHandler = new KDEPrivate::ToolBarHandler( this ); + + if ( factory() ) + factory()->addClient( d->toolBarHandler ); + } else { + if ( !d->toolBarHandler ) + return; + + if ( factory() ) + factory()->removeClient( d->toolBarHandler ); + + delete d->toolBarHandler; + d->toolBarHandler = 0; + } +} + +bool TDEMainWindow::isStandardToolBarMenuEnabled() const +{ + return ( d->toolBarHandler ); +} + +void TDEMainWindow::createStandardStatusBarAction(){ + if(!d->showStatusBarAction){ + d->showStatusBarAction = KStdAction::showStatusbar(TQT_TQOBJECT(this), TQT_SLOT(setSettingsDirty()), actionCollection()); + KStatusBar *sb = statusBar(); // Creates statusbar if it doesn't exist already. + connect(d->showStatusBarAction, TQT_SIGNAL(toggled(bool)), sb, TQT_SLOT(setShown(bool))); + d->showStatusBarAction->setChecked(sb->isHidden()); + } +} + +bool TDEMainWindow::readPropertiesInternal( TDEConfig *config, int number ) +{ + if ( number == 1 ) + readGlobalProperties( config ); + + // in order they are in toolbar list + TQString s; + s.setNum(number); + s.prepend(TQString::fromLatin1("WindowProperties")); + + config->setGroup(s); + + // restore the object name (window role) + if ( config->hasKey(TQString::fromLatin1("ObjectName" )) ) + setName( config->readEntry(TQString::fromLatin1("ObjectName")).latin1()); // latin1 is right here + + applyMainWindowSettings(config); // Menubar, statusbar and toolbar settings. + + s.setNum(number); + config->setGroup(s); + readProperties(config); + return true; +} + +void TDEMainWindow::applyMainWindowSettings(TDEConfig *config, const TQString &configGroup) +{ + return applyMainWindowSettings(config,configGroup,false); +} + +void TDEMainWindow::applyMainWindowSettings(TDEConfig *config, const TQString &configGroup,bool force) +{ + kdDebug(200) << "TDEMainWindow::applyMainWindowSettings" << endl; + + TDEConfigGroupSaver saver( config, configGroup.isEmpty() ? config->group() : configGroup ); + + restoreWindowSize(config); + + TQStatusBar* sb = internalStatusBar(); + if (sb) { + TQString entry = config->readEntry("StatusBar", "Enabled"); + if ( entry == "Disabled" ) + sb->hide(); + else + sb->show(); + if(d->showStatusBarAction) + d->showStatusBarAction->setChecked(!sb->isHidden()); + } + + TQMenuBar* mb = internalMenuBar(); + if (mb) { + TQString entry = config->readEntry ("MenuBar", "Enabled"); + if ( entry == "Disabled" ) + mb->hide(); + else + mb->show(); + } + + int n = 1; // Toolbar counter. toolbars are counted from 1, + TDEToolBar *toolbar; + TQPtrListIterator it( toolBarIterator() ); // must use own iterator + + for ( ; it.current(); ++it) { + toolbar= it.current(); + TQString group; + if (!configGroup.isEmpty()) + { + // Give a number to the toolbar, but prefer a name if there is one, + // because there's no real guarantee on the ordering of toolbars + group = (!::qstrcmp(toolbar->name(), "unnamed") ? TQString::number(n) : TQString(" ")+toolbar->name()); + group.prepend(" Toolbar"); + group.prepend(configGroup); + } + toolbar->applySettings(config, group, force); + n++; + } + + finalizeGUI( true ); +} + +void TDEMainWindow::finalizeGUI( bool force ) +{ + //kdDebug(200) << "TDEMainWindow::finalizeGUI force=" << force << endl; + // The whole reason for this is that moveToolBar relies on the indexes + // of the other toolbars, so in theory it should be called only once per + // toolbar, but in increasing order of indexes. + // Since we can't do that immediately, we move them, and _then_ + // we call positionYourself again for each of them, but this time + // the toolbariterator should give them in the proper order. + // Both the XMLGUI and applySettings call this, hence "force" for the latter. + TQPtrListIterator it( toolBarIterator() ); + for ( ; it.current() ; ++it ) { + it.current()->positionYourself( force ); + } + + d->settingsDirty = false; +} + +void TDEMainWindow::saveWindowSize( TDEConfig * config ) const +{ + int scnum = TQApplication::desktop()->screenNumber(parentWidget()); + TQRect desk = TQApplication::desktop()->screenGeometry(scnum); + int w, h; +#if defined Q_WS_X11 + // save maximalization as desktop size + 1 in that direction + KWin::WindowInfo info = KWin::windowInfo( winId(), NET::WMState ); + w = info.state() & NET::MaxHoriz ? desk.width() + 1 : width(); + h = info.state() & NET::MaxVert ? desk.height() + 1 : height(); +#else + if (isMaximized()) { + w = desk.width() + 1; + h = desk.height() + 1; + } + //TODO: add "Maximized" property instead "+1" hack +#endif + TQRect size( desk.width(), w, desk.height(), h ); + bool defaultSize = (size == d->defaultWindowSize); + TQString widthString = TQString::fromLatin1("Width %1").arg(desk.width()); + TQString heightString = TQString::fromLatin1("Height %1").arg(desk.height()); + if (!config->hasDefault(widthString) && defaultSize) + config->revertToDefault(widthString); + else + config->writeEntry(widthString, w ); + + if (!config->hasDefault(heightString) && defaultSize) + config->revertToDefault(heightString); + else + config->writeEntry(heightString, h ); +} + +void TDEMainWindow::restoreWindowSize( TDEConfig * config ) +{ + if (d->care_about_geometry) { + parseGeometry(true); + } else { + // restore the size + int scnum = TQApplication::desktop()->screenNumber(parentWidget()); + TQRect desk = TQApplication::desktop()->screenGeometry(scnum); + if ( d->defaultWindowSize.isNull() ) // only once + d->defaultWindowSize = TQRect(desk.width(), width(), desk.height(), height()); // store default values + TQSize size( config->readNumEntry( TQString::fromLatin1("Width %1").arg(desk.width()), 0 ), + config->readNumEntry( TQString::fromLatin1("Height %1").arg(desk.height()), 0 ) ); + if (size.isEmpty()) { + // try the KDE 2.0 way + size = TQSize( config->readNumEntry( TQString::fromLatin1("Width"), 0 ), + config->readNumEntry( TQString::fromLatin1("Height"), 0 ) ); + if (!size.isEmpty()) { + // make sure the other resolutions don't get old settings + config->writeEntry( TQString::fromLatin1("Width"), 0 ); + config->writeEntry( TQString::fromLatin1("Height"), 0 ); + } + } + if ( !size.isEmpty() ) { +#ifdef Q_WS_X11 + int state = ( size.width() > desk.width() ? NET::MaxHoriz : 0 ) + | ( size.height() > desk.height() ? NET::MaxVert : 0 ); + if(( state & NET::Max ) == NET::Max ) + ; // no resize + else if(( state & NET::MaxHoriz ) == NET::MaxHoriz ) + resize( width(), size.height()); + else if(( state & NET::MaxVert ) == NET::MaxVert ) + resize( size.width(), height()); + else + resize( size ); + // TQWidget::showMaximized() is both insufficient and broken + KWin::setState( winId(), state ); +#else + if (size.width() > desk.width() || size.height() > desk.height()) + setWindowState( WindowMaximized ); + else + resize( size ); +#endif + } + } +} + +bool TDEMainWindow::initialGeometrySet() const +{ + return d->care_about_geometry; +} + +void TDEMainWindow::ignoreInitialGeometry() +{ + d->care_about_geometry = false; +} + +void TDEMainWindow::setSettingsDirty() +{ + //kdDebug(200) << "TDEMainWindow::setSettingsDirty" << endl; + d->settingsDirty = true; + if ( d->autoSaveSettings ) + { + // Use a timer to save "immediately" user-wise, but not too immediately + // (to compress calls and save only once, in case of multiple changes) + if ( !d->settingsTimer ) + { + d->settingsTimer = new TQTimer( this ); + connect( d->settingsTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( saveAutoSaveSettings() ) ); + } + d->settingsTimer->start( 500, true ); + } +} + +bool TDEMainWindow::settingsDirty() const +{ + return d->settingsDirty; +} + +TQString TDEMainWindow::settingsGroup() const +{ + return d->autoSaveGroup; +} + +void TDEMainWindow::setAutoSaveSettings( const TQString & groupName, bool saveWindowSize ) +{ + d->autoSaveSettings = true; + d->autoSaveGroup = groupName; + d->autoSaveWindowSize = saveWindowSize; + // Get notified when the user moves a toolbar around + disconnect( this, TQT_SIGNAL( dockWindowPositionChanged( TQDockWindow * ) ), + this, TQT_SLOT( setSettingsDirty() ) ); + connect( this, TQT_SIGNAL( dockWindowPositionChanged( TQDockWindow * ) ), + this, TQT_SLOT( setSettingsDirty() ) ); + + // Now read the previously saved settings + applyMainWindowSettings( TDEGlobal::config(), groupName ); +} + +void TDEMainWindow::resetAutoSaveSettings() +{ + d->autoSaveSettings = false; + if ( d->settingsTimer ) + d->settingsTimer->stop(); +} + +bool TDEMainWindow::autoSaveSettings() const +{ + return d->autoSaveSettings; +} + +TQString TDEMainWindow::autoSaveGroup() const +{ + return d->autoSaveGroup; +} + +void TDEMainWindow::saveAutoSaveSettings() +{ + Q_ASSERT( d->autoSaveSettings ); + //kdDebug(200) << "TDEMainWindow::saveAutoSaveSettings -> saving settings" << endl; + saveMainWindowSettings( TDEGlobal::config(), d->autoSaveGroup ); + TDEGlobal::config()->sync(); + d->settingsDirty = false; + if ( d->settingsTimer ) + d->settingsTimer->stop(); +} + +void TDEMainWindow::resizeEvent( TQResizeEvent * ) +{ + if ( d->autoSaveWindowSize ) + setSettingsDirty(); +} + +bool TDEMainWindow::hasMenuBar() +{ + return (internalMenuBar()); +} + +KMenuBar *TDEMainWindow::menuBar() +{ + KMenuBar * mb = internalMenuBar(); + if ( !mb ) { + mb = new KMenuBar( this ); + // trigger a re-layout and trigger a call to the private + // setMenuBar method. + TQMainWindow::menuBar(); + } + return mb; +} + +KStatusBar *TDEMainWindow::statusBar() +{ + KStatusBar * sb = internalStatusBar(); + if ( !sb ) { + sb = new KStatusBar( this ); + // trigger a re-layout and trigger a call to the private + // setStatusBar method. + TQMainWindow::statusBar(); + } + return sb; +} + +void TDEMainWindow::shuttingDown() +{ + // Needed for Qt <= 3.0.3 at least to prevent reentrancy + // when queryExit() shows a dialog. Check before removing! + static bool reentrancy_protection = false; + if (!reentrancy_protection) + { + reentrancy_protection = true; + // call the virtual queryExit + queryExit(); + reentrancy_protection = false; + } + +} + +KMenuBar *TDEMainWindow::internalMenuBar() +{ + TQObjectList *l = queryList( "KMenuBar", 0, false, false ); + if ( !l || !l->first() ) { + delete l; + return 0; + } + + KMenuBar *m = (KMenuBar*)l->first(); + delete l; + return m; +} + +KStatusBar *TDEMainWindow::internalStatusBar() +{ + TQObjectList *l = queryList( "KStatusBar", 0, false, false ); + if ( !l || !l->first() ) { + delete l; + return 0; + } + + KStatusBar *s = (KStatusBar*)l->first(); + delete l; + return s; +} + +void TDEMainWindow::childEvent( TQChildEvent* e) +{ + TQMainWindow::childEvent( e ); +} + +TDEToolBar *TDEMainWindow::toolBar( const char * name ) +{ + if (!name) + name = "mainToolBar"; + TDEToolBar *tb = (TDEToolBar*)child( name, "TDEToolBar" ); + if ( tb ) + return tb; + bool honor_mode = (!strcmp(name, "mainToolBar")); + + if ( builderClient() ) + return new TDEToolBar(this, name, honor_mode); // XMLGUI constructor + else + return new TDEToolBar(this, DockTop, false, name, honor_mode ); // non-XMLGUI +} + +TQPtrListIterator TDEMainWindow::toolBarIterator() +{ + toolbarList.clear(); + TQPtrList lst; + for ( int i = (int)TQMainWindow::DockUnmanaged; i <= (int)DockMinimized; ++i ) { + lst = toolBars( (ToolBarDock)i ); + for ( TQToolBar *tb = lst.first(); tb; tb = lst.next() ) { + if ( !tb->inherits( "TDEToolBar" ) ) + continue; + toolbarList.append( (TDEToolBar*)tb ); + } + } + return TQPtrListIterator( toolbarList ); +} + +TDEAccel * TDEMainWindow::accel() +{ + if ( !d->kaccel ) + d->kaccel = new TDEAccel( this, "kmw-kaccel" ); + return d->kaccel; +} + +void TDEMainWindow::paintEvent( TQPaintEvent * pe ) +{ + TQMainWindow::paintEvent(pe); //Upcall to handle SH_MainWindow_SpaceBelowMenuBar rendering +} + +TQSize TDEMainWindow::sizeForCentralWidgetSize(TQSize size) +{ + TDEToolBar *tb = (TDEToolBar*)child( "mainToolBar", "TDEToolBar" ); + if (tb && !tb->isHidden()) { + switch( tb->barPos() ) + { + case TDEToolBar::Top: + case TDEToolBar::Bottom: + size += TQSize(0, tb->sizeHint().height()); + break; + + case TDEToolBar::Left: + case TDEToolBar::Right: + size += TQSize(toolBar()->sizeHint().width(), 0); + break; + + case TDEToolBar::Flat: + size += TQSize(0, 3+kapp->style().pixelMetric( TQStyle::PM_DockWindowHandleExtent )); + break; + + default: + break; + } + } + KMenuBar *mb = internalMenuBar(); + if (mb && !mb->isHidden()) { + size += TQSize(0,mb->heightForWidth(size.width())); + if (style().styleHint(TQStyle::SH_MainWindow_SpaceBelowMenuBar, this)) + size += TQSize( 0, dockWindowsMovable() ? 1 : 2); + } + TQStatusBar *sb = internalStatusBar(); + if( sb && !sb->isHidden() ) + size += TQSize(0, sb->sizeHint().height()); + + return size; +} + +#if KDE_IS_VERSION( 3, 9, 0 ) +#ifdef __GNUC__ +#warning Remove, should be in Qt +#endif +#endif +void TDEMainWindow::setIcon( const TQPixmap& p ) +{ + TQMainWindow::setIcon( p ); +#ifdef Q_WS_X11 + // Qt3 doesn't support _NET_WM_ICON, but TDEApplication::setTopWidget(), which + // is used by TDEMainWindow, sets it + KWin::setIcons( winId(), p, TQPixmap()); +#endif +} + +TQPtrList* TDEMainWindow::getMemberList() { return memberList; } + +// why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI; +// DF: because they compile KDE much faster :) +void TDEMainWindow::finalizeGUI( KXMLGUIClient *client ) +{ KXMLGUIBuilder::finalizeGUI( client ); } + +void TDEMainWindow::virtual_hook( int id, void* data ) +{ KXMLGUIBuilder::virtual_hook( id, data ); + KXMLGUIClient::virtual_hook( id, data ); } + + + +#include "kmainwindow.moc" + diff --git a/tdeui/tdemainwindow.h b/tdeui/tdemainwindow.h new file mode 100644 index 000000000..9ad7dedc6 --- /dev/null +++ b/tdeui/tdemainwindow.h @@ -0,0 +1,1076 @@ +/* + This file is part of the KDE libraries + + 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 KMAINWINDOW_H +#define KMAINWINDOW_H + +#include "kxmlguifactory.h" +#include "kxmlguiclient.h" +#include "kxmlguibuilder.h" +#include +#include +#include + +class TDEPopupMenu; +class KXMLGUIFactory; +class TDEConfig; +class KHelpMenu; +class KStatusBar; +class TQStatusBar; +class KMenuBar; +class KMWSessionManaged; +class TDEMainWindowPrivate; +class TDEAccel; +class TDEToolBarMenuAction; +class DCOPObject; + +#define KDE_DEFAULT_WINDOWFLAGS WType_TopLevel | WDestructiveClose + + +/** + * @short %KDE top level main window + * + * Top level widget that provides toolbars, a status line and a frame. + * + * It should be used as a top level (parent-less) widget. + * It manages the geometry for all its children, including your + * main widget. + * + * Normally, you will inherit from TDEMainWindow, + * then construct (or use some existing) widget as + * your main view. You can set only one main view. + * + * You can add as many toolbars as you like. There can be only one menubar + * and only one statusbar. + * + * The toolbars, menubar, and statusbar can be created by the + * TDEMainWindow and - unlike the old TDEMainWindow - may, but do not + * have to, be deleted by you. TDEMainWindow will handle that internally. + * + * Height and width can be operated independently from each other. Simply + * define the minimum/maximum height/width of your main widget and + * TDEMainWindow will take this into account. For fixed size windows set + * your main widget to a fixed size. + * + * Fixed aspect ratios (heightForWidth()) and fixed width widgets are + * not supported. +* + * TDEMainWindow will set icon, mini icon and caption, which it gets + * from TDEApplication. It provides full session management, and + * will save its position, geometry and positions of toolbars and + * menubar on logout. If you want to save additional data, reimplement + * saveProperties() and (to read them again on next login) + * readProperties(). To save special data about your data, reimplement + * saveGlobalProperties(). To warn user that application or + * windows have unsaved data on close or logout, reimplement + * queryClose() and/or queryExit(). + * + * There are also kRestoreMainWindows convenience functions which + * can restore all your windows on next login. + * + * Note that a TDEMainWindow per-default is created with the + * WDestructiveClose flag, i.e. it is automatically destroyed when the + * window is closed. If you do not want this behavior, specify 0 as + * widget flag in the constructor. + * + * @see TDEApplication + * @author Reginald Stadlbauer (reggie@kde.org) Stephan Kulow (coolo@kde.org), Matthias Ettrich (ettrich@kde.org), Chris Schlaeger (cs@kde.org), Sven Radej (radej@kde.org). Maintained by Sven Radej (radej@kde.org) + + */ + +class TDEUI_EXPORT TDEMainWindow : public TQMainWindow, public KXMLGUIBuilder, virtual public KXMLGUIClient +{ + friend class KMWSessionManaged; + Q_OBJECT + +public: + /** + * Construct a main window. + * + * @param parent The widget parent. This is usually 0 but it may also be the window + * group leader. In that case, the TDEMainWindow becomes sort of a + * secondary window. + * + * @param name The object name. For session management and window management to work + * properly, all main windows in the application should have a + * different name. When passing 0 (the default), TDEMainWindow will create + * a unique name, but it's recommended to explicitly pass a window name that will + * also describe the type of the window. If there can be several windows of the same + * type, append '#' (hash) to the name, and TDEMainWindow will append numbers to make + * the names unique. For example, for a mail client which has one main window showing + * the mails and folders, and which can also have one or more windows for composing + * mails, the name for the folders window should be e.g. "mainwindow" and + * for the composer windows "composer#". + * + * @param f Specify the widget flags. The default is + * WType_TopLevel and WDestructiveClose. TopLevel indicates that a + * main window is a toplevel window, regardless of whether it has a + * parent or not. DestructiveClose indicates that a main window is + * automatically destroyed when its window is closed. Pass 0 if + * you do not want this behavior. + * + * @see http://doc.trolltech.com/3.2/tqt.html#WidgetFlags-enum + * + * TDEMainWindows must be created on the heap with 'new', like: + * \code + * TDEMainWindow *kmw = new TDEMainWindow (...); + * \endcode + **/ +#ifdef qdoc + TDEMainWindow( TQWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose ); +#else + TDEMainWindow( TQWidget* parent = 0, const char *name = 0, WFlags f = (WFlags)(WType_TopLevel | WDestructiveClose) ); +#endif + + /** + * Flags that can be passed in an argument to the constructor to + * change the behavior. + * + * NoDCOPObject tells TDEMainWindow not to create a TDEMainWindowInterface. + * This can be useful in particular for inherited classes, which + * might want to create more specific dcop interfaces. It's a good + * idea to use TDEMainWindowInterface as the base class for such interfaces + * though (to provide the standard mainwindow functionality via DCOP). + */ + enum CreationFlags + { + NoDCOPObject = 1 + }; + + /** + * Overloaded constructor which allows passing some TDEMainWindow::CreationFlags. + * + * @since 3.2 + */ +#ifdef qdoc + TDEMainWindow( int cflags, TQWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose ); +#else + TDEMainWindow( int cflags, TQWidget* parent = 0, const char *name = 0, WFlags f = (WFlags)(WType_TopLevel | WDestructiveClose) ); +#endif + + /** + * \brief Destructor. + * + * Will also destroy the toolbars, and menubar if + * needed. + */ + virtual ~TDEMainWindow(); + + /** + * Retrieve the standard help menu. + * + * It contains entires for the + * help system (activated by F1), an optional "What's This?" entry + * (activated by Shift F1), an application specific dialog box, + * and an "About KDE" dialog box. + * + * Example (adding a standard help menu to your application): + * \code + * TDEPopupMenu *help = helpMenu( ); + * menuBar()->insertItem( i18n("&Help"), help ); + * \endcode + * + * @param aboutAppText The string that is used in the application + * specific dialog box. If you leave this string empty the + * information in the global TDEAboutData of the + * application will be used to make a standard dialog box. + * + * @param showWhatsThis Set this to false if you do not want to include + * the "What's This" menu entry. + * + * @return A standard help menu. + */ + TDEPopupMenu* helpMenu( const TQString &aboutAppText = TQString::null, + bool showWhatsThis = true ); + + /** + * Returns the help menu. Creates a standard help menu if none exists yet. + * + * It contains entries for the + * help system (activated by F1), an optional "What's This?" entry + * (activated by Shift F1), an application specific dialog box, + * and an "About KDE" dialog box. You must create the application + * specific dialog box yourself. When the "About application" + * menu entry is activated, a signal will trigger the + * showAboutApplication slot. See showAboutApplication for more + * information. + * + * Example (adding a help menu to your application): + * \code + * menuBar()->insertItem( i18n("&Help"), customHelpMenu() ); + * \endcode + * + * @param showWhatsThis Set this to @p false if you do not want to include + * the "What's This" menu entry. + * + * @return A standard help menu. + */ + TDEPopupMenu* customHelpMenu( bool showWhatsThis = true ); + + /** + * Session Management + * + * Try to restore the toplevel widget as defined by the number (1..X). + * + * If the session did not contain so high a number, the configuration + * is not changed and @p false returned. + * + * That means clients could simply do the following: + * \code + * if (kapp->isRestored()){ + * int n = 1; + * while (TDEMainWindow::canBeRestored(n)){ + * (new childMW)->restore(n); + * n++; + * } + * } else { + * // create default application as usual + * } + * \endcode + * Note that TQWidget::show() is called implicitly in restore. + * + * With this you can easily restore all toplevel windows of your + * application. + * + * If your application uses different kinds of toplevel + * windows, then you can use TDEMainWindow::classNameOfToplevel(n) + * to determine the exact type before calling the childMW + * constructor in the example from above. + * + * If your client has only one kind of toplevel widgets (which + * should be pretty usual) then you should use the RESTORE-macro + * for backwards compatibility with 3.1 and 3.0 branches: + * + * \code + * if (kapp->isRestored()) + * RESTORE(childMW) + * else { + * // create default application as usual + * } + * \endcode + * + * The macro expands to the term above but is easier to use and + * less code to write. + * + * For new code or if you have more than one kind of toplevel + * widget (each derived from TDEMainWindow, of course), you can + * use the templated kRestoreMainWindows global functions: + * + * \code + * if (kapp->isRestored()) + * kRestoreMainWindows< childMW1, childMW2, childMW3 >(); + * else { + * // create default application as usual + * } + * \endcode + * + * Currently, these functions are provided for up to three + * template arguments. If you need more, tell us. To help you in + * deciding whether or not you can use kRestoreMainWindows, a + * define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS is provided. + * + * @see restore() + * @see classNameOfToplevel() + * + **/ + static bool canBeRestored( int number ); + + /** + * Returns the className() of the @p number of the toplevel window which + * should be restored. + * + * This is only useful if your application uses + * different kinds of toplevel windows. + */ + // KDE 4 return TQCString - TQObject::className() returns const char* + static const TQString classNameOfToplevel( int number ); + + /** + * Reimplementation of TQMainWindow::show() + */ + // KDE4 remove this method if this has been fixed in Qt + virtual void show(); + + /** + * Reimplementation of TQMainWindow::hide() + */ + // KDE4 remove this method if this has been fixed in Qt + virtual void hide(); + + /** + * Restore the session specified by @p number. + * + * Returns @p false if this + * fails, otherwise returns @p true and shows the window. + * You should call canBeRestored() first. + * If @p show is true (default), this widget will be shown automatically. + */ + bool restore( int number, bool show = true ); + + virtual KXMLGUIFactory *guiFactory(); + + /** + * Create a GUI given a local XML file. + * + * If @p xmlfile is NULL, + * then it will try to construct a local XML filename like + * appnameui.rc where 'appname' is your app's name. If that file + * does not exist, then the XML UI code will only use the global + * (standard) XML file for the layout purposes. + * + * Note that when passing true for the conserveMemory argument subsequent + * calls to guiFactory()->addClient/removeClient may not work as expected. + * Also retrieving references to containers like popup menus or toolbars using + * the container method will not work. + * + * @param xmlfile The local xmlfile (relative or absolute) + * @param _conserveMemory Specify whether createGUI() should call + * KXMLGUIClient::conserveMemory() to free all memory + * allocated by the TQDomDocument and by the KXMLGUIFactory. + */ + void createGUI( const TQString &xmlfile = TQString::null, bool _conserveMemory = true ); + + /** + * Enables the build of a standard help menu when calling createGUI(). + * + * The default behavior is to build one, you must call this function + * to disable it + */ + void setHelpMenuEnabled(bool showHelpMenu = true); + + /** + * Return @p true when the help menu is enabled + */ + bool isHelpMenuEnabled(); + + + /** + * Returns true, if there is a menubar + * @since 3.1 + */ + bool hasMenuBar(); + + /** + * Returns a pointer to the menu bar. + * + * If there is no menu bar yet one will be created. + **/ + KMenuBar *menuBar(); + + /** + * Returns a pointer to the status bar. + * + * If there is no status bar yet, one will be created. + * + * Note that tooltips for kactions in actionCollection() are not + * automatically connected to this statusBar. + * See the TDEActionCollection documentation for more details. + * + * @see TDEActionCollection + */ + KStatusBar *statusBar(); + + /** + * List of members of TDEMainWindow class. + */ + static TQPtrList* memberList; + + //KDE4: replace with memberList() and make memberList member private + /** + * List of members of TDEMainWindow class. + * @since 3.4 + */ + static TQPtrList* getMemberList(); + + /** + * Returns a pointer to the toolbar with the specified name. + * This refers to toolbars created dynamically from the XML UI + * framework. If the toolbar does not exist one will be created. + * + * @param name The internal name of the toolbar. If no name is + * specified "mainToolBar" is assumed. + * + * @return A pointer to the toolbar + **/ + TDEToolBar *toolBar( const char *name=0 ); + + /** + * @return An iterator over the list of all toolbars for this window. + */ + TQPtrListIterator toolBarIterator(); + + /** + * @return A TDEAccel instance bound to this mainwindow. Used automatically + * by TDEAction to make keybindings work in all cases. + */ + TDEAccel *accel(); + + void setFrameBorderWidth( int ) {} + + /** + * Call this to enable "auto-save" of toolbar/menubar/statusbar settings + * (and optionally window size). + * If the *bars were moved around/shown/hidden when the window is closed, + * saveMainWindowSettings( TDEGlobal::config(), groupName ) will be called. + * + * @param groupName a name that identifies this "type of window". + * You can have several types of window in the same application. + * + * @param saveWindowSize set it to true to include the window size + * when saving. + * + * Typically, you will call setAutoSaveSettings() in your + * TDEMainWindow-inherited class constructor, and it will take care + * of restoring and saving automatically. Make sure you call this + * _after all_ your *bars have been created. + * + * To make sure that TDEMainWindow propertly obtains the default + * size of the window you should do the following: + * - Remove hard coded resize() calls in the constructor or main, they + * should be removed in favor of letting the automatic resizing + * determine the default window size. Hard coded window sizes will + * be wrong for users that have big fonts, use different styles, + * long/small translations, large toolbars, and other factors. + * - Put the setAutoSaveSettings ( or setupGUI() ) call after all widgets + * have been created and placed inside the main window (i.e. for 99% of + * apps setCentralWidget()) + * - Widgets that inherit from TQWidget (like game boards) should overload + * "virtual TQSize sizeHint() const;" to specify a default size rather + * than letting TQWidget::adjust use the default size of 0x0. + */ + void setAutoSaveSettings( const TQString & groupName = TQString::fromLatin1("MainWindow"), + bool saveWindowSize = true ); + + /** + * Disable the auto-save-settings feature. + * You don't normally need to call this, ever. + */ + void resetAutoSaveSettings(); + + /** + * @return the current autosave setting, i.e. true if setAutoSaveSettings() was called, + * false by default or if resetAutoSaveSettings() was called. + * @since 3.1 + */ + bool autoSaveSettings() const; + + /** + * @return the group used for setting-autosaving. + * Only meaningful if setAutoSaveSettings() was called. + * This can be useful for forcing a save or an apply, e.g. before and after + * using KEditToolbar. + * @since 3.1 + */ + TQString autoSaveGroup() const; + + /** + * Read settings for statusbar, menubar and toolbar from their respective + * groups in the config file and apply them. + * + * @param config Config file to read the settings from. + * @param groupName Group name to use. If not specified, the last used + * group name is used. + * @param force if set, even default settings are re-applied + */ + void applyMainWindowSettings(TDEConfig *config, const TQString &groupName, bool force); + // KDE4 merge with force=false + void applyMainWindowSettings(TDEConfig *config, const TQString &groupName = TQString::null); + + /** + * Save settings for statusbar, menubar and toolbar to their respective + * groups in the config file @p config. + * + * @param config Config file to save the settings to. + * @param groupName Group name to use. If not specified, the last used + * group name is used + */ + void saveMainWindowSettings(TDEConfig *config, const TQString &groupName = TQString::null); + + /** + * Sets whether TDEMainWindow should provide a menu that allows showing/hiding + * the available toolbars ( using TDEToggleToolBarAction ) . In case there + * is only one toolbar configured a simple 'Show \' menu item + * is shown. + * + * The menu / menu item is implemented using xmlgui. It will be inserted in your + * menu structure in the 'Settings' menu. + * + * If your application uses a non-standard xmlgui resource file then you can + * specify the exact position of the menu / menu item by adding a + * <Merge name="StandardToolBarMenuHandler" /> + * line to the settings menu section of your resource file ( usually appname.rc ). + * + * Note that you should enable this feature before calling createGUI() ( or similar ) . + * You enable/disable it anytime if you pass false to the conserveMemory argument of createGUI. + * @since 3.1 + */ + void setStandardToolBarMenuEnabled( bool enable ); + /// @since 3.1 + bool isStandardToolBarMenuEnabled() const; + + + /** + * Sets whether TDEMainWindow should provide a menu that allows showing/hiding + * of the statusbar ( using TDEToggleStatusBarAction ). + * + * The menu / menu item is implemented using xmlgui. It will be inserted + * in your menu structure in the 'Settings' menu. + * + * Note that you should enable this feature before calling createGUI() + * ( or similar ). + * + * If an application maintains the action on its own (i.e. never calls + * this function) a connection needs to be made to let TDEMainWindow + * know when that status (hidden/shown) of the statusbar has changed. + * For example: + * connect(action, TQT_SIGNAL(activated()), + * kmainwindow, TQT_SLOT(setSettingsDirty())); + * Otherwise the status (hidden/show) of the statusbar might not be saved + * by TDEMainWindow. + * @since 3.2 + */ + void createStandardStatusBarAction(); + + /** + * @see setupGUI() + */ + enum StandardWindowOptions + { + /** + * adds action to show/hide the toolbar(s) and adds + * action to configure the toolbar(s). + * @see setStandardToolBarMenuEnabled + */ + ToolBar = 1, + + /** + * adds action to show the key configure action. + */ + Keys = 2, + + /** + * adds action to show/hide the statusbar if the + * statusbar exists. See createStandardStatusBarAction + */ + StatusBar = 4, + + /** + * auto-saves (and loads) the toolbar/menubar/statusbar settings and + * window size using the default name. See setAutoSaveSettings + * + * Typically you want to let the default window size be determined by + * the widgets size hints. Make sure that setupGUI() is called after + * all the widgets are created ( including setCentralWidget ) so the + * default size's will be correct. See setAutoSaveSettings for + * more information on this topic. + */ + Save = 8, + + /** + * calls createGUI() once ToolBar, Keys and Statusbar have been + * taken care of. See createGUI + */ + Create = 16 + }; + + /** + * Configures the current windows and its actions in the typical KDE + * fashion. The options are all enabled by default but can be turned + * off if desired through the params or if the prereqs don't exists. + * + * Typically this function replaces createGUI(). + * + * @see StandardWindowOptions + * + * @since 3.3 + */ + void setupGUI( int options = ToolBar | Keys | StatusBar | Save | Create, const TQString& xmlfile = TQString::null ); + + /** + * Configures the current windows and its actions in the typical KDE + * fashion. The options are all enabled by default but can be turned + * off if desired through the params or if the prereqs don't exists. + * + * @p defaultSize The default size of the window + * + * Typically this function replaces createGUI(). + * + * @see StandardWindowOptions + * + * @since 3.5 + */ + void setupGUI( TQSize defaultSize, int options = ToolBar | Keys | StatusBar | Save | Create, const TQString& xmlfile = TQString::null ); + + /** + * Returns a pointer to the mainwindows action responsible for the toolbars menu + * @since 3.1 + */ + TDEAction *toolBarMenuAction(); + + /** + * @internal for TDEToolBar + * @since 3.3.1 + */ + void setupToolbarMenuActions(); + + // why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI; + /// @since 3.1 + virtual void finalizeGUI( KXMLGUIClient *client ); + + /** + * @internal + */ + void finalizeGUI( bool force ); + + /** + * @return true if a -geometry argument was given on the command line, + * and this is the first window created (the one on which this option applies) + */ + bool initialGeometrySet() const; + + /** + * @internal + * Used from Konqueror when reusing the main window. + */ + void ignoreInitialGeometry(); + + /** + * @return the size the mainwindow should have so that the central + * widget will be of @p size. + * + * @deprecated You normally don't need this, the recommended way to achieve a + * certain central widget size is as follows: + * @li Override sizeHint() in the central widget so that it + * returns the desired size. + * @li Call updateGeometry() in the central widget whenever the + * desired size changes. This ensures that the new sizeHint() is properly + * propagated to any parent layout. + * @li Now call adjustSize() in the mainwindow to resize the + * mainwindow such that the central widget will become the desired size. + * + */ + // KDE4 to be removed + TQSize sizeForCentralWidgetSize(TQSize size) KDE_DEPRECATED; + + /** + * @internal + */ + // KDE4 remove + virtual void setIcon( const TQPixmap & ); + +public slots: + /** + * Show a standard configure toolbar dialog. + * + * This slot can be connected dirrectly to the action to configure shortcuts. + * This is very simple to do that by adding a single line + * \code + * KStdAction::configureToolbars( guiFactory(), TQT_SLOT( configureToolbars() ), + * actionCollection() ); + * \endcode + * + * @since 3.3 + */ + int configureToolbars(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow + + /** + * Makes a KDE compliant caption. + * + * @param caption Your caption. @em Do @em not include the application name + * in this string. It will be added automatically according to the KDE + * standard. + */ + virtual void setCaption( const TQString &caption ); + /** + * Makes a KDE compliant caption. + * + * @param caption Your caption. @em Do @em not include the application name + * in this string. It will be added automatically according to the KDE + * standard. + * @param modified Specify whether the document is modified. This displays + * an additional sign in the title bar, usually "**". + */ + virtual void setCaption( const TQString &caption, bool modified ); + + /** + * Make a plain caption without any modifications. + * + * @param caption Your caption. This is the string that will be + * displayed in the window title. + */ + virtual void setPlainCaption( const TQString &caption ); + + /** + * Open the help page for the application. + * + * The application name is + * used as a key to determine what to display and the system will attempt + * to open \/index.html. + * + * This method is intended for use by a help button in the toolbar or + * components outside the regular help menu. Use helpMenu() when you + * want to provide access to the help system from the help menu. + * + * Example (adding a help button to the first toolbar): + * + * \code + * KIconLoader &loader = *TDEGlobal::iconLoader(); + * TQPixmap pixmap = loader.loadIcon( "help" ); + * toolBar(0)->insertButton( pixmap, 0, TQT_SIGNAL(clicked()), + * this, TQT_SLOT(appHelpActivated()), true, i18n("Help") ); + * \endcode + * + */ + void appHelpActivated( void ); + + /** + * Apply a state change + * + * Enable and disable actions as defined in the XML rc file + * @since 3.1 + */ + virtual void slotStateChanged(const TQString &newstate); + + /** + * Apply a state change + * + * Enable and disable actions as defined in the XML rc file, + * can "reverse" the state (disable the actions which should be + * enabled, and vice-versa) if specified. + * @since 3.1 + */ + void slotStateChanged(const TQString &newstate, + KXMLGUIClient::ReverseStateChange); // KDE 4.0: remove this + + + /** + * Apply a state change + * + * Enable and disable actions as defined in the XML rc file, + * can "reverse" the state (disable the actions which should be + * enabled, and vice-versa) if specified. + */ +// void slotStateChanged(const TQString &newstate, +// bool reverse); // KDE 4.0: enable this + + /** + * Tell the main window that it should save its settings when being closed. + * This is part of the auto-save-settings feature. + * For everything related to toolbars this happens automatically, + * but you have to call setSettingsDirty() in the slot that toggles + * the visibility of the statusbar. + */ + void setSettingsDirty(); + +protected: + void paintEvent( TQPaintEvent* e ); + void childEvent( TQChildEvent* e); + void resizeEvent( TQResizeEvent* e); + /** + * Reimplemented to call the queryClose() and queryExit() handlers. + * + * We recommend that you reimplement the handlers rather than closeEvent(). + * If you do it anyway, ensure to call the base implementation to keep + * queryExit() running. + */ + virtual void closeEvent ( TQCloseEvent *); + + // KDE4 This seems to be flawed to me. Either the app has only one + // mainwindow, so queryClose() is enough, or if it can have more of them, + // then the windows should take care of themselves, and queryExit() + // would be useful only for the annoying 'really quit' dialog, which + // also doesn't make sense in apps with multiple mainwindows. + // And saving configuration in something called queryExit()? IMHO + // one can e.g. use TDEApplication::shutDown(), which if nothing else + // has at least better fitting name. + // See also TDEApplication::sessionSaving(). + // This stuff should get changed somehow, so that it at least doesn't + // mess with session management. + /** + Called before the very last window is closed, either by the + user or indirectly by the session manager. + + It is not recommended to do any user interaction in this + function other than indicating severe errors. Better ask the + user on queryClose() (see below). + + A typical usage of queryExit() is to write configuration data back. + Note that the application may continue to run after queryExit() + (the user may have canceled a shutdown), so you should not do any cleanups + here. The purpose of queryExit() is purely to prepare the application + (with possible user interaction) so it can safely be closed later (without + user interaction). + + If you need to do serious things on exit (like shutting a + dial-up connection down), connect to the signal + TDEApplication::shutDown(). + + Default implementation returns @p true. Returning @p false will + cancel the exiting. In the latter case, the last window will + remain visible. If TDEApplication::sessionSaving() is true, refusing + the exit will also cancel KDE logout. + + @see queryClose() + @see TDEApplication::sessionSaving() + */ + virtual bool queryExit(); + + /** + Called before the window is closed, either by the user or indirectly by + the session manager. + + The purpose of this function is to prepare the window in a way that it is + safe to close it, i.e. without the user losing some data. + + Default implementation returns true. Returning @p false will cancel + the closing, and, if TDEApplication::sessionSaving() is true, it will also + cancel KDE logout. + + Reimplement this function to prevent the user from losing data. + Example: + \code + switch ( KMessageBox::warningYesNoCancel( this, + i18n("Save changes to document foo?")) ) { + case KMessageBox::Yes : + // save document here. If saving fails, return false; + return true; + case KMessageBox::No : + return true; + default: // cancel + return false; + \endcode + + Note that you should probably @em not actually close the document from + within this method, as it may be called by the session manager before the + session is saved. If the document is closed before the session save occurs, + its location might not be properly saved. In addition, the session shutdown + may be canceled, in which case the document should remain open. + + @see queryExit() + @see TDEApplication::sessionSaving() + */ + virtual bool queryClose(); + + /** + * Save your instance-specific properties. The function is + * invoked when the session manager requests your application + * to save its state. + * + * You @em must @em not change the group of the @p tdeconfig object, since + * TDEMainWindow uses one group for each window. Please + * reimplement these function in childclasses. + * + * Note: No user interaction is allowed + * in this function! + * + */ + virtual void saveProperties( TDEConfig* ) {} + + /** + * Read your instance-specific properties. + */ + virtual void readProperties( TDEConfig* ) {} + + /** + * Save your application-wide properties. The function is + * invoked when the session manager requests your application + * to save its state. + * + * This function is similar to saveProperties() but is only called for + * the very first main window, regardless how many main window are open. + + * Override it if you need to save other data about your documents on + * session end. sessionConfig is a config to which that data should be + * saved. Normally, you don't need this function. But if you want to save + * data about your documents that are not in opened windows you might need + * it. + * + * Default implementation does nothing. + */ + virtual void saveGlobalProperties( TDEConfig* sessionConfig ); + + /** + * The counterpart of saveGlobalProperties(). + * + * Read the application-specific properties in again. + */ + virtual void readGlobalProperties( TDEConfig* sessionConfig ); + void savePropertiesInternal( TDEConfig*, int ); + bool readPropertiesInternal( TDEConfig*, int ); + + /** + * For inherited classes + */ + bool settingsDirty() const; + /** + * For inherited classes + */ + TQString settingsGroup() const; + /** + * For inherited classes + * Note that the group must be set before calling + */ + void saveWindowSize( TDEConfig * config ) const; + /** + * For inherited classes + * Note that the group must be set before calling, and that + * a -geometry on the command line has priority. + */ + void restoreWindowSize( TDEConfig * config ); + + /// parse the geometry from the geometry command line argument + void parseGeometry(bool parsewidth); + +protected slots: + /** + * Rebuilds the GUI after KEditToolbar changed the toolbar layout. + * @see configureToolbars() + */ + void saveNewToolbarConfig(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow + + /** + * This slot does nothing. + * + * It must be reimplemented if you want + * to use a custom About Application dialog box. This slot is + * connected to the About Application entry in the menu returned + * by customHelpMenu. + * + * Example: + * \code + * + * void MyMainLevel::setupInterface() + * { + * .. + * menuBar()->insertItem( i18n("&Help"), customHelpMenu() ); + * .. + * } + * + * void MyMainLevel::showAboutApplication() + * { + * + * } + * \endcode + */ + virtual void showAboutApplication(); + + /** + * This slot should only be called in case you reimplement closeEvent() and + * if you are using the "auto-save" feature. In all other cases, + * setSettingsDirty() should be called instead to benefit from the delayed + * saving. + * + * @see setAutoSaveSettings + * @see setSettingsDirty + * + * @since 3.2 + * + * Example: + * \code + * + * void MyMainWindow::closeEvent( TQCloseEvent *e ) + * { + * // Save settings if auto-save is enabled, and settings have changed + * if ( settingsDirty() && autoSaveSettings() ) + * saveAutoSaveSettings(); + * .. + * } + * \endcode + */ + void saveAutoSaveSettings(); + +private slots: + /** + * Called when the app is shutting down. + */ + void shuttingDown(); + +private: + KMenuBar *internalMenuBar(); + KStatusBar *internalStatusBar(); + KHelpMenu *mHelpMenu, *helpMenu2; + KXMLGUIFactory *factory_; + TQPtrList toolbarList; +protected: + virtual void virtual_hook( int id, void* data ); +private: + TDEMainWindowPrivate *d; + void initTDEMainWindow(const char *name, int cflags); +}; + +#define RESTORE(type) { int n = 1;\ + while (TDEMainWindow::canBeRestored(n)){\ + (new type)->restore(n);\ + n++;}} + +#define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3 + +/** + * These global convenience functions (that come with a varying + * number of template arguments) are a replacement for the RESTORE + * macro provided in earlier versions of KDE. The old RESTORE macro + * is still provided for backwards compatibility. See + * TDEMainWindow documentation for more. + * + * \since KDE 3.2 + * + **/ +template +inline void kRestoreMainWindows() { + for ( int n = 1 ; TDEMainWindow::canBeRestored( n ) ; ++n ) { + const TQString className = TDEMainWindow::classNameOfToplevel( n ); + if ( className == TQString::fromLatin1( T::staticMetaObject()->className() ) ) + (new T)->restore( n ); + } +} + +template +inline void kRestoreMainWindows() { + const char * classNames[2]; + classNames[0] = T0::staticMetaObject()->className(); + classNames[1] = T1::staticMetaObject()->className(); + for ( int n = 1 ; TDEMainWindow::canBeRestored( n ) ; ++n ) { + const TQString className = TDEMainWindow::classNameOfToplevel( n ); + if ( className == TQString::fromLatin1( classNames[0] ) ) + (new T0)->restore( n ); + else if ( className == TQString::fromLatin1( classNames[1] ) ) + (new T1)->restore( n ); + } +} + +template +inline void kRestoreMainWindows() { + const char * classNames[3]; + classNames[0] = T0::staticMetaObject()->className(); + classNames[1] = T1::staticMetaObject()->className(); + classNames[2] = T2::staticMetaObject()->className(); + for ( int n = 1 ; TDEMainWindow::canBeRestored( n ) ; ++n ) { + const TQString className = TDEMainWindow::classNameOfToplevel( n ); + if ( className == TQString::fromLatin1( classNames[0] ) ) + (new T0)->restore( n ); + else if ( className == TQString::fromLatin1( classNames[1] ) ) + (new T1)->restore( n ); + else if ( className == TQString::fromLatin1( classNames[2] ) ) + (new T2)->restore( n ); + } +} + +#endif + diff --git a/tdeui/tdemainwindowiface.cpp b/tdeui/tdemainwindowiface.cpp new file mode 100644 index 000000000..ec8ee3630 --- /dev/null +++ b/tdeui/tdemainwindowiface.cpp @@ -0,0 +1,194 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Ian Reinhart Geiser + + This program is free software; you can redistribute it and/or + modify it under the terms of the Lesser GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program 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 + General Public License for more details. + + You should have received a copy of the Lesser GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kmainwindowiface.h" + +#include +#include +#include +#include +#include +#include +#include + + +TDEMainWindowInterface::TDEMainWindowInterface(TDEMainWindow * mainWindow) + : DCOPObject( mainWindow->name()) +{ + m_MainWindow = mainWindow; + m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); + m_dcopPropertyProxy = new KDCOPPropertyProxy(TQT_TQOBJECT(m_MainWindow)); +} + +TDEMainWindowInterface::~TDEMainWindowInterface() +{ + delete m_dcopActionProxy; + delete m_dcopPropertyProxy; +} + +QCStringList TDEMainWindowInterface::actions() +{ + delete m_dcopActionProxy; + m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); + QCStringList tmp_actions; + TQValueList lst = m_dcopActionProxy->actions(); + TQValueList::ConstIterator it = lst.begin(); + TQValueList::ConstIterator end = lst.end(); + for (; it != end; ++it ) + if ((*it)->isPlugged()) + tmp_actions.append( (TQCString)(*it)->name() ); + return tmp_actions; +} +bool TDEMainWindowInterface::activateAction( TQCString action) +{ + delete m_dcopActionProxy; + m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); + TDEAction *tmp_Action = m_dcopActionProxy->action(action); + if (tmp_Action) + { + tmp_Action->activate(); + return true; + } + else + return false; +} +bool TDEMainWindowInterface::disableAction( TQCString action) +{ + delete m_dcopActionProxy; + m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); + TDEAction *tmp_Action = m_dcopActionProxy->action(action); + if (tmp_Action) + { + tmp_Action->setEnabled(false); + return true; + } + else + return false; +} +bool TDEMainWindowInterface::enableAction( TQCString action) +{ + delete m_dcopActionProxy; + m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); + TDEAction *tmp_Action = m_dcopActionProxy->action(action); + if (tmp_Action) + { + tmp_Action->setEnabled(true); + return true; + } + else + return false; +} +bool TDEMainWindowInterface::actionIsEnabled( TQCString action) +{ + delete m_dcopActionProxy; + m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); + TDEAction *tmp_Action = m_dcopActionProxy->action(action); + if (tmp_Action) + { + return tmp_Action->isEnabled(); + } + else + return false; +} +TQCString TDEMainWindowInterface::actionToolTip( TQCString action) +{ + delete m_dcopActionProxy; + m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); + TDEAction *tmp_Action = m_dcopActionProxy->action(action); + if (tmp_Action) + { + return tmp_Action->toolTip().utf8(); + } + else + return "Error no such object!"; +} + +DCOPRef TDEMainWindowInterface::action( const TQCString &name ) +{ + return DCOPRef( kapp->dcopClient()->appId(), m_dcopActionProxy->actionObjectId( name ) ); +} + +TQMap TDEMainWindowInterface::actionMap() +{ + return m_dcopActionProxy->actionMap(); +} + +int TDEMainWindowInterface::getWinID() +{ + return (int) m_MainWindow->winId(); +} +void TDEMainWindowInterface::grabWindowToClipBoard() +{ + TQClipboard *clipboard = TQApplication::clipboard(); + clipboard->setPixmap(TQPixmap::grabWidget(m_MainWindow)); +} +void TDEMainWindowInterface::hide() +{ + m_MainWindow->hide(); +} +void TDEMainWindowInterface::maximize() +{ + m_MainWindow->showMaximized(); +} +void TDEMainWindowInterface::minimize() +{ + m_MainWindow->showMinimized(); +} +void TDEMainWindowInterface::resize(int newX, int newY) +{ + m_MainWindow->resize(newX, newY); +} +void TDEMainWindowInterface::move(int newX, int newY) +{ + m_MainWindow->move(newX, newY); +} +void TDEMainWindowInterface::setGeometry(int newX, int newY, int newWidth, int newHeight) +{ + m_MainWindow->setGeometry(newX, newY, newWidth, newHeight); +} +void TDEMainWindowInterface::raise() +{ + m_MainWindow->raise(); +} +void TDEMainWindowInterface::lower() +{ + m_MainWindow->lower(); +} +void TDEMainWindowInterface::restore() +{ + m_MainWindow->showNormal(); +} +void TDEMainWindowInterface::close() +{ + m_MainWindow->close(); +} +void TDEMainWindowInterface::show() +{ + m_MainWindow->show(); +} +QCStringList TDEMainWindowInterface::functionsDynamic() +{ + return m_dcopPropertyProxy->functions(); +} +bool TDEMainWindowInterface::processDynamic(const TQCString &fun, const TQByteArray &data, TQCString& replyType, TQByteArray &replyData) +{ + return m_dcopPropertyProxy->processPropertyRequest( fun, data, replyType, replyData); + +} + diff --git a/tdeui/tdemainwindowiface.h b/tdeui/tdemainwindowiface.h new file mode 100644 index 000000000..9ba1c4da9 --- /dev/null +++ b/tdeui/tdemainwindowiface.h @@ -0,0 +1,161 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Ian Reinhart Geiser + + 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. + + This program 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 + General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KWINDOW_INTERFACE_H +#define KWINDOW_INTERFACE_H + +#include +#include +#include +#include + +class KDCOPActionProxy; +class KDCOPPropertyProxy; +class TDEMainWindow; + +/** + * @short DCOP interface to TDEMainWindow. + * + * This is the main interface to the TDEMainWindow. This will provide a consistent + * DCOP interface to all KDE applications that use it. + * + * @author Ian Reinhart Geiser + */ +class TDEUI_EXPORT TDEMainWindowInterface : virtual public DCOPObject +{ +K_DCOP + +public: + /** + Construct a new interface object. + @param mainWindow - The parent TDEMainWindow object + that will provide us with the TDEAction objects. + */ + TDEMainWindowInterface( TDEMainWindow * mainWindow ); + /** + Destructor + Cleans up the dcop action proxy object. + **/ + ~TDEMainWindowInterface(); + + QCStringList functionsDynamic(); + bool processDynamic(const TQCString &fun, const TQByteArray &data, TQCString& replyType, TQByteArray &replyData); + + +k_dcop: + /** + Return a list of actions available to the application's window. + @return A QCStringList containing valid names actions. + */ + QCStringList actions(); + + /** + Activates the requested action. + @param action The name of the action to activate. The names of valid + actions can be found by calling actions(). + @return The success of the operation. + */ + bool activateAction( TQCString action); + + /** + Disables the requested action. + @param action The name of the action to disable. The names of valid + actions can be found by calling actions(). + @return The success of the operation. + */ + bool disableAction( TQCString action); + + /** + Enables the requested action. + @param action The name of the action to enable. The names of valid + actions can be found by calling actions(). + @return The success of the operation. + */ + bool enableAction( TQCString action); + + /** + Returns the status of the requested action. + @param action The name of the action. The names of valid + actions can be found by calling actions(). + @returns The state of the action, true - enabled, false - disabled. + */ + bool actionIsEnabled( TQCString action); + + /** + Returns the tool tip text of the requested action. + @param action The name of the action to activate. The names of valid + actions can be found by calling actions(). + @return A TQCString containing the text of the action's tool tip. + */ + TQCString actionToolTip( TQCString action); + + /** + Returns a dcop reference to the selected TDEAction + @param name The name of the action. The names of valid + actions can be found by calling actions(). + @return A DCOPRef for the kaction. + **/ + DCOPRef action( const TQCString &name ); + + /** + Returns and action map + **/ + TQMap actionMap(); + /** + Returns the ID of the current main window. + This is useful for automated screen captures or other evil + widget fun. + @return A integer value of the main window's ID. + **/ + int getWinID(); + /** + Copies a pixmap representation of the current main window to + the clipboard. + **/ + void grabWindowToClipBoard(); +// bool isHidden(); + void hide(); +// bool isMaximized(); + void maximize(); +// bool isMinimized(); + void minimize(); +// int width(); +// int height(); + void resize(int newWidth, int newHeight); +// int Xpos(); +// int Ypos(); + void move(int newX, int newY); + void setGeometry(int newX, int newY, int newWidth, int newHeight); + void raise(); + void lower(); + void restore(); + void show(); + void close(); + +// QCStringList getQTProperties(); + +private: + TDEMainWindow *m_MainWindow; + KDCOPActionProxy *m_dcopActionProxy; + KDCOPPropertyProxy *m_dcopPropertyProxy; +}; + +#endif + + diff --git a/tdeui/tdepopupmenu.cpp b/tdeui/tdepopupmenu.cpp new file mode 100644 index 000000000..5547d9316 --- /dev/null +++ b/tdeui/tdepopupmenu.cpp @@ -0,0 +1,694 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 Daniel M. Duley + Copyright (C) 2002 Hamish Rodda + + 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. +*/ +#include +#include +#include +#include + +#ifdef USE_QT4 +#undef None +#endif // USE_QT4 + +#include + +#include "kpopupmenu.h" + +#include +#include + +TDEPopupTitle::TDEPopupTitle(TQWidget *parent, const char *name) + : TQWidget(parent, name) +{ + setMinimumSize(16, fontMetrics().height()+8); +} + +TDEPopupTitle::TDEPopupTitle(KPixmapEffect::GradientType /* gradient */, + const TQColor &/* color */, const TQColor &/* textColor */, + TQWidget *parent, const char *name) + : TQWidget(parent, name) +{ + calcSize(); +} + +TDEPopupTitle::TDEPopupTitle(const KPixmap & /* background */, const TQColor &/* color */, + const TQColor &/* textColor */, TQWidget *parent, + const char *name) + : TQWidget(parent, name) +{ + calcSize(); +} + +void TDEPopupTitle::setTitle(const TQString &text, const TQPixmap *icon) +{ + titleStr = text; + if (icon) + miniicon = *icon; + else + miniicon.resize(0, 0); + + calcSize(); +} + +void TDEPopupTitle::setText( const TQString &text ) +{ + titleStr = text; + calcSize(); +} + +void TDEPopupTitle::setIcon( const TQPixmap &pix ) +{ + miniicon = pix; + calcSize(); +} + +void TDEPopupTitle::calcSize() +{ + TQFont f = font(); + f.setBold(true); + int w = miniicon.width()+TQFontMetrics(f).width(titleStr); + int h = QMAX( fontMetrics().height(), miniicon.height() ); + setMinimumSize( w+16, h+8 ); +} + +void TDEPopupTitle::paintEvent(TQPaintEvent *) +{ + TQRect r(rect()); + TQPainter p(this); + kapp->style().tqdrawPrimitive(TQStyle::PE_HeaderSectionMenu, &p, r, palette().active()); + + if (!miniicon.isNull()) + p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon); + + if (!titleStr.isNull()) + { + p.setPen(palette().active().text()); + TQFont f = p.font(); + f.setBold(true); + p.setFont(f); + if(!miniicon.isNull()) + { + p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8), + height(), AlignLeft | AlignVCenter | SingleLine, + titleStr); + } + else + { + p.drawText(0, 0, width(), height(), + AlignCenter | SingleLine, titleStr); + } + } +} + +TQSize TDEPopupTitle::sizeHint() const +{ + return minimumSize(); +} + +class TDEPopupMenu::TDEPopupMenuPrivate +{ +public: + TDEPopupMenuPrivate () + : noMatches(false) + , shortcuts(false) + , autoExec(false) + , lastHitIndex(-1) + , state(Qt::NoButton) + , m_ctxMenu(0) + {} + + ~TDEPopupMenuPrivate () + { + delete m_ctxMenu; + } + + TQString m_lastTitle; + + // variables for keyboard navigation + TQTimer clearTimer; + + bool noMatches : 1; + bool shortcuts : 1; + bool autoExec : 1; + + TQString keySeq; + TQString originalText; + + int lastHitIndex; + TQt::ButtonState state; + + // support for RMB menus on menus + TQPopupMenu* m_ctxMenu; + static bool s_continueCtxMenuShow; + static int s_highlightedItem; + static TDEPopupMenu* s_contextedMenu; +}; + +int TDEPopupMenu::TDEPopupMenuPrivate::s_highlightedItem(-1); +TDEPopupMenu* TDEPopupMenu::TDEPopupMenuPrivate::s_contextedMenu(0); +bool TDEPopupMenu::TDEPopupMenuPrivate::s_continueCtxMenuShow(true); + +TDEPopupMenu::TDEPopupMenu(TQWidget *parent, const char *name) + : TQPopupMenu(parent, name) +{ + d = new TDEPopupMenuPrivate; + resetKeyboardVars(); + connect(&(d->clearTimer), TQT_SIGNAL(timeout()), TQT_SLOT(resetKeyboardVars())); +} + +TDEPopupMenu::~TDEPopupMenu() +{ + if (TDEPopupMenuPrivate::s_contextedMenu == this) + { + TDEPopupMenuPrivate::s_contextedMenu = 0; + TDEPopupMenuPrivate::s_highlightedItem = -1; + } + + delete d; +} + +int TDEPopupMenu::insertTitle(const TQString &text, int id, int index) +{ + TDEPopupTitle *titleItem = new TDEPopupTitle(); + titleItem->setTitle(text); + int ret = insertItem(titleItem, id, index); + setItemEnabled(ret, false); + return ret; +} + +int TDEPopupMenu::insertTitle(const TQPixmap &icon, const TQString &text, int id, + int index) +{ + TDEPopupTitle *titleItem = new TDEPopupTitle(); + titleItem->setTitle(text, &icon); + int ret = insertItem(titleItem, id, index); + setItemEnabled(ret, false); + return ret; +} + +void TDEPopupMenu::changeTitle(int id, const TQString &text) +{ + TQMenuItem *item = findItem(id); + if(item){ + if(item->widget()) + ((TDEPopupTitle *)item->widget())->setTitle(text); +#ifndef NDEBUG + else + kdWarning() << "TDEPopupMenu: changeTitle() called with non-title id "<< id << endl; +#endif + } +#ifndef NDEBUG + else + kdWarning() << "TDEPopupMenu: changeTitle() called with invalid id " << id << endl; +#endif +} + +void TDEPopupMenu::changeTitle(int id, const TQPixmap &icon, const TQString &text) +{ + TQMenuItem *item = findItem(id); + if(item){ + if(item->widget()) + ((TDEPopupTitle *)item->widget())->setTitle(text, &icon); +#ifndef NDEBUG + else + kdWarning() << "TDEPopupMenu: changeTitle() called with non-title id "<< id << endl; +#endif + } +#ifndef NDEBUG + else + kdWarning() << "TDEPopupMenu: changeTitle() called with invalid id " << id << endl; +#endif +} + +TQString TDEPopupMenu::title(int id) const +{ + if(id == -1) // obsolete + return d->m_lastTitle; + TQMenuItem *item = findItem(id); + if(item){ + if(item->widget()) + return ((TDEPopupTitle *)item->widget())->title(); + else + tqWarning("TDEPopupMenu: title() called with non-title id %d.", id); + } + else + tqWarning("TDEPopupMenu: title() called with invalid id %d.", id); + return TQString::null; +} + +TQPixmap TDEPopupMenu::titlePixmap(int id) const +{ + TQMenuItem *item = findItem(id); + if(item){ + if(item->widget()) + return ((TDEPopupTitle *)item->widget())->icon(); + else + tqWarning("TDEPopupMenu: titlePixmap() called with non-title id %d.", id); + } + else + tqWarning("TDEPopupMenu: titlePixmap() called with invalid id %d.", id); + TQPixmap tmp; + return tmp; +} + +/** + * This is re-implemented for keyboard navigation. + */ +void TDEPopupMenu::closeEvent(TQCloseEvent*e) +{ + if (d->shortcuts) + resetKeyboardVars(); + TQPopupMenu::closeEvent(e); +} + +void TDEPopupMenu::activateItemAt(int index) +{ + d->state = Qt::NoButton; + TQPopupMenu::activateItemAt(index); +} + +TQt::ButtonState TDEPopupMenu::state() const +{ + return d->state; +} + +void TDEPopupMenu::keyPressEvent(TQKeyEvent* e) +{ + d->state = Qt::NoButton; + if (!d->shortcuts) { + // continue event processing by Qpopup + //e->ignore(); + d->state = e->state(); + TQPopupMenu::keyPressEvent(e); + return; + } + + int i = 0; + bool firstpass = true; + TQString keyString = e->text(); + + // check for common commands dealt with by QPopup + int key = e->key(); + if (key == Key_Escape || key == Key_Return || key == Key_Enter + || key == Key_Up || key == Key_Down || key == Key_Left + || key == Key_Right || key == Key_F1) { + + resetKeyboardVars(); + // continue event processing by Qpopup + //e->ignore(); + d->state = e->state(); + TQPopupMenu::keyPressEvent(e); + return; + } else if ( key == Key_Shift || key == Key_Control || key == Key_Alt || key == Key_Meta ) + return TQPopupMenu::keyPressEvent(e); + + // check to see if the user wants to remove a key from the sequence (backspace) + // or clear the sequence (delete) + if (!d->keySeq.isNull()) { + + if (key == Key_Backspace) { + + if (d->keySeq.length() == 1) { + resetKeyboardVars(); + return; + } + + // keep the last sequence in keyString + keyString = d->keySeq.left(d->keySeq.length() - 1); + + // allow sequence matching to be tried again + resetKeyboardVars(); + + } else if (key == Key_Delete) { + resetKeyboardVars(); + + // clear active item + setActiveItem(0); + return; + + } else if (d->noMatches) { + // clear if there are no matches + resetKeyboardVars(); + + // clear active item + setActiveItem(0); + + } else { + // the key sequence is not a null string + // therefore the lastHitIndex is valid + i = d->lastHitIndex; + } + } else if (key == Key_Backspace && parentMenu) { + // backspace with no chars in the buffer... go back a menu. + hide(); + resetKeyboardVars(); + return; + } + + d->keySeq += keyString; + int seqLen = d->keySeq.length(); + + for (; i < (int)count(); i++) { + // compare typed text with text of this entry + int j = idAt(i); + + // don't search disabled entries + if (!isItemEnabled(j)) + continue; + + TQString thisText; + + // retrieve the right text + // (the last selected item one may have additional ampersands) + if (i == d->lastHitIndex) + thisText = d->originalText; + else + thisText = text(j); + + // if there is an accelerator present, remove it + if ((int)accel(j) != 0) + thisText = thisText.replace("&", TQString()); + + // chop text to the search length + thisText = thisText.left(seqLen); + + // do the search + if (!thisText.find(d->keySeq, 0, false)) { + + if (firstpass) { + // match + setActiveItem(i); + + // check to see if we're underlining a different item + if (d->lastHitIndex != i) + // yes; revert the underlining + changeItem(idAt(d->lastHitIndex), d->originalText); + + // set the original text if it's a different item + if (d->lastHitIndex != i || d->lastHitIndex == -1) + d->originalText = text(j); + + // underline the currently selected item + changeItem(j, underlineText(d->originalText, d->keySeq.length())); + + // remember what's going on + d->lastHitIndex = i; + + // start/restart the clear timer + d->clearTimer.start(5000, true); + + // go around for another try, to see if we can execute + firstpass = false; + } else { + // don't allow execution + return; + } + } + + // fall through to allow execution + } + + if (!firstpass) { + if (d->autoExec) { + // activate anything + activateItemAt(d->lastHitIndex); + resetKeyboardVars(); + + } else if (findItem(idAt(d->lastHitIndex)) && + findItem(idAt(d->lastHitIndex))->popup()) { + // only activate sub-menus + activateItemAt(d->lastHitIndex); + resetKeyboardVars(); + } + + return; + } + + // no matches whatsoever, clean up + resetKeyboardVars(true); + //e->ignore(); + TQPopupMenu::keyPressEvent(e); +} + +bool TDEPopupMenu::focusNextPrevChild( bool next ) +{ + resetKeyboardVars(); + return TQPopupMenu::focusNextPrevChild( next ); +} + +TQString TDEPopupMenu::underlineText(const TQString& text, uint length) +{ + TQString ret = text; + for (uint i = 0; i < length; i++) { + if (ret[2*i] != '&') + ret.insert(2*i, "&"); + } + return ret; +} + +void TDEPopupMenu::resetKeyboardVars(bool noMatches /* = false */) +{ + // Clean up keyboard variables + if (d->lastHitIndex != -1) { + changeItem(idAt(d->lastHitIndex), d->originalText); + d->lastHitIndex = -1; + } + + if (!noMatches) { + d->keySeq = TQString::null; + } + + d->noMatches = noMatches; +} + +void TDEPopupMenu::setKeyboardShortcutsEnabled(bool enable) +{ + d->shortcuts = enable; +} + +void TDEPopupMenu::setKeyboardShortcutsExecute(bool enable) +{ + d->autoExec = enable; +} +/** + * End keyboard navigation. + */ + +/** + * RMB menus on menus + */ + +void TDEPopupMenu::mousePressEvent(TQMouseEvent* e) +{ + if (d->m_ctxMenu && d->m_ctxMenu->isVisible()) + { + // hide on a second context menu event + d->m_ctxMenu->hide(); + } + + TQPopupMenu::mousePressEvent(e); +} + +void TDEPopupMenu::mouseReleaseEvent(TQMouseEvent* e) +{ + // Save the button, and the modifiers from state() + d->state = TQt::ButtonState(e->button() | (e->state() & KeyButtonMask)); + + if ( !d->m_ctxMenu || !d->m_ctxMenu->isVisible() ) + TQPopupMenu::mouseReleaseEvent(e); +} + +TQPopupMenu* TDEPopupMenu::contextMenu() +{ + if (!d->m_ctxMenu) + { + d->m_ctxMenu = new TQPopupMenu(this); + connect(d->m_ctxMenu, TQT_SIGNAL(aboutToHide()), this, TQT_SLOT(ctxMenuHiding())); + } + + return d->m_ctxMenu; +} + +const TQPopupMenu* TDEPopupMenu::contextMenu() const +{ + return const_cast< TDEPopupMenu* >( this )->contextMenu(); +} + +void TDEPopupMenu::hideContextMenu() +{ + TDEPopupMenuPrivate::s_continueCtxMenuShow = false; +} + +int TDEPopupMenu::contextMenuFocusItem() +{ + return TDEPopupMenuPrivate::s_highlightedItem; +} + +TDEPopupMenu* TDEPopupMenu::contextMenuFocus() +{ + return TDEPopupMenuPrivate::s_contextedMenu; +} + +void TDEPopupMenu::itemHighlighted(int /* whichItem */) +{ + if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible()) + { + return; + } + + d->m_ctxMenu->hide(); + showCtxMenu(mapFromGlobal(TQCursor::pos())); +} + +void TDEPopupMenu::showCtxMenu(TQPoint pos) +{ + TQMenuItem* item = findItem(TDEPopupMenuPrivate::s_highlightedItem); + if (item) + { + TQPopupMenu* subMenu = item->popup(); + if (subMenu) + { + disconnect(subMenu, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(ctxMenuHideShowingMenu())); + } + } + + TDEPopupMenuPrivate::s_highlightedItem = idAt(pos); + + if (TDEPopupMenuPrivate::s_highlightedItem == -1) + { + TDEPopupMenuPrivate::s_contextedMenu = 0; + return; + } + + emit aboutToShowContextMenu(this, TDEPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu); + + TQPopupMenu* subMenu = findItem(TDEPopupMenuPrivate::s_highlightedItem)->popup(); + if (subMenu) + { + connect(subMenu, TQT_SIGNAL(aboutToShow()), TQT_SLOT(ctxMenuHideShowingMenu())); + TQTimer::singleShot(100, subMenu, TQT_SLOT(hide())); + } + + if (!TDEPopupMenuPrivate::s_continueCtxMenuShow) + { + TDEPopupMenuPrivate::s_continueCtxMenuShow = true; + return; + } + + TDEPopupMenuPrivate::s_contextedMenu = this; + d->m_ctxMenu->popup(this->mapToGlobal(pos)); + connect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(itemHighlighted(int))); +} + +/* + * this method helps prevent submenus popping up while we have a context menu + * showing + */ +void TDEPopupMenu::ctxMenuHideShowingMenu() +{ + TQMenuItem* item = findItem(TDEPopupMenuPrivate::s_highlightedItem); + if (item) + { + TQPopupMenu* subMenu = item->popup(); + if (subMenu) + { + TQTimer::singleShot(0, subMenu, TQT_SLOT(hide())); + } + } +} + +void TDEPopupMenu::ctxMenuHiding() +{ + if (TDEPopupMenuPrivate::s_highlightedItem) + { + TQPopupMenu* subMenu = findItem(TDEPopupMenuPrivate::s_highlightedItem)->popup(); + if (subMenu) + { + disconnect(subMenu, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(ctxMenuHideShowingMenu())); + } + } + + disconnect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(itemHighlighted(int))); + TDEPopupMenuPrivate::s_continueCtxMenuShow = true; +} + +void TDEPopupMenu::contextMenuEvent(TQContextMenuEvent* e) +{ + if (d->m_ctxMenu) + { + if (e->reason() == TQContextMenuEvent::Mouse) + { + showCtxMenu(e->pos()); + } + else if (actItem != -1) + { + showCtxMenu(itemGeometry(actItem).center()); + } + + e->accept(); + return; + } + + TQPopupMenu::contextMenuEvent(e); +} + +void TDEPopupMenu::hideEvent(TQHideEvent*) +{ + if (d->m_ctxMenu && d->m_ctxMenu->isVisible()) + { + // we need to block signals here when the ctxMenu is showing + // to prevent the TQPopupMenu::activated(int) signal from emitting + // when hiding with a context menu, the user doesn't expect the + // menu to actually do anything. + // since hideEvent gets called very late in the process of hiding + // (deep within TQWidget::hide) the activated(int) signal is the + // last signal to be emitted, even after things like aboutToHide() + // AJS + blockSignals(true); + d->m_ctxMenu->hide(); + blockSignals(false); + } +} +/** + * end of RMB menus on menus support + */ + +// Obsolete +TDEPopupMenu::TDEPopupMenu(const TQString& title, TQWidget *parent, const char *name) + : TQPopupMenu(parent, name) +{ + d = new TDEPopupMenuPrivate; + insertTitle(title); +} + +// Obsolete +void TDEPopupMenu::setTitle(const TQString &title) +{ + TDEPopupTitle *titleItem = new TDEPopupTitle(); + titleItem->setTitle(title); + insertItem(titleItem); + d->m_lastTitle = title; +} + +void TDEPopupTitle::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +void TDEPopupMenu::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +#include "kpopupmenu.moc" diff --git a/tdeui/tdepopupmenu.h b/tdeui/tdepopupmenu.h new file mode 100644 index 000000000..2d50e2d56 --- /dev/null +++ b/tdeui/tdepopupmenu.h @@ -0,0 +1,282 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 Daniel M. Duley + + 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 _KPOPUP_H +#define _KPOPUP_H "$Id$" + +#define INCLUDE_MENUITEM_DEF + +#include +#include +#include +#include +/** + * @short TDEPopupMenu title widget. + * + * Title widget for use in TDEPopupMenu. + * + * You usually don't have to create this manually since + * TDEPopupMenu::insertTitle will do it for you, but it is allowed if + * you wish to customize it's look. + * + * @author Daniel M. Duley + */ +class TDEUI_EXPORT TDEPopupTitle : public TQWidget +{ + Q_OBJECT + +public: + /** + * Constructs a title widget with the user specified gradient, pixmap, + * and colors. + */ + TDEPopupTitle(TQWidget *parent=0, const char *name=0); + /** + * @deprecated + * Constructs a title widget with the specified gradient and colors. + */ + TDEPopupTitle(KPixmapEffect::GradientType gradient, const TQColor &color, + const TQColor &textColor, TQWidget *parent=0, + const char *name=0) KDE_DEPRECATED; + /** + * @deprecated + * Constructs a title widget with the specified pixmap and colors. + */ + TDEPopupTitle(const KPixmap &background, const TQColor &color, + const TQColor &textColor, TQWidget *parent=0, + const char *name=0) KDE_DEPRECATED; + /** + * Sets the title string and optional icon for the title widget. + * + * You will want to call this before inserting into a menu. + */ + void setTitle(const TQString &text, const TQPixmap *icon=0); + /** + * Returns the current title. + */ + TQString title() const { return titleStr; } + /** + * Returns the current icon. + */ + TQPixmap icon() const { return miniicon; } + + TQSize sizeHint() const; + +public slots: + /// @since 3.1 + void setText( const TQString &text ); + /// @since 3.1 + void setIcon( const TQPixmap &pix ); + +protected: + void calcSize(); + void paintEvent(TQPaintEvent *ev); + + // Remove in KDE4 + KPixmapEffect::GradientType grType; + TQString titleStr; + // Remove in KDE4 + KPixmap fill; + TQPixmap miniicon; + TQColor fgColor, bgColor, grHigh, grLow; + bool useGradient; + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDEPopupTitlePrivate; + TDEPopupTitlePrivate *d; +}; + +/** + * @short A menu with title items. + * + * TDEPopupMenu is a class for menus with standard title items and keyboard + * accessibility for popups with many options and/or varying options. It acts + * identically to TQPopupMenu, with the addition of insertTitle(), + * changeTitle(), setKeyboardShortcutsEnabled() and + * setKeyboardShortcutsExecute() methods. + * + * The titles support a text string, an icon, plus user defined gradients, + * colors, and background pixmaps. + * + * The keyboard search algorithm is incremental with additional underlining + * for user feedback. + * + * @author Daniel M. Duley + * @author Hamish Rodda + */ +class TDEUI_EXPORT TDEPopupMenu : public TQPopupMenu { + Q_OBJECT + +public: + /** + * Constructs a TDEPopupMenu. + */ + TDEPopupMenu(TQWidget *parent=0, const char *name=0); + + /** + * Destructs the object + */ + ~TDEPopupMenu(); + + /** + * Inserts a title item with no icon. + */ + int insertTitle(const TQString &text, int id=-1, int index=-1); + /** + * Inserts a title item with the given icon and title. + */ + int insertTitle(const TQPixmap &icon, const TQString &text, int id=-1, + int index=-1); + /** + * Changes the title of the item at the specified id. If a icon was + * previously set it is cleared. + */ + void changeTitle(int id, const TQString &text); + /** + * Changes the title and icon of the title item at the specified id. + */ + void changeTitle(int id, const TQPixmap &icon, const TQString &text); + /** + * Returns the title of the title item at the specified id. The default + * id of -1 is for backwards compatibility only, you should always specify + * the id. + */ + TQString title(int id=-1) const; + /** + * Returns the icon of the title item at the specified id. + */ + TQPixmap titlePixmap(int id) const; + + /** + * Enables keyboard navigation by searching for the entered key sequence. + * Also underlines the currently selected item, providing feedback on the search. + * + * Defaults to off. + * + * WARNING: calls to text() of currently keyboard-selected items will + * contain additional ampersand characters. + * + * WARNING: though pre-existing keyboard shortcuts will not interfere with the + * operation of this feature, they may be confusing to the user as the existing + * shortcuts will not work. + * @since 3.1 + */ + void setKeyboardShortcutsEnabled(bool enable); + + /** + * Enables execution of the menu item once it is uniquely specified. + * Defaults to off. + * @since 3.1 + */ + void setKeyboardShortcutsExecute(bool enable); + + /** + * @deprecated + * Obsolete method provided for backwards compatibility only. Use the + * normal constructor and insertTitle instead. + */ + TDEPopupMenu(const TQString &title, TQWidget *parent=0, const char *name=0) KDE_DEPRECATED; + + /** + * @deprecated + * Obsolete method provided for backwards compatibility only. Use + * insertTitle and changeTitle instead. + */ + void setTitle(const TQString &title) KDE_DEPRECATED; + + /** + * Returns the context menu associated with this menu + * @since 3.2 + */ + TQPopupMenu* contextMenu(); + + /** + * Returns the context menu associated with this menu + * @since 3.2 + */ + const TQPopupMenu* contextMenu() const; + + /** + * Hides the context menu if shown + * @since 3.2 + */ + void hideContextMenu(); + + /** + * Returns the TDEPopupMenu associated with the current context menu + * @since 3.2 + */ + static TDEPopupMenu* contextMenuFocus(); + + /** + * returns the ID of the menuitem associated with the current context menu + * @since 3.2 + */ + static int contextMenuFocusItem(); + + /** + * Reimplemented for internal purposes + * @since 3.4 + */ + virtual void activateItemAt(int index); + /** + * Return the state of the mouse button and keyboard modifiers + * when the last menuitem was activated. + * @since 3.4 + */ + TQt::ButtonState state() const; + +signals: + /** + * connect to this signal to be notified when a context menu is about to be shown + * @param menu The menu that the context menu is about to be shown for + * @param menuItem The menu item that the context menu is currently on + * @param ctxMenu The context menu itself + * @since 3.2 + */ + void aboutToShowContextMenu(TDEPopupMenu* menu, int menuItem, TQPopupMenu* ctxMenu); + +protected: + virtual void closeEvent(TQCloseEvent *); + virtual void keyPressEvent(TQKeyEvent* e); + /// @since 3.4 + virtual void mouseReleaseEvent(TQMouseEvent* e); + virtual void mousePressEvent(TQMouseEvent* e); + virtual bool focusNextPrevChild( bool next ); + virtual void contextMenuEvent(TQContextMenuEvent *e); + virtual void hideEvent(TQHideEvent*); + + virtual void virtual_hook( int id, void* data ); + +protected slots: + /// @since 3.1 + TQString underlineText(const TQString& text, uint length); + /// @since 3.1 + void resetKeyboardVars(bool noMatches = false); + void itemHighlighted(int whichItem); + void showCtxMenu(TQPoint pos); + void ctxMenuHiding(); + void ctxMenuHideShowingMenu(); + +private: + class TDEPopupMenuPrivate; + TDEPopupMenuPrivate *d; +}; + +#endif diff --git a/tdeui/tdeselect.cpp b/tdeui/tdeselect.cpp new file mode 100644 index 000000000..19214ede3 --- /dev/null +++ b/tdeui/tdeselect.cpp @@ -0,0 +1,534 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997 Martin Jones (mjones@kde.org) + + This library 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. + + 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. +*/ + +#include +#include +#include +#include +#include +#include "kselect.h" + +#define STORE_W 8 +#define STORE_W2 STORE_W * 2 + +//----------------------------------------------------------------------------- +/* + * 2D value selector. + * The contents of the selector are drawn by derived class. + */ + +KXYSelector::KXYSelector( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ + xPos = 0; + yPos = 0; + minX = 0; + minY = 0; + maxX = 100; + maxY = 100; + store.setOptimization( TQPixmap::BestOptim ); + store.resize( STORE_W2, STORE_W2 ); +} + + +KXYSelector::~KXYSelector() +{} + + +void KXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY ) +{ + int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); + px = w; + py = w; + minX = _minX; + minY = _minY; + maxX = _maxX; + maxY = _maxY; +} + +void KXYSelector::setXValue( int _xPos ) +{ + setValues(_xPos, yPos); +} + +void KXYSelector::setYValue( int _yPos ) +{ + setValues(xPos, _yPos); +} + +void KXYSelector::setValues( int _xPos, int _yPos ) +{ + int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); + if (w < 5) w = 5; + + xPos = _xPos; + yPos = _yPos; + + if ( xPos > maxX ) + xPos = maxX; + else if ( xPos < minX ) + xPos = minX; + + if ( yPos > maxY ) + yPos = maxY; + else if ( yPos < minY ) + yPos = minY; + + int xp = w + (width() - 2 * w) * xPos / (maxX - minX); + int yp = height() - w - (height() - 2 * w) * yPos / (maxY - minY); + + setPosition( xp, yp ); +} + +TQRect KXYSelector::contentsRect() const +{ + int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); + if (w < 5) { + w = 5; + } + TQRect contents(rect()); + contents.addCoords(w, w, -w, -w); + return contents; +} + +void KXYSelector::paintEvent( TQPaintEvent *ev ) +{ + TQRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2); + TQRect paintRect = ev->rect(); + TQRect borderRect = rect(); + + int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); + if (w < 5) { + w = 5 - w; + } + borderRect.addCoords(w, w, -w, -w); + + TQPainter painter; + painter.begin( this ); + + style().tqdrawPrimitive(TQStyle::PE_Panel, &painter, + borderRect, colorGroup(), + TQStyle::Style_Sunken); + + drawContents( &painter ); + if (paintRect.contains(cursorRect)) + { + bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W, + STORE_W2, STORE_W2, CopyROP ); + drawCursor( &painter, px, py ); + } + else if (paintRect.intersects(cursorRect)) + { + repaint( cursorRect, false); + } + + painter.end(); +} + +void KXYSelector::mousePressEvent( TQMouseEvent *e ) +{ + mouseMoveEvent(e); +} + +void KXYSelector::mouseMoveEvent( TQMouseEvent *e ) +{ + int xVal, yVal; + + int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); + valuesFromPosition( e->pos().x() - w, e->pos().y() - w, xVal, yVal ); + + setValues( xVal, yVal ); + + emit valueChanged( xPos, yPos ); +} + +void KXYSelector::wheelEvent( TQWheelEvent *e ) +{ + if ( e->orientation() == Qt::Horizontal ) + setValues( xValue() + e->delta()/120, yValue() ); + else + setValues( xValue(), yValue() + e->delta()/120 ); + + emit valueChanged( xPos, yPos ); +} + +void KXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const +{ + int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); + if (w < 5) w = 5; + xVal = ( (maxX-minX) * (x-w) ) / ( width()-2*w ); + yVal = maxY - ( ( (maxY-minY) * (y-w) ) / ( height()-2*w ) ); + + if ( xVal > maxX ) + xVal = maxX; + else if ( xVal < minX ) + xVal = minX; + + if ( yVal > maxY ) + yVal = maxY; + else if ( yVal < minY ) + yVal = minY; +} + +void KXYSelector::setPosition( int xp, int yp ) +{ + int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); + if (w < 5) w = 5; + if ( xp < w ) + xp = w; + else if ( xp > width() - w ) + xp = width() - w; + + if ( yp < w ) + yp = w; + else if ( yp > height() - w ) + yp = height() - w; + + TQPainter painter; + painter.begin( this ); + + bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0, + STORE_W2, STORE_W2, CopyROP ); + bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W, + STORE_W2, STORE_W2, CopyROP ); + drawCursor( &painter, xp, yp ); + px = xp; + py = yp; + + painter.end(); +} + +void KXYSelector::drawContents( TQPainter * ) +{} + + +void KXYSelector::drawCursor( TQPainter *p, int xp, int yp ) +{ + p->setPen( TQPen( white ) ); + + p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 ); + p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 ); + p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 ); + p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 ); +} + +//----------------------------------------------------------------------------- +/* + * 1D value selector with contents drawn by derived class. + * See KColorDialog for example. + */ + + +TDESelector::TDESelector( TQWidget *parent, const char *name ) + : TQWidget( parent, name ), TQRangeControl() +{ + _orientation = Qt::Horizontal; + _indent = true; +} + +TDESelector::TDESelector( Orientation o, TQWidget *parent, const char *name ) + : TQWidget( parent, name ), TQRangeControl() +{ + _orientation = o; + _indent = true; +} + + +TDESelector::~TDESelector() +{} + + +TQRect TDESelector::contentsRect() const +{ + int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); + int iw = (w < 5) ? 5 : w; + if ( orientation() == Qt::Vertical ) + return TQRect( w, iw, width() - w * 2 - 5, height() - 2 * iw ); + else + return TQRect( iw, w, width() - 2 * iw, height() - w * 2 - 5 ); +} + +void TDESelector::paintEvent( TQPaintEvent * ) +{ + TQPainter painter; + int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); + int iw = (w < 5) ? 5 : w; + + painter.begin( this ); + + drawContents( &painter ); + + if ( indent() ) + { + TQRect r = rect(); + if ( orientation() == Qt::Vertical ) + r.addCoords(0, iw - w, -iw, w - iw); + else + r.addCoords(iw - w, 0, w - iw, -iw); + style().tqdrawPrimitive(TQStyle::PE_Panel, &painter, + r, colorGroup(), + TQStyle::Style_Sunken); + } + + TQPoint pos = calcArrowPos( value() ); + drawArrow( &painter, true, pos ); + + painter.end(); +} + +void TDESelector::mousePressEvent( TQMouseEvent *e ) +{ + moveArrow( e->pos() ); +} + +void TDESelector::mouseMoveEvent( TQMouseEvent *e ) +{ + moveArrow( e->pos() ); +} + +void TDESelector::wheelEvent( TQWheelEvent *e ) +{ + int val = value() + e->delta()/120; + setValue( val ); +} + +void TDESelector::valueChange() +{ + TQPainter painter; + TQPoint pos; + + painter.begin( this ); + + pos = calcArrowPos( prevValue() ); + drawArrow( &painter, false, pos ); + + pos = calcArrowPos( value() ); + drawArrow( &painter, true, pos ); + + painter.end(); + + emit valueChanged( value() ); +} + +void TDESelector::moveArrow( const TQPoint &pos ) +{ + int val; + int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); + int iw = (w < 5) ? 5 : w; + + if ( orientation() == Qt::Vertical ) + val = ( maxValue() - minValue() ) * (height()-pos.y()-5+w) + / (height()-iw*2) + minValue(); + else + val = ( maxValue() - minValue() ) * (width()-pos.x()-5+w) + / (width()-iw*2) + minValue(); + + setValue( val ); +} + +TQPoint TDESelector::calcArrowPos( int val ) +{ + TQPoint p; + + int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth); + int iw = (w < 5) ? 5 : w; + if ( orientation() == Qt::Vertical ) + { + p.setY( height() - ( (height()-2*iw) * val + / ( maxValue() - minValue() ) + 5 ) ); + p.setX( width() - 5 ); + } + else + { + p.setX( width() - ( (width()-2*iw) * val + / ( maxValue() - minValue() ) + 5 ) ); + p.setY( height() - 5 ); + } + + return p; +} + +void TDESelector::drawContents( TQPainter * ) +{} + +void TDESelector::drawArrow( TQPainter *painter, bool show, const TQPoint &pos ) +{ + if ( show ) + { + TQPointArray array(3); + + painter->setPen( TQPen() ); + painter->setBrush( TQBrush( colorGroup().buttonText() ) ); + array.setPoint( 0, pos.x()+0, pos.y()+0 ); + array.setPoint( 1, pos.x()+5, pos.y()+5 ); + if ( orientation() == Qt::Vertical ) + { + array.setPoint( 2, pos.x()+5, pos.y()-5 ); + } + else + { + array.setPoint( 2, pos.x()-5, pos.y()+5 ); + } + + painter->drawPolygon( array ); + } + else + { + if ( orientation() == Qt::Vertical ) + { + repaint(pos.x(), pos.y()-5, 6, 11, true); + } + else + { + repaint(pos.x()-5, pos.y(), 11, 6, true); + } + } +} + +//---------------------------------------------------------------------------- + +KGradientSelector::KGradientSelector( TQWidget *parent, const char *name ) + : TDESelector( parent, name ) +{ + init(); +} + + +KGradientSelector::KGradientSelector( Orientation o, TQWidget *parent, + const char *name ) + : TDESelector( o, parent, name ) +{ + init(); +} + + +KGradientSelector::~KGradientSelector() +{} + + +void KGradientSelector::init() +{ + color1.setRgb( 0, 0, 0 ); + color2.setRgb( 255, 255, 255 ); + + text1 = text2 = ""; +} + + +void KGradientSelector::drawContents( TQPainter *painter ) +{ + TQImage image( contentsRect().width(), contentsRect().height(), 32 ); + + TQColor col; + float scale; + + int redDiff = color2.red() - color1.red(); + int greenDiff = color2.green() - color1.green(); + int blueDiff = color2.blue() - color1.blue(); + + if ( orientation() == Qt::Vertical ) + { + for ( int y = 0; y < image.height(); y++ ) + { + scale = 1.0 * y / image.height(); + col.setRgb( color1.red() + int(redDiff*scale), + color1.green() + int(greenDiff*scale), + color1.blue() + int(blueDiff*scale) ); + + unsigned int *p = (uint *) image.scanLine( y ); + for ( int x = 0; x < image.width(); x++ ) + *p++ = col.rgb(); + } + } + else + { + unsigned int *p = (uint *) image.scanLine( 0 ); + + for ( int x = 0; x < image.width(); x++ ) + { + scale = 1.0 * x / image.width(); + col.setRgb( color1.red() + int(redDiff*scale), + color1.green() + int(greenDiff*scale), + color1.blue() + int(blueDiff*scale) ); + *p++ = col.rgb(); + } + + for ( int y = 1; y < image.height(); y++ ) + memcpy( image.scanLine( y ), image.scanLine( y - 1), + sizeof( unsigned int ) * image.width() ); + } + + TQColor ditherPalette[8]; + + for ( int s = 0; s < 8; s++ ) + ditherPalette[s].setRgb( color1.red() + redDiff * s / 8, + color1.green() + greenDiff * s / 8, + color1.blue() + blueDiff * s / 8 ); + + KImageEffect::dither( image, ditherPalette, 8 ); + + TQPixmap p; + p.convertFromImage( image ); + + painter->drawPixmap( contentsRect().x(), contentsRect().y(), p ); + + if ( orientation() == Qt::Vertical ) + { + int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2; + int xPos = contentsRect().left() + (contentsRect().width() - + painter->fontMetrics().width( text2 )) / 2; + TQPen pen( color2 ); + painter->setPen( pen ); + painter->drawText( xPos, yPos, text2 ); + + yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2; + xPos = contentsRect().left() + (contentsRect().width() - + painter->fontMetrics().width( text1 )) / 2; + pen.setColor( color1 ); + painter->setPen( pen ); + painter->drawText( xPos, yPos, text1 ); + } + else + { + int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2; + + TQPen pen( color2 ); + painter->setPen( pen ); + painter->drawText( contentsRect().left() + 2, yPos, text1 ); + + pen.setColor( color1 ); + painter->setPen( pen ); + painter->drawText( contentsRect().right() - + painter->fontMetrics().width( text2 ) - 2, yPos, text2 ); + } +} + +//----------------------------------------------------------------------------- + +void KXYSelector::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +void TDESelector::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +void KGradientSelector::virtual_hook( int id, void* data ) +{ TDESelector::virtual_hook( id, data ); } + +#include "kselect.moc" + diff --git a/tdeui/tdeselect.h b/tdeui/tdeselect.h new file mode 100644 index 000000000..fd9a90ccd --- /dev/null +++ b/tdeui/tdeselect.h @@ -0,0 +1,373 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997 Martin Jones (mjones@kde.org) + + This library 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. + + 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. +*/ +//----------------------------------------------------------------------------- +// Selector widgets for KDE Color Selector, but probably useful for other +// stuff also. + +#ifndef __KSELECT_H__ +#define __KSELECT_H__ + +#include +#include +#include + +#include + +/** + * KXYSelector is the base class for other widgets which + * provides the ability to choose from a two-dimensional + * range of values. The currently chosen value is indicated + * by a cross. An example is the KHSSelector which + * allows to choose from a range of colors, and which is + * used in KColorDialog. + * + * A custom drawing routine for the widget surface has + * to be provided by the subclass. + */ +class TDEUI_EXPORT KXYSelector : public TQWidget +{ + Q_OBJECT + TQ_PROPERTY( int xValue READ xValue WRITE setXValue ) + TQ_PROPERTY( int yValue READ yValue WRITE setYValue ) + +public: + /** + * Constructs a two-dimensional selector widget which + * has a value range of [0..100] in both directions. + */ + KXYSelector( TQWidget *parent=0, const char *name=0 ); + /** + * Destructs the widget. + */ + ~KXYSelector(); + + /** + * Sets the current values in horizontal and + * vertical direction. + * @param xPos the horizontal value + * @param yPos the veritcal value + */ + void setValues( int xPos, int yPos ); + + /** + * Sets the current horizontal value + * @param xPos the horizontal value + */ + void setXValue( int xPos ); + + /** + * Sets the current vertical value + * @param yPos the veritcal value + */ + void setYValue( int yPos ); + + /** + * Sets the range of possible values. + */ + void setRange( int minX, int minY, int maxX, int maxY ); + + /** + * @return the current value in horizontal direction. + */ + int xValue() const { return xPos; } + /** + * @return the current value in vertical direction. + */ + int yValue() const { return yPos; } + + /** + * @return the rectangle on which subclasses should draw. + */ + TQRect contentsRect() const; + +signals: + /** + * This signal is emitted whenever the user chooses a value, + * e.g. by clicking with the mouse on the widget. + */ + void valueChanged( int x, int y ); + +protected: + /** + * Override this function to draw the contents of the widget. + * The default implementation does nothing. + * + * Draw within contentsRect() only. + */ + virtual void drawContents( TQPainter * ); + /** + * Override this function to draw the cursor which + * indicates the currently selected value pair. + */ + virtual void drawCursor( TQPainter *p, int xp, int yp ); + + virtual void paintEvent( TQPaintEvent *e ); + virtual void mousePressEvent( TQMouseEvent *e ); + virtual void mouseMoveEvent( TQMouseEvent *e ); + virtual void wheelEvent( TQWheelEvent * ); + + /** + * Converts a pixel position to its corresponding values. + */ + void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const; + +private: + void setPosition( int xp, int yp ); + int px; + int py; + int xPos; + int yPos; + int minX; + int maxX; + int minY; + int maxY; + TQPixmap store; + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class KXYSelectorPrivate; + KXYSelectorPrivate *d; +}; + + +/** + * TDESelector is the base class for other widgets which + * provides the ability to choose from a one-dimensional + * range of values. An example is the KGradientSelector + * which allows to choose from a range of colors. + * + * A custom drawing routine for the widget surface has + * to be provided by the subclass. + */ +class TDEUI_EXPORT TDESelector : public TQWidget, public TQRangeControl +{ + Q_OBJECT + TQ_PROPERTY( int value READ value WRITE setValue ) + TQ_PROPERTY( int minValue READ minValue WRITE setMinValue ) + TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) +public: + + /** + * Constructs a horizontal one-dimensional selection widget. + */ + TDESelector( TQWidget *parent=0, const char *name=0 ); + /** + * Constructs a one-dimensional selection widget with + * a given orientation. + */ + TDESelector( Orientation o, TQWidget *parent = 0L, const char *name = 0L ); + /* + * Destructs the widget. + */ + ~TDESelector(); + + /** + * @return the orientation of the widget. + */ + Orientation orientation() const + { return _orientation; } + + /** + * @return the rectangle on which subclasses should draw. + */ + TQRect contentsRect() const; + + /** + * Sets the indent option of the widget to i. + * This determines whether a shaded frame is drawn. + */ + void setIndent( bool i ) + { _indent = i; } + /** + * @return whether the indent option is set. + */ + bool indent() const + { return _indent; } + + /** + * Sets the value. + */ + void setValue(int value) + { TQRangeControl::setValue(value); } + + /** + * @returns the value. + */ + int value() const + { return TQRangeControl::value(); } + + /** + * Sets the min value. + */ + void setMinValue(int value) + { TQRangeControl::setMinValue(value); } + + /** + * @return the min value. + */ + int minValue() const + { return TQRangeControl::minValue(); } + + /** + * Sets the max value. + */ + void setMaxValue(int value) + { TQRangeControl::setMaxValue(value); } + + /** + * @return the max value. + */ + int maxValue() const + { return TQRangeControl::maxValue(); } + +signals: + /** + * This signal is emitted whenever the user chooses a value, + * e.g. by clicking with the mouse on the widget. + */ + void valueChanged( int value ); + +protected: + /** + * Override this function to draw the contents of the control. + * The default implementation does nothing. + * + * Draw only within contentsRect(). + */ + virtual void drawContents( TQPainter * ); + /** + * Override this function to draw the cursor which + * indicates the current value. This function is + * always called twice, once with argument show=false + * to clear the old cursor, once with argument show=true + * to draw the new one. + */ + virtual void drawArrow( TQPainter *painter, bool show, const TQPoint &pos ); + + virtual void valueChange(); + virtual void paintEvent( TQPaintEvent * ); + virtual void mousePressEvent( TQMouseEvent *e ); + virtual void mouseMoveEvent( TQMouseEvent *e ); + virtual void wheelEvent( TQWheelEvent * ); + +private: + TQPoint calcArrowPos( int val ); + void moveArrow( const TQPoint &pos ); + + Orientation _orientation; + bool _indent; + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class TDESelectorPrivate; + TDESelectorPrivate *d; +}; + + +/** + * The KGradientSelector widget allows the user to choose + * from a one-dimensional range of colors which is given as a + * gradient between two colors provided by the programmer. + * + * \image html kgradientselector.png "KDE Gradient Selector Widget" + * + **/ +class TDEUI_EXPORT KGradientSelector : public TDESelector +{ + Q_OBJECT + + TQ_PROPERTY( TQColor firstColor READ firstColor WRITE setFirstColor ) + TQ_PROPERTY( TQColor secondColor READ secondColor WRITE setSecondColor ) + TQ_PROPERTY( TQString firstText READ firstText WRITE setFirstText ) + TQ_PROPERTY( TQString secondText READ secondText WRITE setSecondText ) + +public: + /** + * Constructs a horizontal color selector which + * contains a gradient between white and black. + */ + KGradientSelector( TQWidget *parent=0, const char *name=0 ); + /** + * Constructs a colors selector with orientation o which + * contains a gradient between white and black. + */ + KGradientSelector( Orientation o, TQWidget *parent=0, const char *name=0 ); + /** + * Destructs the widget. + */ + ~KGradientSelector(); + /** + * Sets the two colors which span the gradient. + */ + void setColors( const TQColor &col1, const TQColor &col2 ) + { color1 = col1; color2 = col2; update();} + void setText( const TQString &t1, const TQString &t2 ) + { text1 = t1; text2 = t2; update(); } + + /** + * Set each color on its own. + */ + void setFirstColor( const TQColor &col ) + { color1 = col; update(); } + void setSecondColor( const TQColor &col ) + { color2 = col; update(); } + + /** + * Set each description on its own + */ + void setFirstText( const TQString &t ) + { text1 = t; update(); } + void setSecondText( const TQString &t ) + { text2 = t; update(); } + + const TQColor firstColor() const + { return color1; } + const TQColor secondColor() const + { return color2; } + + const TQString firstText() const + { return text1; } + const TQString secondText() const + { return text2; } + +protected: + + virtual void drawContents( TQPainter * ); + virtual TQSize minimumSize() const + { return sizeHint(); } + +private: + void init(); + TQColor color1; + TQColor color2; + TQString text1; + TQString text2; + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class KGradientSelectorPrivate; + KGradientSelectorPrivate *d; +}; + + +#endif // __KSELECT_H__ + diff --git a/tdeui/tdeshortcutdialog.cpp b/tdeui/tdeshortcutdialog.cpp new file mode 100644 index 000000000..14cdd9190 --- /dev/null +++ b/tdeui/tdeshortcutdialog.cpp @@ -0,0 +1,529 @@ +/* This file is part of the KDE libraries + Copyright (C) 2002,2003 Ellis Whitehead + + This library 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. + + 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. +*/ + +#include "kshortcutdialog.h" + +#include + +#ifdef Q_WS_X11 + #define XK_XKB_KEYS + #define XK_MISCELLANY + #include // For x11Event() + #include // For XK_... + + #ifdef KeyPress + const int XKeyPress = KeyPress; + const int XKeyRelease = KeyRelease; + const int XFocusOut = FocusOut; + const int XFocusIn = FocusIn; + #undef KeyRelease + #undef KeyPress + #undef FocusOut + #undef FocusIn + #endif +#elif defined(Q_WS_WIN) +# include +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool TDEShortcutDialog::s_showMore = false; + +TDEShortcutDialog::TDEShortcutDialog( const TDEShortcut& shortcut, bool bQtShortcut, TQWidget* parent, const char* name ) +: KDialogBase( parent, name, true, i18n("Configure Shortcut"), + KDialogBase::Details|KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Cancel, true ) +{ + setButtonText(Details, i18n("Advanced")); + m_stack = new TQVBox(this); + m_stack->setMinimumWidth(360); + m_stack->setSpacing(0); + m_stack->setMargin(0); + setMainWidget(m_stack); + + m_simple = new TDEShortcutDialogSimple(m_stack); + + m_adv = new TDEShortcutDialogAdvanced(m_stack); + m_adv->hide(); + + m_bQtShortcut = bQtShortcut; + + m_bGrab = false; + m_iSeq = 0; + m_iKey = 0; + m_ptxtCurrent = 0; + m_bRecording = false; + m_mod = 0; + + m_simple->m_btnClearShortcut->setPixmap( SmallIcon( "locationbar_erase" ) ); + m_adv->m_btnClearPrimary->setPixmap( SmallIcon( "locationbar_erase" ) ); + m_adv->m_btnClearAlternate->setPixmap( SmallIcon( "locationbar_erase" ) ); + connect(m_simple->m_btnClearShortcut, TQT_SIGNAL(clicked()), + this, TQT_SLOT(slotClearShortcut())); + connect(m_adv->m_btnClearPrimary, TQT_SIGNAL(clicked()), + this, TQT_SLOT(slotClearPrimary())); + connect(m_adv->m_btnClearAlternate, TQT_SIGNAL(clicked()), + this, TQT_SLOT(slotClearAlternate())); + + connect(m_adv->m_txtPrimary, TQT_SIGNAL(clicked()), + m_adv->m_btnPrimary, TQT_SLOT(animateClick())); + connect(m_adv->m_txtAlternate, TQT_SIGNAL(clicked()), + m_adv->m_btnAlternate, TQT_SLOT(animateClick())); + connect(m_adv->m_btnPrimary, TQT_SIGNAL(clicked()), + this, TQT_SLOT(slotSelectPrimary())); + connect(m_adv->m_btnAlternate, TQT_SIGNAL(clicked()), + this, TQT_SLOT(slotSelectAlternate())); + + KGuiItem ok = KStdGuiItem::ok(); + ok.setText( i18n( "OK" ) ); + setButtonOK( ok ); + + KGuiItem cancel = KStdGuiItem::cancel(); + cancel.setText( i18n( "Cancel" ) ); + setButtonCancel( cancel ); + + setShortcut( shortcut ); + resize( 0, 0 ); + + s_showMore = TDEConfigGroup(TDEGlobal::config(), "General").readBoolEntry("ShowAlternativeShortcutConfig", s_showMore); + updateDetails(); + + #ifdef Q_WS_X11 + kapp->installX11EventFilter( this ); // Allow button to capture X Key Events. + #endif +} + +TDEShortcutDialog::~TDEShortcutDialog() +{ + TDEConfigGroup group(TDEGlobal::config(), "General"); + group.writeEntry("ShowAlternativeShortcutConfig", s_showMore); +} + +void TDEShortcutDialog::setShortcut( const TDEShortcut & shortcut ) +{ + m_shortcut = shortcut; + updateShortcutDisplay(); +} + +void TDEShortcutDialog::updateShortcutDisplay() +{ + TQString s[2] = { m_shortcut.seq(0).toString(), m_shortcut.seq(1).toString() }; + + if( m_bRecording ) { + m_ptxtCurrent->setDefault( true ); + m_ptxtCurrent->setFocus(); + + // Display modifiers for the first key in the KKeySequence + if( m_iKey == 0 ) { + if( m_mod ) { + TQString keyModStr; + if( m_mod & KKey::WIN ) keyModStr += KKey::modFlagLabel(KKey::WIN) + "+"; + if( m_mod & KKey::ALT ) keyModStr += KKey::modFlagLabel(KKey::ALT) + "+"; + if( m_mod & KKey::CTRL ) keyModStr += KKey::modFlagLabel(KKey::CTRL) + "+"; + if( m_mod & KKey::SHIFT ) keyModStr += KKey::modFlagLabel(KKey::SHIFT) + "+"; + s[m_iSeq] = keyModStr; + } + } + // When in the middle of entering multi-key shortcuts, + // add a "," to the end of the displayed shortcut. + else + s[m_iSeq] += ","; + } + else { + m_adv->m_txtPrimary->setDefault( false ); + m_adv->m_txtAlternate->setDefault( false ); + this->setFocus(); + } + + s[0].replace('&', TQString::fromLatin1("&&")); + s[1].replace('&', TQString::fromLatin1("&&")); + + m_simple->m_txtShortcut->setText( s[0] ); + m_adv->m_txtPrimary->setText( s[0] ); + m_adv->m_txtAlternate->setText( s[1] ); + + // Determine the enable state of the 'Less' button + bool bLessOk; + // If there is no shortcut defined, + if( m_shortcut.count() == 0 ) + bLessOk = true; + // If there is a single shortcut defined, and it is not a multi-key shortcut, + else if( m_shortcut.count() == 1 && m_shortcut.seq(0).count() <= 1 ) + bLessOk = true; + // Otherwise, we have an alternate shortcut or multi-key shortcut(s). + else + bLessOk = false; + enableButton(Details, bLessOk); +} + +void TDEShortcutDialog::slotDetails() +{ + s_showMore = (m_adv->isHidden()); + updateDetails(); +} + +void TDEShortcutDialog::updateDetails() +{ + bool showAdvanced = s_showMore || (m_shortcut.count() > 1); + setDetails(showAdvanced); + m_bRecording = false; + m_iSeq = 0; + m_iKey = 0; + + if (showAdvanced) + { + m_simple->hide(); + m_adv->show(); + m_adv->m_btnPrimary->setChecked( true ); + slotSelectPrimary(); + } + else + { + m_ptxtCurrent = m_simple->m_txtShortcut; + m_adv->hide(); + m_simple->show(); + m_simple->m_txtShortcut->setDefault( true ); + m_simple->m_txtShortcut->setFocus(); + m_adv->m_btnMultiKey->setChecked( false ); + } + kapp->processEvents(); + adjustSize(); +} + +void TDEShortcutDialog::slotSelectPrimary() +{ + m_bRecording = false; + m_iSeq = 0; + m_iKey = 0; + m_ptxtCurrent = m_adv->m_txtPrimary; + m_ptxtCurrent->setDefault(true); + m_ptxtCurrent->setFocus(); + updateShortcutDisplay(); +} + +void TDEShortcutDialog::slotSelectAlternate() +{ + m_bRecording = false; + m_iSeq = 1; + m_iKey = 0; + m_ptxtCurrent = m_adv->m_txtAlternate; + m_ptxtCurrent->setDefault(true); + m_ptxtCurrent->setFocus(); + updateShortcutDisplay(); +} + +void TDEShortcutDialog::slotClearShortcut() +{ + m_shortcut.setSeq( 0, KKeySequence() ); + updateShortcutDisplay(); +} + +void TDEShortcutDialog::slotClearPrimary() +{ + m_shortcut.setSeq( 0, KKeySequence() ); + m_adv->m_btnPrimary->setChecked( true ); + slotSelectPrimary(); +} + +void TDEShortcutDialog::slotClearAlternate() +{ + if( m_shortcut.count() == 2 ) + m_shortcut.init( m_shortcut.seq(0) ); + m_adv->m_btnAlternate->setChecked( true ); + slotSelectAlternate(); +} + +void TDEShortcutDialog::slotMultiKeyMode( bool bOn ) +{ + // If turning off multi-key mode during a recording, + if( !bOn && m_bRecording ) { + m_bRecording = false; + m_iKey = 0; + updateShortcutDisplay(); + } +} + +#ifdef Q_WS_X11 +/* we don't use the generic Qt code on X11 because it allows us + to grab the keyboard so that all keypresses are seen + */ +bool TDEShortcutDialog::x11Event( XEvent *pEvent ) +{ + switch( pEvent->type ) { + case XKeyPress: + x11KeyPressEvent( pEvent ); + return true; + case XKeyRelease: + x11KeyReleaseEvent( pEvent ); + return true; + case XFocusIn: + if (!m_bGrab) { + //kdDebug(125) << "FocusIn and Grab!" << endl; + grabKeyboard(); + m_bGrab = true; + } + //else + // kdDebug(125) << "FocusIn" << endl; + break; + case XFocusOut: + if (m_bGrab) { + //kdDebug(125) << "FocusOut and Ungrab!" << endl; + releaseKeyboard(); + m_bGrab = false; + } + //else + // kdDebug(125) << "FocusOut" << endl; + break; + default: + //kdDebug(125) << "x11Event->type = " << pEvent->type << endl; + break; + } + return KDialogBase::x11Event( pEvent ); +} + +static uint getModsFromModX( uint keyModX ) +{ + uint mod = 0; + if( keyModX & KKeyNative::modX(KKey::SHIFT) ) mod += KKey::SHIFT; + if( keyModX & KKeyNative::modX(KKey::CTRL) ) mod += KKey::CTRL; + if( keyModX & KKeyNative::modX(KKey::ALT) ) mod += KKey::ALT; + if( keyModX & KKeyNative::modX(KKey::WIN) ) mod += KKey::WIN; + return mod; +} + +static bool convertSymXToMod( uint keySymX, uint* pmod ) +{ + switch( keySymX ) { + // Don't allow setting a modifier key as an accelerator. + // Also, don't release the focus yet. We'll wait until + // we get a 'normal' key. + case XK_Shift_L: case XK_Shift_R: *pmod = KKey::SHIFT; break; + case XK_Control_L: case XK_Control_R: *pmod = KKey::CTRL; break; + case XK_Alt_L: case XK_Alt_R: *pmod = KKey::ALT; break; + // FIXME: check whether the Meta or Super key are for the Win modifier + case XK_Meta_L: case XK_Meta_R: + case XK_Super_L: case XK_Super_R: *pmod = KKey::WIN; break; + case XK_Hyper_L: case XK_Hyper_R: + case XK_Mode_switch: + case XK_Num_Lock: + case XK_Caps_Lock: + break; + default: + return false; + } + return true; +} + +void TDEShortcutDialog::x11KeyPressEvent( XEvent* pEvent ) +{ + KKeyNative keyNative( pEvent ); + uint keyModX = keyNative.mod(); + uint keySymX = keyNative.sym(); + + m_mod = getModsFromModX( keyModX ); + + if( keySymX ) { + m_bRecording = true; + + uint mod = 0; + if( convertSymXToMod( keySymX, &mod ) ) { + if( mod ) + m_mod |= mod; + } + else + keyPressed( KKey(keyNative) ); + } + updateShortcutDisplay(); +} + +void TDEShortcutDialog::x11KeyReleaseEvent( XEvent* pEvent ) +{ + // We're only interested in the release of modifier keys, + // and then only when it's for the first key in a sequence. + if( m_bRecording && m_iKey == 0 ) { + KKeyNative keyNative( pEvent ); + uint keyModX = keyNative.mod(); + uint keySymX = keyNative.sym(); + + m_mod = getModsFromModX( keyModX ); + + uint mod = 0; + if( convertSymXToMod( keySymX, &mod ) && mod ) { + m_mod &= ~mod; + if( !m_mod ) + m_bRecording = false; + } + updateShortcutDisplay(); + } +} +#elif defined(Q_WS_WIN) +void TDEShortcutDialog::keyPressEvent( TQKeyEvent * e ) +{ + kdDebug() << e->text() << " " << (int)e->text()[0].latin1()<< " " << (int)e->ascii() << endl; + //if key is a letter, it must be stored as lowercase + int keyQt = TQChar( e->key() & 0xff ).isLetter() ? + (TQChar( e->key() & 0xff ).lower().latin1() | (e->key() & 0xffff00) ) + : e->key(); + int modQt = KKeyServer::qtButtonStateToMod( e->state() ); + KKeyNative keyNative( KKey(keyQt, modQt) ); + m_mod = keyNative.mod(); + uint keySym = keyNative.sym(); + + switch( keySym ) { + case Key_Shift: + m_mod |= KKey::SHIFT; + m_bRecording = true; + break; + case Key_Control: + m_mod |= KKey::CTRL; + m_bRecording = true; + break; + case Key_Alt: + m_mod |= KKey::ALT; + m_bRecording = true; + break; + case Key_Menu: + case Key_Meta: //unused + break; + default: + if( keyNative.sym() == Key_Return && m_iKey > 0 ) { + accept(); + return; + } + //accept + if (keyNative.sym()) { + KKey key = keyNative; + key.simplify(); + KKeySequence seq; + if( m_iKey == 0 ) + seq = key; + else { + seq = m_shortcut.seq( m_iSeq ); + seq.setKey( m_iKey, key ); + } + m_shortcut.setSeq( m_iSeq, seq ); + + if(m_adv->m_btnMultiKey->isChecked()) + m_iKey++; + + m_bRecording = true; + + updateShortcutDisplay(); + + if( !m_adv->m_btnMultiKey->isChecked() ) + TQTimer::singleShot(500, this, TQT_SLOT(accept())); + } + return; + } + + // If we are editing the first key in the sequence, + // display modifier keys which are held down + if( m_iKey == 0 ) { + updateShortcutDisplay(); + } +} + +bool TDEShortcutDialog::event ( TQEvent * e ) +{ + if (e->type()==TQEvent::KeyRelease) { + int modQt = KKeyServer::qtButtonStateToMod( static_cast(e)->state() ); + KKeyNative keyNative( KKey(static_cast(e)->key(), modQt) ); + uint keySym = keyNative.sym(); + + bool change = true; + switch( keySym ) { + case Key_Shift: + if (m_mod & KKey::SHIFT) + m_mod ^= KKey::SHIFT; + break; + case Key_Control: + if (m_mod & KKey::CTRL) + m_mod ^= KKey::CTRL; + break; + case Key_Alt: + if (m_mod & KKey::ALT) + m_mod ^= KKey::ALT; + break; + default: + change = false; + } + if (change) + updateShortcutDisplay(); + } + return KDialogBase::event(e); +} +#endif + +void TDEShortcutDialog::keyPressed( KKey key ) +{ + kdDebug(125) << "keyPressed: " << key.toString() << endl; + + key.simplify(); + if( m_bQtShortcut ) { + key = key.keyCodeQt(); + if( key.isNull() ) { + // TODO: message box about key not able to be used as application shortcut + } + } + + KKeySequence seq; + if( m_iKey == 0 ) + seq = key; + else { + // Remove modifiers + key.init( key.sym(), 0 ); + seq = m_shortcut.seq( m_iSeq ); + seq.setKey( m_iKey, key ); + } + + m_shortcut.setSeq( m_iSeq, seq ); + + m_mod = 0; + if( m_adv->m_btnMultiKey->isChecked() && m_iKey < KKeySequence::MAX_KEYS - 1 ) + m_iKey++; + else { + m_iKey = 0; + m_bRecording = false; + } + + updateShortcutDisplay(); + + if( !m_adv->m_btnMultiKey->isChecked() ) + TQTimer::singleShot(500, this, TQT_SLOT(accept())); +} + +#include "kshortcutdialog.moc" diff --git a/tdeui/tdeshortcutdialog.h b/tdeui/tdeshortcutdialog.h new file mode 100644 index 000000000..59a4bb565 --- /dev/null +++ b/tdeui/tdeshortcutdialog.h @@ -0,0 +1,96 @@ +/* This file is part of the KDE libraries + Copyright (C) 2002,2003 Ellis Whitehead + + This library 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. + + 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 _KSHORTCUTDIALOG_H_ +#define _KSHORTCUTDIALOG_H_ + +#include "kdialogbase.h" +#include "kshortcut.h" + +class TQVBox; +class KPushButton; +class TDEShortcutDialogSimple; +class TDEShortcutDialogAdvanced; + +/** + * @short Dialog for configuring a shortcut. + * + * This dialog allows configuring a single TDEShortcut. KKeyDialog + * should be usually used instead. + * + * @internal + * @see KKeyDialog + * @since 3.4 + */ +class TDEUI_EXPORT TDEShortcutDialog : public KDialogBase +{ + Q_OBJECT +public: + TDEShortcutDialog( const TDEShortcut& shortcut, bool bQtShortcut, TQWidget* parent = 0, const char* name = 0 ); + ~TDEShortcutDialog(); + + void setShortcut( const TDEShortcut & shortcut ); + const TDEShortcut& shortcut() const { return m_shortcut; } + +private: + // true if qt shortcut, false if native shortcut + bool m_bQtShortcut; + + TDEShortcut m_shortcut; + bool m_bGrab; + KPushButton* m_ptxtCurrent; + uint m_iSeq; + uint m_iKey; + bool m_bRecording; + uint m_mod; + TDEShortcutDialogSimple *m_simple; + TDEShortcutDialogAdvanced *m_adv; + TQVBox *m_stack; + + void updateShortcutDisplay(); + //void displayMods(); + void keyPressed( KKey key ); + void updateDetails(); + + #ifdef Q_WS_X11 + virtual bool x11Event( XEvent *pEvent ); + //void x11EventKeyPress( XEvent *pEvent ); + void x11KeyPressEvent( XEvent* pEvent ); + void x11KeyReleaseEvent( XEvent* pEvent ); + #endif + #ifdef Q_WS_WIN + virtual void keyPressEvent( TQKeyEvent * e ); + virtual bool event(TQEvent * e); + #endif + +protected slots: + void slotDetails(); + void slotSelectPrimary(); + void slotSelectAlternate(); + void slotClearShortcut(); + void slotClearPrimary(); + void slotClearAlternate(); + void slotMultiKeyMode( bool bOn ); + +private: + class TDEShortcutDialogPrivate* d; + static bool s_showMore; +}; + +#endif // _KSHORTCUTDIALOG_H_ diff --git a/tdeui/tdeshortcutdialog_advanced.ui b/tdeui/tdeshortcutdialog_advanced.ui new file mode 100644 index 000000000..77c7fae14 --- /dev/null +++ b/tdeui/tdeshortcutdialog_advanced.ui @@ -0,0 +1,254 @@ + +TDEShortcutDialogAdvanced + + + TDEShortcutDialogAdvanced + + + + 0 + 0 + 359 + 157 + + + + + 3 + 3 + 0 + 0 + + + + + unnamed + + + 0 + + + + m_frameMore + + + NoFrame + + + Plain + + + + + + + unnamed + + + 0 + + + + m_btnAlternate + + + NoFocus + + + Alternate shortcut: + + + + + m_btnPrimary + + + NoFocus + + + Primary shortcut: + + + + + layout6 + + + + unnamed + + + + m_txtAlternate + + + + 255 + 255 + 255 + + + + ClickFocus + + + + + + false + + + false + + + + + spacer6 + + + Horizontal + + + Expanding + + + + 21 + 20 + + + + + + + + layout7 + + + + unnamed + + + + m_txtPrimary + + + + 255 + 255 + 255 + + + + 4 + + + ClickFocus + + + + + + false + + + The currently set shortcut or the shortcut you are entering will show up here. + + + + + spacer5 + + + Horizontal + + + Expanding + + + + 21 + 20 + + + + + + + + m_btnClearPrimary + + + x + + + true + + + Clear shortcut + + + + + m_btnClearAlternate + + + x + + + true + + + Clear shortcut + + + + + m_btnMultiKey + + + NoFocus + + + Multi-key mode + + + Enable the entry of multi-key shortcuts + + + Select this checkbox to enable the entry of multi-key shortcuts. A multi-key shortcut consists of a sequence of up to 4 keys. For example, you could assign "Ctrl+F,B" to Font-Bold and "Ctrl+F,U" to Font-Underline. + + + + + + + + + m_txtPrimary + clicked() + m_btnPrimary + animateClick() + + + m_txtAlternate + clicked() + m_btnAlternate + animateClick() + + + + kshortcut.h + kdialog.h + kpushbutton.h + + + class TDEShortcut + + + + + kpushbutton.h + kpushbutton.h + + diff --git a/tdeui/tdeshortcutdialog_simple.ui b/tdeui/tdeshortcutdialog_simple.ui new file mode 100644 index 000000000..e271e2bd6 --- /dev/null +++ b/tdeui/tdeshortcutdialog_simple.ui @@ -0,0 +1,120 @@ + +TDEShortcutDialogSimple + + + TDEShortcutDialogSimple + + + + 0 + 0 + 177 + 36 + + + + + unnamed + + + 0 + + + + textLabel2 + + + Shortcut: + + + + + spacer3 + + + Vertical + + + Expanding + + + + 20 + 0 + + + + + + m_txtShortcut + + + + 255 + 255 + 255 + + + + 4 + + + ClickFocus + + + Alt+Tab + + + false + + + false + + + + + m_btnClearShortcut + + + x + + + true + + + Clear shortcut + + + + + spacer2 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + kshortcut.h + kdialog.h + kpushbutton.h + + + class TDEShortcut + + + + + kpushbutton.h + + diff --git a/tdeui/tdetoolbar.cpp b/tdeui/tdetoolbar.cpp new file mode 100644 index 000000000..71d182275 --- /dev/null +++ b/tdeui/tdetoolbar.cpp @@ -0,0 +1,2264 @@ +/* This file is part of the KDE libraries + Copyright + (C) 2000 Reginald Stadlbauer (reggie@kde.org) + (C) 1997, 1998 Stephan Kulow (coolo@kde.org) + (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) + (C) 1997, 1998 Sven Radej (radej@kde.org) + (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) + (C) 1999 Chris Schlaeger (cs@kde.org) + (C) 1999 Kurt Granroth (granroth@kde.org) + + 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. +*/ + +#include + +#ifdef KDE_USE_FINAL +#undef Always +#include +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + CONTEXT_TOP = 0, + CONTEXT_LEFT = 1, + CONTEXT_RIGHT = 2, + CONTEXT_BOTTOM = 3, + CONTEXT_FLOAT = 4, + CONTEXT_FLAT = 5, + CONTEXT_ICONS = 6, + CONTEXT_TEXT = 7, + CONTEXT_TEXTRIGHT = 8, + CONTEXT_TEXTUNDER = 9, + CONTEXT_ICONSIZES = 50 // starting point for the icon size list, put everything else before +}; + +class TDEToolBarPrivate +{ +public: + TDEToolBarPrivate() { + m_iconSize = 0; + m_iconText = TDEToolBar::IconOnly; + m_highlight = true; + m_transparent = true; + m_honorStyle = false; + + m_enableContext = true; + + m_xmlguiClient = 0; + + oldPos = TQt::DockUnmanaged; + + modified = m_isHorizontal = positioned = false; + + IconSizeDefault = 0; + IconTextDefault = "IconOnly"; + + NewLineDefault = false; + OffsetDefault = 0; + PositionDefault = "Top"; + HiddenDefault = false; + idleButtons.setAutoDelete(true); + } + + int m_iconSize; + TDEToolBar::IconText m_iconText; + bool m_highlight : 1; + bool m_transparent : 1; + bool m_honorStyle : 1; + bool m_isHorizontal : 1; + bool m_enableContext : 1; + bool modified : 1; + bool positioned : 1; + + TQWidget *m_parent; + + TQMainWindow::ToolBarDock oldPos; + + KXMLGUIClient *m_xmlguiClient; + + struct ToolBarInfo + { + ToolBarInfo() : index( -1 ), offset( -1 ), newline( false ), dock( TQt::DockTop ) {} + ToolBarInfo( TQt::Dock d, int i, bool n, int o ) : index( i ), offset( o ), newline( n ), dock( d ) {} + int index, offset; + bool newline; + TQt::Dock dock; + }; + + ToolBarInfo toolBarInfo; + TQValueList iconSizes; + TQTimer repaintTimer; + + // Default Values. + bool HiddenDefault; + int IconSizeDefault; + TQString IconTextDefault; + bool NewLineDefault; + int OffsetDefault; + TQString PositionDefault; + + TQPtrList idleButtons; +}; + +TDEToolBarSeparator::TDEToolBarSeparator(Orientation o , bool l, TQToolBar *parent, + const char* name ) + :TQFrame( parent, name ), line( l ) +{ + connect( parent, TQT_SIGNAL(orientationChanged(Orientation)), + this, TQT_SLOT(setOrientation(Orientation)) ); + setOrientation( o ); + setBackgroundMode( parent->backgroundMode() ); + setBackgroundOrigin( ParentOrigin ); +} + +void TDEToolBarSeparator::setOrientation( Orientation o ) +{ + orient = o; + setFrameStyle( NoFrame ); +} + +void TDEToolBarSeparator::drawContents( TQPainter* p ) +{ + if ( line ) { + TQStyle::SFlags flags = TQStyle::Style_Default; + + if ( orientation() == Qt::Horizontal ) + flags = flags | TQStyle::Style_Horizontal; + + style().tqdrawPrimitive(TQStyle::PE_DockWindowSeparator, p, + contentsRect(), colorGroup(), flags); + } else { + TQFrame::drawContents(p); + } +} + +void TDEToolBarSeparator::styleChange( TQStyle& ) +{ + setOrientation( orient ); +} + +TQSize TDEToolBarSeparator::sizeHint() const +{ + int dim = style().pixelMetric( TQStyle::PM_DockWindowSeparatorExtent, this ); + return orientation() == Qt::Vertical ? TQSize( 0, dim ) : TQSize( dim, 0 ); +} + +TQSizePolicy TDEToolBarSeparator::sizePolicy() const +{ + return TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ); +} + +TDEToolBar::TDEToolBar( TQWidget *parent, const char *name, bool honorStyle, bool readConfig ) + : TQToolBar( TQString::fromLatin1( name ), + tqt_dynamic_cast(parent), + parent, false, + name ? name : "mainToolBar") +{ + init( readConfig, honorStyle ); +} + +TDEToolBar::TDEToolBar( TQMainWindow *parentWindow, TQMainWindow::ToolBarDock dock, bool newLine, const char *name, bool honorStyle, bool readConfig ) + : TQToolBar( TQString::fromLatin1( name ), + parentWindow, dock, newLine, + name ? name : "mainToolBar") +{ + init( readConfig, honorStyle ); +} + +TDEToolBar::TDEToolBar( TQMainWindow *parentWindow, TQWidget *dock, bool newLine, const char *name, bool honorStyle, bool readConfig ) + : TQToolBar( TQString::fromLatin1( name ), + parentWindow, dock, newLine, + name ? name : "mainToolBar") +{ + init( readConfig, honorStyle ); +} + +TDEToolBar::~TDEToolBar() +{ + emit toolbarDestroyed(); + delete d; +} + +void TDEToolBar::init( bool readConfig, bool honorStyle ) +{ + d = new TDEToolBarPrivate; + setFullSize( true ); + d->m_honorStyle = honorStyle; + context = 0; + layoutTimer = new TQTimer( this ); + connect( layoutTimer, TQT_SIGNAL( timeout() ), + this, TQT_SLOT( rebuildLayout() ) ); + connect( &(d->repaintTimer), TQT_SIGNAL( timeout() ), + this, TQT_SLOT( slotRepaint() ) ); + + if ( kapp ) { // may be null when started inside designer + connect(kapp, TQT_SIGNAL(toolbarAppearanceChanged(int)), this, TQT_SLOT(slotAppearanceChanged())); + // request notification of changes in icon style + kapp->addKipcEventMask(KIPC::IconChanged); + connect(kapp, TQT_SIGNAL(iconChanged(int)), this, TQT_SLOT(slotIconChanged(int))); + } + + // finally, read in our configurable settings + if ( readConfig ) + slotReadConfig(); + + if ( mainWindow() ) + connect( mainWindow(), TQT_SIGNAL( toolBarPositionChanged( TQToolBar * ) ), + this, TQT_SLOT( toolBarPosChanged( TQToolBar * ) ) ); + + // Hack to make sure we recalculate our size when we dock. + connect( this, TQT_SIGNAL(placeChanged(TQDockWindow::Place)), TQT_SLOT(rebuildLayout()) ); +} + +int TDEToolBar::insertButton(const TQString& icon, int id, bool enabled, + const TQString& text, int index, TDEInstance *_instance ) +{ + TDEToolBarButton *button = new TDEToolBarButton( icon, id, this, 0, text, _instance ); + + insertWidgetInternal( button, index, id ); + button->setEnabled( enabled ); + doConnections( button ); + return index; +} + + +int TDEToolBar::insertButton(const TQString& icon, int id, const char *signal, + const TQObject *receiver, const char *slot, + bool enabled, const TQString& text, int index, TDEInstance *_instance ) +{ + TDEToolBarButton *button = new TDEToolBarButton( icon, id, this, 0, text, _instance); + insertWidgetInternal( button, index, id ); + button->setEnabled( enabled ); + connect( button, signal, receiver, slot ); + doConnections( button ); + return index; +} + + +int TDEToolBar::insertButton(const TQPixmap& pixmap, int id, bool enabled, + const TQString& text, int index ) +{ + TDEToolBarButton *button = new TDEToolBarButton( pixmap, id, this, 0, text); + insertWidgetInternal( button, index, id ); + button->setEnabled( enabled ); + doConnections( button ); + return index; +} + + +int TDEToolBar::insertButton(const TQPixmap& pixmap, int id, const char *signal, + const TQObject *receiver, const char *slot, + bool enabled, const TQString& text, + int index ) +{ + TDEToolBarButton *button = new TDEToolBarButton( pixmap, id, this, 0, text); + insertWidgetInternal( button, index, id ); + button->setEnabled( enabled ); + connect( button, signal, receiver, slot ); + doConnections( button ); + return index; +} + + +int TDEToolBar::insertButton(const TQString& icon, int id, TQPopupMenu *popup, + bool enabled, const TQString &text, int index ) +{ + TDEToolBarButton *button = new TDEToolBarButton( icon, id, this, 0, text ); + insertWidgetInternal( button, index, id ); + button->setEnabled( enabled ); + button->setPopup( popup ); + doConnections( button ); + return index; +} + + +int TDEToolBar::insertButton(const TQPixmap& pixmap, int id, TQPopupMenu *popup, + bool enabled, const TQString &text, int index ) +{ + TDEToolBarButton *button = new TDEToolBarButton( pixmap, id, this, 0, text ); + insertWidgetInternal( button, index, id ); + button->setEnabled( enabled ); + button->setPopup( popup ); + doConnections( button ); + return index; +} + + +int TDEToolBar::insertLined (const TQString& text, int id, + const char *signal, + const TQObject *receiver, const char *slot, + bool enabled , + const TQString& toolTipText, + int size, int index ) +{ + KLineEdit *lined = new KLineEdit ( this, 0 ); + if ( !toolTipText.isEmpty() ) + TQToolTip::add( lined, toolTipText ); + if ( size > 0 ) + lined->setMinimumWidth( size ); + insertWidgetInternal( lined, index, id ); + connect( lined, signal, receiver, slot ); + lined->setText(text); + lined->setEnabled( enabled ); + return index; +} + +int TDEToolBar::insertCombo (const TQStringList &list, int id, bool writable, + const char *signal, const TQObject *receiver, + const char *slot, bool enabled, + const TQString& tooltiptext, + int size, int index, + TQComboBox::Policy policy ) +{ + KComboBox *combo = new KComboBox ( writable, this ); + + insertWidgetInternal( combo, index, id ); + combo->insertStringList (list); + combo->setInsertionPolicy(policy); + combo->setEnabled( enabled ); + if ( size > 0 ) + combo->setMinimumWidth( size ); + if (!tooltiptext.isNull()) + TQToolTip::add( combo, tooltiptext ); + + if ( signal && receiver && slot ) + connect ( combo, signal, receiver, slot ); + return index; +} + + +int TDEToolBar::insertCombo (const TQString& text, int id, bool writable, + const char *signal, TQObject *receiver, + const char *slot, bool enabled, + const TQString& tooltiptext, + int size, int index, + TQComboBox::Policy policy ) +{ + KComboBox *combo = new KComboBox ( writable, this ); + insertWidgetInternal( combo, index, id ); + combo->insertItem (text); + combo->setInsertionPolicy(policy); + combo->setEnabled( enabled ); + if ( size > 0 ) + combo->setMinimumWidth( size ); + if (!tooltiptext.isNull()) + TQToolTip::add( combo, tooltiptext ); + connect (combo, signal, receiver, slot); + return index; +} + +int TDEToolBar::insertSeparator(int index, int id) +{ + TQWidget *w = new TDEToolBarSeparator( orientation(), false, this, "tool bar separator" ); + insertWidgetInternal( w, index, id ); + return index; +} + +int TDEToolBar::insertLineSeparator(int index, int id) +{ + TQWidget *w = new TDEToolBarSeparator( orientation(), true, this, "tool bar separator" ); + insertWidgetInternal( w, index, id ); + return index; +} + + +int TDEToolBar::insertWidget(int id, int /*width*/, TQWidget *widget, int index) +{ + removeWidgetInternal( widget ); // in case we already have it ? + insertWidgetInternal( widget, index, id ); + return index; +} + +int TDEToolBar::insertAnimatedWidget(int id, TQObject *receiver, const char *slot, + const TQString& icons, int index ) +{ + KAnimWidget *anim = new KAnimWidget( icons, d->m_iconSize, this ); + insertWidgetInternal( anim, index, id ); + + if ( receiver ) + connect( anim, TQT_SIGNAL(clicked()), receiver, slot); + + return index; +} + +KAnimWidget *TDEToolBar::animatedWidget( int id ) +{ + Id2WidgetMap::Iterator it = id2widget.find( id ); + if ( it == id2widget.end() ) + return 0; + KAnimWidget *aw = tqt_dynamic_cast(*it); + if ( aw ) + return aw; + TQObjectList *l = queryList( "KAnimWidget" ); + if ( !l || !l->first() ) { + delete l; + return 0; + } + + for ( TQObject *o = l->first(); o; o = l->next() ) { + KAnimWidget *aw = tqt_dynamic_cast(o); + if ( aw ) + { + delete l; + return aw; + } + } + + delete l; + return 0; +} + + +void TDEToolBar::addConnection (int id, const char *signal, + const TQObject *receiver, const char *slot) +{ + TQWidget* w = getWidget( id ); + if ( w ) + connect( w, signal, receiver, slot ); +} + +void TDEToolBar::setItemEnabled( int id, bool enabled ) +{ + TQWidget* w = getWidget( id ); + if ( w ) + w->setEnabled( enabled ); +} + + +void TDEToolBar::setButtonPixmap( int id, const TQPixmap& _pixmap ) +{ + TDEToolBarButton * button = getButton( id ); + if ( button ) + button->setPixmap( _pixmap ); +} + + +void TDEToolBar::setButtonIcon( int id, const TQString& _icon ) +{ + TDEToolBarButton * button = getButton( id ); + if ( button ) + button->setIcon( _icon ); +} + +void TDEToolBar::setButtonIconSet( int id, const TQIconSet& iconset ) +{ + TDEToolBarButton * button = getButton( id ); + if ( button ) + button->setIconSet( iconset ); +} + + +void TDEToolBar::setDelayedPopup (int id , TQPopupMenu *_popup, bool toggle ) +{ + TDEToolBarButton * button = getButton( id ); + if ( button ) + button->setDelayedPopup( _popup, toggle ); +} + + +void TDEToolBar::setAutoRepeat (int id, bool flag) +{ + TDEToolBarButton * button = getButton( id ); + if ( button ) + button->setAutoRepeat( flag ); +} + + +void TDEToolBar::setToggle (int id, bool flag ) +{ + TDEToolBarButton * button = getButton( id ); + if ( button ) + button->setToggle( flag ); +} + + +void TDEToolBar::toggleButton (int id) +{ + TDEToolBarButton * button = getButton( id ); + if ( button ) + button->toggle(); +} + + +void TDEToolBar::setButton (int id, bool flag) +{ + TDEToolBarButton * button = getButton( id ); + if ( button ) + button->on( flag ); +} + + +bool TDEToolBar::isButtonOn (int id) const +{ + TDEToolBarButton * button = const_cast( this )->getButton( id ); + return button ? button->isOn() : false; +} + + +void TDEToolBar::setLinedText (int id, const TQString& text) +{ + KLineEdit * lineEdit = getLined( id ); + if ( lineEdit ) + lineEdit->setText( text ); +} + + +TQString TDEToolBar::getLinedText (int id) const +{ + KLineEdit * lineEdit = const_cast( this )->getLined( id ); + return lineEdit ? lineEdit->text() : TQString::null; +} + + +void TDEToolBar::insertComboItem (int id, const TQString& text, int index) +{ + KComboBox * comboBox = getCombo( id ); + if (comboBox) + comboBox->insertItem( text, index ); +} + +void TDEToolBar::insertComboList (int id, const TQStringList &list, int index) +{ + KComboBox * comboBox = getCombo( id ); + if (comboBox) + comboBox->insertStringList( list, index ); +} + + +void TDEToolBar::removeComboItem (int id, int index) +{ + KComboBox * comboBox = getCombo( id ); + if (comboBox) + comboBox->removeItem( index ); +} + + +void TDEToolBar::setCurrentComboItem (int id, int index) +{ + KComboBox * comboBox = getCombo( id ); + if (comboBox) + comboBox->setCurrentItem( index ); +} + + +void TDEToolBar::changeComboItem (int id, const TQString& text, int index) +{ + KComboBox * comboBox = getCombo( id ); + if (comboBox) + comboBox->changeItem( text, index ); +} + + +void TDEToolBar::clearCombo (int id) +{ + KComboBox * comboBox = getCombo( id ); + if (comboBox) + comboBox->clear(); +} + + +TQString TDEToolBar::getComboItem (int id, int index) const +{ + KComboBox * comboBox = const_cast( this )->getCombo( id ); + return comboBox ? comboBox->text( index ) : TQString::null; +} + + +KComboBox * TDEToolBar::getCombo(int id) +{ + Id2WidgetMap::Iterator it = id2widget.find( id ); + if ( it == id2widget.end() ) + return 0; + return tqt_dynamic_cast( *it ); +} + + +KLineEdit * TDEToolBar::getLined (int id) +{ + Id2WidgetMap::Iterator it = id2widget.find( id ); + if ( it == id2widget.end() ) + return 0; + return tqt_dynamic_cast( *it ); +} + + +TDEToolBarButton * TDEToolBar::getButton (int id) +{ + Id2WidgetMap::Iterator it = id2widget.find( id ); + if ( it == id2widget.end() ) + return 0; + return tqt_dynamic_cast( *it ); +} + + +void TDEToolBar::alignItemRight (int id, bool right ) +{ + Id2WidgetMap::Iterator it = id2widget.find( id ); + if ( it == id2widget.end() ) + return; + if ( rightAligned && !right && (*it) == rightAligned ) + rightAligned = 0; + if ( (*it) && right ) + rightAligned = (*it); +} + + +TQWidget *TDEToolBar::getWidget (int id) +{ + Id2WidgetMap::Iterator it = id2widget.find( id ); + return ( it == id2widget.end() ) ? 0 : (*it); +} + + +void TDEToolBar::setItemAutoSized (int id, bool yes ) +{ + TQWidget *w = getWidget(id); + if ( w && yes ) + setStretchableWidget( w ); +} + + +void TDEToolBar::clear () +{ + /* Delete any idle buttons, so TQToolBar doesn't delete them itself, making a mess */ + for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next()) + w->blockSignals(false); + d->idleButtons.clear(); + + TQToolBar::clear(); + widget2id.clear(); + id2widget.clear(); +} + + +void TDEToolBar::removeItem(int id) +{ + Id2WidgetMap::Iterator it = id2widget.find( id ); + if ( it == id2widget.end() ) + { + kdDebug(220) << name() << " TDEToolBar::removeItem item " << id << " not found" << endl; + return; + } + TQWidget * w = (*it); + id2widget.remove( id ); + widget2id.remove( w ); + widgets.removeRef( w ); + delete w; +} + + +void TDEToolBar::removeItemDelayed(int id) +{ + Id2WidgetMap::Iterator it = id2widget.find( id ); + if ( it == id2widget.end() ) + { + kdDebug(220) << name() << " TDEToolBar::removeItem item " << id << " not found" << endl; + return; + } + TQWidget * w = (*it); + id2widget.remove( id ); + widget2id.remove( w ); + widgets.removeRef( w ); + + w->blockSignals(true); + d->idleButtons.append(w); + layoutTimer->start( 50, true ); +} + + +void TDEToolBar::hideItem (int id) +{ + TQWidget *w = getWidget(id); + if ( w ) + w->hide(); +} + + +void TDEToolBar::showItem (int id) +{ + TQWidget *w = getWidget(id); + if ( w ) + w->show(); +} + + +int TDEToolBar::itemIndex (int id) +{ + TQWidget *w = getWidget(id); + return w ? widgets.findRef(w) : -1; +} + +int TDEToolBar::idAt (int index) +{ + TQWidget *w = widgets.at(index); + return widget2id[w]; +} + +void TDEToolBar::setFullSize(bool flag ) +{ + setHorizontalStretchable( flag ); + setVerticalStretchable( flag ); +} + + +bool TDEToolBar::fullSize() const +{ + return isHorizontalStretchable() || isVerticalStretchable(); +} + + +void TDEToolBar::enableMoving(bool flag ) +{ + setMovingEnabled(flag); +} + + +void TDEToolBar::setBarPos (BarPosition bpos) +{ + if ( !mainWindow() ) + return; + mainWindow()->moveDockWindow( this, (Dock)bpos ); + //kdDebug(220) << name() << " setBarPos dockWindowIndex=" << dockWindowIndex() << endl; +} + + +TDEToolBar::BarPosition TDEToolBar::barPos() const +{ + if ( !this->mainWindow() ) + return place() == TQDockWindow::InDock ? TDEToolBar::Top : TDEToolBar::Floating; + Dock dock; + int dm1, dm2; + bool dm3; + this->mainWindow()->getLocation( (TQToolBar*)this, dock, dm1, dm3, dm2 ); + if ( dock == DockUnmanaged ) { + return (TDEToolBar::BarPosition)DockTop; + } + return (BarPosition)dock; +} + + +bool TDEToolBar::enable(BarStatus stat) +{ + bool mystat = isVisible(); + + if ( (stat == Toggle && mystat) || stat == Hide ) + hide(); + else + show(); + + return isVisible() == mystat; +} + + +void TDEToolBar::setMaxHeight ( int h ) +{ + setMaximumHeight( h ); +} + +int TDEToolBar::maxHeight() +{ + return maximumHeight(); +} + + +void TDEToolBar::setMaxWidth (int dw) +{ + setMaximumWidth( dw ); +} + + +int TDEToolBar::maxWidth() +{ + return maximumWidth(); +} + + +void TDEToolBar::setTitle (const TQString& _title) +{ + setLabel( _title ); +} + + +void TDEToolBar::enableFloating (bool ) +{ +} + + +void TDEToolBar::setIconText(IconText it) +{ + setIconText( it, true ); +} + + +void TDEToolBar::setIconText(IconText icontext, bool update) +{ + bool doUpdate=false; + + if (icontext != d->m_iconText) { + d->m_iconText = icontext; + doUpdate=true; + //kdDebug(220) << name() << " icontext has changed, doUpdate=true" << endl; + } + else { + //kdDebug(220) << name() << " icontext hasn't changed, doUpdate=false" << endl; + } + + if (!update) + return; + + if (doUpdate) + doModeChange(); // tell buttons what happened + + // ugly hack to force a TQMainWindow::triggerLayout( true ) + TQMainWindow *mw = mainWindow(); + if ( mw ) { + mw->setUpdatesEnabled( false ); +// mw->setToolBarsMovable( !mw->toolBarsMovable() ); // Old way +// mw->setToolBarsMovable( !mw->toolBarsMovable() ); + mw->setCentralWidget(mw->centralWidget()); // This is a faster hack + mw->setUpdatesEnabled( true ); + } +} + + +TDEToolBar::IconText TDEToolBar::iconText() const +{ + return d->m_iconText; +} + + +void TDEToolBar::setIconSize(int size) +{ + setIconSize( size, true ); +} + +void TDEToolBar::setIconSize(int size, bool update) +{ + bool doUpdate=false; + + if ( size != d->m_iconSize ) { + d->m_iconSize = size; + doUpdate=true; + } + + if (!update) + return; + + if (doUpdate) + doModeChange(); // tell buttons what happened + + // ugly hack to force a TQMainWindow::triggerLayout( true ) + if ( mainWindow() ) { + TQMainWindow *mw = mainWindow(); + mw->setUpdatesEnabled( false ); +// mw->setToolBarsMovable( !mw->toolBarsMovable() ); // Old way +// mw->setToolBarsMovable( !mw->toolBarsMovable() ); + mw->setCentralWidget(mw->centralWidget()); // This is a faster hack + mw->setUpdatesEnabled( true ); + } +} + +int TDEToolBar::iconSize() const +{ + if ( !d->m_iconSize ) // default value? + return iconSizeDefault(); + + return d->m_iconSize; +} + +int TDEToolBar::iconSizeDefault() const +{ + if (!::qstrcmp(name(), "mainToolBar")) + return TDEGlobal::iconLoader()->currentSize(KIcon::MainToolbar); + + return TDEGlobal::iconLoader()->currentSize(KIcon::Toolbar); +} + +void TDEToolBar::setEnableContextMenu(bool enable ) +{ + d->m_enableContext = enable; +} + + +bool TDEToolBar::contextMenuEnabled() const +{ + return d->m_enableContext; +} + + +void TDEToolBar::setItemNoStyle(int id, bool no_style ) +{ + TDEToolBarButton * button = getButton( id ); + if (button) + button->setNoStyle( no_style ); +} + + +void TDEToolBar::setFlat (bool flag) +{ + if ( !mainWindow() ) + return; + if ( flag ) + mainWindow()->moveDockWindow( this, DockMinimized ); + else + mainWindow()->moveDockWindow( this, DockTop ); + // And remember to save the new look later + TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); + if ( kmw ) + kmw->setSettingsDirty(); +} + + +int TDEToolBar::count() const +{ + return id2widget.count(); +} + + +void TDEToolBar::saveState() +{ + // first, try to save to the xml file + if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() ) { + //kdDebug(220) << name() << " saveState: saving to " << d->m_xmlguiClient->xmlFile() << endl; + TQString barname(!::qstrcmp(name(), "unnamed") ? "mainToolBar" : name()); + // try to find our toolbar + d->modified = false; + // go down one level to get to the right tags + TQDomElement current; + for( TQDomNode n = d->m_xmlguiClient->domDocument().documentElement().firstChild(); + !n.isNull(); n = n.nextSibling()) { + current = n.toElement(); + + if ( current.tagName().lower() != "toolbar" ) + continue; + + TQString curname(current.attribute( "name" )); + + if ( curname == barname ) { + saveState( current ); + break; + } + } + // if we didn't make changes, then just return + if ( !d->modified ) + return; + + // now we load in the (non-merged) local file + TQString local_xml(KXMLGUIFactory::readConfigFile(d->m_xmlguiClient->xmlFile(), true, d->m_xmlguiClient->instance())); + TQDomDocument local; + local.setContent(local_xml); + + // make sure we don't append if this toolbar already exists locally + bool just_append = true; + + for( TQDomNode n = local.documentElement().firstChild(); + !n.isNull(); n = n.nextSibling()) { + TQDomElement elem = n.toElement(); + + if ( elem.tagName().lower() != "toolbar" ) + continue; + + TQString curname(elem.attribute( "name" )); + + if ( curname == barname ) { + just_append = false; + local.documentElement().replaceChild( current, elem ); + break; + } + } + + if (just_append) + local.documentElement().appendChild( current ); + + KXMLGUIFactory::saveConfigFile(local, d->m_xmlguiClient->localXMLFile(), d->m_xmlguiClient->instance() ); + + return; + } + + // if that didn't work, we save to the config file + TDEConfig *config = TDEGlobal::config(); + saveSettings(config, TQString::null); + config->sync(); +} + +TQString TDEToolBar::settingsGroup() const +{ + TQString configGroup; + if (!::qstrcmp(name(), "unnamed") || !::qstrcmp(name(), "mainToolBar")) + configGroup = "Toolbar style"; + else + configGroup = TQString(name()) + " Toolbar style"; + if ( this->mainWindow() ) + { + configGroup.prepend(" "); + configGroup.prepend( this->mainWindow()->name() ); + } + return configGroup; +} + +void TDEToolBar::saveSettings(TDEConfig *config, const TQString &_configGroup) +{ + TQString configGroup = _configGroup; + if (configGroup.isEmpty()) + configGroup = settingsGroup(); + //kdDebug(220) << name() << " saveSettings() group=" << _configGroup << " -> " << configGroup << endl; + + TQString position, icontext; + int index; + getAttributes( position, icontext, index ); + + //kdDebug(220) << name() << " position=" << position << " index=" << index << " offset=" << offset() << " newLine=" << newLine() << endl; + + TDEConfigGroupSaver saver(config, configGroup); + + if(!config->hasDefault("Position") && position == d->PositionDefault ) + config->revertToDefault("Position"); + else + config->writeEntry("Position", position); + + //kdDebug(220) << name() << " icontext=" << icontext << " hasDefault:" << config->hasDefault( "IconText" ) << " d->IconTextDefault=" << d->IconTextDefault << endl; + + if(d->m_honorStyle && icontext == d->IconTextDefault && !config->hasDefault("IconText") ) + { + //kdDebug(220) << name() << " reverting icontext to default" << endl; + config->revertToDefault("IconText"); + } + else + { + //kdDebug(220) << name() << " writing icontext " << icontext << endl; + config->writeEntry("IconText", icontext); + } + + if(!config->hasDefault("IconSize") && iconSize() == iconSizeDefault() ) + config->revertToDefault("IconSize"); + else + config->writeEntry("IconSize", iconSize()); + + if(!config->hasDefault("Hidden") && isHidden() == d->HiddenDefault ) + config->revertToDefault("Hidden"); + else + config->writeEntry("Hidden", isHidden()); + + // Note that index, unlike the other settings, depends on the other toolbars + // So on the first run with a clean local config file, even the usual + // hasDefault/==IndexDefault test would save the toolbar indexes + // (IndexDefault was 0, whereas index is the real index in the GUI) + // + // Saving the whole set of indexes is necessary though. When moving only + // one toolbar, if we only saved the changed indexes, the toolbars wouldn't + // reappear at the same position the next time. + // The whole set of indexes has to be saved. + //kdDebug(220) << name() << " writing index " << index << endl; + TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); + // don't save if there's only one toolbar + + // Don't use kmw->toolBarIterator() because you might + // mess up someone else's iterator. Make the list on your own + TQPtrList toolbarList; + TQPtrList lst; + for ( int i = (int)TQMainWindow::DockUnmanaged; i <= (int)DockMinimized; ++i ) { + lst = kmw->toolBars( (ToolBarDock)i ); + for ( TQToolBar *tb = lst.first(); tb; tb = lst.next() ) { + if ( !tb->inherits( "TDEToolBar" ) ) + continue; + toolbarList.append( (TDEToolBar*)tb ); + } + } + TQPtrListIterator toolbarIterator( toolbarList ); + if ( !kmw || toolbarIterator.count() > 1 ) + config->writeEntry("Index", index); + else + config->revertToDefault("Index"); + + if(!config->hasDefault("Offset") && offset() == d->OffsetDefault ) + config->revertToDefault("Offset"); + else + config->writeEntry("Offset", offset()); + + if(!config->hasDefault("NewLine") && newLine() == d->NewLineDefault ) + config->revertToDefault("NewLine"); + else + config->writeEntry("NewLine", newLine()); +} + + +void TDEToolBar::setXMLGUIClient( KXMLGUIClient *client ) +{ + d->m_xmlguiClient = client; +} + +void TDEToolBar::setText( const TQString & txt ) +{ + setLabel( txt + " (" + kapp->caption() + ") " ); +} + + +TQString TDEToolBar::text() const +{ + return label(); +} + + +void TDEToolBar::doConnections( TDEToolBarButton *button ) +{ + connect(button, TQT_SIGNAL(clicked(int)), this, TQT_SIGNAL( clicked( int ) ) ); + connect(button, TQT_SIGNAL(doubleClicked(int)), this, TQT_SIGNAL( doubleClicked( int ) ) ); + connect(button, TQT_SIGNAL(released(int)), this, TQT_SIGNAL( released( int ) ) ); + connect(button, TQT_SIGNAL(pressed(int)), this, TQT_SIGNAL( pressed( int ) ) ); + connect(button, TQT_SIGNAL(toggled(int)), this, TQT_SIGNAL( toggled( int ) ) ); + connect(button, TQT_SIGNAL(highlighted(int, bool)), this, TQT_SIGNAL( highlighted( int, bool ) ) ); +} + +void TDEToolBar::mousePressEvent ( TQMouseEvent *m ) +{ + if ( !mainWindow() ) + return; + TQMainWindow *mw = mainWindow(); + if ( mw->toolBarsMovable() && d->m_enableContext ) { + if ( m->button() == Qt::RightButton ) { + TQGuardedPtr guard( this ); + int i = contextMenu()->exec( m->globalPos(), 0 ); + // "Configure Toolbars" recreates toolbars, so we might not exist anymore. + if ( guard ) + slotContextAboutToHide(); + switch ( i ) { + case -1: + return; // popup canceled + case CONTEXT_LEFT: + mw->moveDockWindow( this, DockLeft ); + break; + case CONTEXT_RIGHT: + mw->moveDockWindow( this, DockRight ); + break; + case CONTEXT_TOP: + mw->moveDockWindow( this, DockTop ); + break; + case CONTEXT_BOTTOM: + mw->moveDockWindow( this, DockBottom ); + break; + case CONTEXT_FLOAT: + mw->moveDockWindow( this, DockTornOff ); + break; + case CONTEXT_FLAT: + mw->moveDockWindow( this, DockMinimized ); + break; + case CONTEXT_ICONS: + setIconText( IconOnly ); + break; + case CONTEXT_TEXTRIGHT: + setIconText( IconTextRight ); + break; + case CONTEXT_TEXT: + setIconText( TextOnly ); + break; + case CONTEXT_TEXTUNDER: + setIconText( IconTextBottom ); + break; + default: + if ( i >= CONTEXT_ICONSIZES ) + setIconSize( i - CONTEXT_ICONSIZES ); + else + return; // assume this was an action handled elsewhere, no need for setSettingsDirty() + } + TDEMainWindow *kmw = tqt_dynamic_cast(mw); + if ( kmw ) + kmw->setSettingsDirty(); + } + } +} + +void TDEToolBar::doModeChange() +{ + for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next()) + w->blockSignals(false); + d->idleButtons.clear(); + + emit modechange(); +} + +void TDEToolBar::rebuildLayout() +{ + for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next()) + w->blockSignals(false); + d->idleButtons.clear(); + + layoutTimer->stop(); + TQApplication::sendPostedEvents( this, TQEvent::ChildInserted ); + TQBoxLayout *l = boxLayout(); + + // clear the old layout + TQLayoutIterator it = l->iterator(); + while ( it.current() ) + it.deleteCurrent(); + + for ( TQWidget *w = widgets.first(); w; w = widgets.next() ) { + if ( w == rightAligned ) + continue; + TDEToolBarSeparator *ktbs = tqt_dynamic_cast(w); + if ( ktbs && !ktbs->showLine() ) { + l->addSpacing( orientation() == Qt::Vertical ? w->sizeHint().height() : w->sizeHint().width() ); + w->hide(); + continue; + } + if ( tqt_dynamic_cast(w) ) // w is a QPopupMenu? + continue; + l->addWidget( w ); + w->show(); + if ((orientation() == Qt::Horizontal) && tqt_dynamic_cast(w)) // w is TQLineEdit ? + l->addSpacing(2); // A little bit extra spacing behind it. + } + if ( rightAligned ) { + l->addStretch(); + l->addWidget( rightAligned ); + rightAligned->show(); + } + + if ( fullSize() ) { + if ( !rightAligned ) + l->addStretch(); + if ( stretchableWidget ) + l->setStretchFactor( stretchableWidget, 10 ); + } + l->invalidate(); + TQApplication::postEvent( this, new TQEvent( TQEvent::LayoutHint ) ); +} + +void TDEToolBar::childEvent( TQChildEvent *e ) +{ + if ( e->child()->isWidgetType() ) { + TQWidget * w = tqt_dynamic_cast(e->child()); + if (!w || !(::qstrcmp( "qt_dockwidget_internal", w->name()))) + { + TQToolBar::childEvent( e ); + return; + } + if ( e->type() == TQEvent::ChildInserted ) { + if ( !tqt_dynamic_cast(w)) { // e->child() is not a QPopupMenu + // prevent items that have been explicitly inserted by insert*() from + // being inserted again + if ( !widget2id.contains( w ) ) + { + int dummy = -1; + insertWidgetInternal( w, dummy, -1 ); + } + } + } else { + removeWidgetInternal( w ); + } + if ( isVisibleTo( 0 ) ) + { + layoutTimer->start( 50, true ); + TQBoxLayout *l = boxLayout(); + + // clear the old layout so that we don't get unnecessary layout + // changes until we have rebuilt the thing + TQLayoutIterator it = l->iterator(); + while ( it.current() ) + it.deleteCurrent(); + } + } + TQToolBar::childEvent( e ); +} + +void TDEToolBar::insertWidgetInternal( TQWidget *w, int &index, int id ) +{ + // we can't have it in widgets, or something is really wrong + //widgets.removeRef( w ); + + connect( w, TQT_SIGNAL( destroyed() ), + this, TQT_SLOT( widgetDestroyed() ) ); + if ( index == -1 || index > (int)widgets.count() ) { + index = (int)widgets.count(); + widgets.append( w ); + } + else + widgets.insert( index, w ); + if ( id == -1 ) + id = id2widget.count(); + id2widget.insert( id, w ); + widget2id.insert( w, id ); +} + +void TDEToolBar::showEvent( TQShowEvent *e ) +{ + TQToolBar::showEvent( e ); + rebuildLayout(); +} + +void TDEToolBar::setStretchableWidget( TQWidget *w ) +{ + TQToolBar::setStretchableWidget( w ); + stretchableWidget = w; +} + +TQSizePolicy TDEToolBar::sizePolicy() const +{ + if ( orientation() == Qt::Horizontal ) + return TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ); + else + return TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Expanding ); +} + +TQSize TDEToolBar::sizeHint() const +{ + TQSize minSize(0,0); + TDEToolBar *ncThis = const_cast(this); + + ncThis->polish(); + + int margin = static_cast(ncThis)->layout()->margin() + frameWidth(); + switch( barPos() ) + { + case TDEToolBar::Top: + case TDEToolBar::Bottom: + for ( TQWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() ) + { + TQSize sh = w->sizeHint(); + if ( w->sizePolicy().horData() == TQSizePolicy::Ignored ) + sh.setWidth( 1 ); + if ( w->sizePolicy().verData() == TQSizePolicy::Ignored ) + sh.setHeight( 1 ); + sh = sh.boundedTo( w->maximumSize() ) + .expandedTo( w->minimumSize() ).expandedTo( TQSize(1, 1) ); + + minSize = minSize.expandedTo(TQSize(0, sh.height())); + minSize += TQSize(sh.width()+1, 0); + if (tqt_dynamic_cast(w)) // w is a TQLineEdit ? + minSize += TQSize(2, 0); // A little bit extra spacing behind it. + } + + minSize += TQSize(TQApplication::style().pixelMetric( TQStyle::PM_DockWindowHandleExtent ), 0); + minSize += TQSize(margin*2, margin*2); + break; + + case TDEToolBar::Left: + case TDEToolBar::Right: + for ( TQWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() ) + { + TQSize sh = w->sizeHint(); + if ( w->sizePolicy().horData() == TQSizePolicy::Ignored ) + sh.setWidth( 1 ); + if ( w->sizePolicy().verData() == TQSizePolicy::Ignored ) + sh.setHeight( 1 ); + sh = sh.boundedTo( w->maximumSize() ) + .expandedTo( w->minimumSize() ).expandedTo( TQSize(1, 1) ); + + minSize = minSize.expandedTo(TQSize(sh.width(), 0)); + minSize += TQSize(0, sh.height()+1); + } + minSize += TQSize(0, TQApplication::style().pixelMetric( TQStyle::PM_DockWindowHandleExtent )); + minSize += TQSize(margin*2, margin*2); + break; + + default: + minSize = TQToolBar::sizeHint(); + break; + } + return minSize; +} + +TQSize TDEToolBar::minimumSize() const +{ + return minimumSizeHint(); +} + +TQSize TDEToolBar::minimumSizeHint() const +{ + return sizeHint(); +} + +bool TDEToolBar::highlight() const +{ + return d->m_highlight; +} + +void TDEToolBar::hide() +{ + TQToolBar::hide(); +} + +void TDEToolBar::show() +{ + TQToolBar::show(); +} + +void TDEToolBar::resizeEvent( TQResizeEvent *e ) +{ + bool b = isUpdatesEnabled(); + setUpdatesEnabled( false ); + TQToolBar::resizeEvent( e ); + if (b) + { + if (layoutTimer->isActive()) + { + // Wait with repainting till layout is complete. + d->repaintTimer.start( 100, true ); + } + else + { + // Repaint now + slotRepaint(); + } + } +// else { +// printf("[WARNING] In TDEToolBar::resizeEvent, but this code block should not be executing. Preventing toolbar lockup. [Code 0045]\n\r"); +// setUpdatesEnabled( true ); +// } +} + +void TDEToolBar::slotIconChanged(int group) +{ + if ((group != KIcon::Toolbar) && (group != KIcon::MainToolbar)) + return; + if ((group == KIcon::MainToolbar) != !::qstrcmp(name(), "mainToolBar")) + return; + + doModeChange(); + + if (isVisible()) + updateGeometry(); +} + +void TDEToolBar::slotReadConfig() +{ + //kdDebug(220) << name() << " slotReadConfig" << endl; + // Read appearance settings (hmm, we used to do both here, + // but a well behaved application will call applyMainWindowSettings + // anyway, right ?) + applyAppearanceSettings(TDEGlobal::config(), TQString::null ); +} + +void TDEToolBar::slotAppearanceChanged() +{ + // Read appearance settings from global file. + applyAppearanceSettings(TDEGlobal::config(), TQString::null, true /* lose local settings */ ); + + // And remember to save the new look later + TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); + if ( kmw ) + kmw->setSettingsDirty(); +} + +//static +bool TDEToolBar::highlightSetting() +{ + TQString grpToolbar(TQString::fromLatin1("Toolbar style")); + TDEConfigGroupSaver saver(TDEGlobal::config(), grpToolbar); + return TDEGlobal::config()->readBoolEntry(TQString::fromLatin1("Highlighting"),true); +} + +//static +bool TDEToolBar::transparentSetting() +{ + TQString grpToolbar(TQString::fromLatin1("Toolbar style")); + TDEConfigGroupSaver saver(TDEGlobal::config(), grpToolbar); + return TDEGlobal::config()->readBoolEntry(TQString::fromLatin1("TransparentMoving"),true); +} + +//static +TDEToolBar::IconText TDEToolBar::iconTextSetting() +{ + TQString grpToolbar(TQString::fromLatin1("Toolbar style")); + TDEConfigGroupSaver saver(TDEGlobal::config(), grpToolbar); + TQString icontext = TDEGlobal::config()->readEntry(TQString::fromLatin1("IconText"),TQString::fromLatin1("IconOnly")); + if ( icontext == "IconTextRight" ) + return IconTextRight; + else if ( icontext == "IconTextBottom" ) + return IconTextBottom; + else if ( icontext == "TextOnly" ) + return TextOnly; + else + return IconOnly; +} + +void TDEToolBar::applyAppearanceSettings(TDEConfig *config, const TQString &_configGroup, bool forceGlobal) +{ + TQString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup; + //kdDebug(220) << name() << " applyAppearanceSettings: configGroup=" << configGroup << " forceGlobal=" << forceGlobal << endl; + + // If we have application-specific settings in the XML file, + // and nothing in the application's config file, then + // we don't apply the global defaults, the XML ones are preferred + // (see applySettings for a full explanation) + // This is the reason for the xmlgui tests below. + bool xmlgui = d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty(); + + TDEConfig *gconfig = TDEGlobal::config(); + + static const TQString &attrIconText = TDEGlobal::staticQString("IconText"); + static const TQString &attrHighlight = TDEGlobal::staticQString("Highlighting"); + static const TQString &attrTrans = TDEGlobal::staticQString("TransparentMoving"); + static const TQString &attrIconSize = TDEGlobal::staticQString("IconSize"); + + // we actually do this in two steps. + // First, we read in the global styles [Toolbar style] (from the KControl module). + // Then, if the toolbar is NOT 'mainToolBar', we will also try to read in [barname Toolbar style] + bool highlight; + int transparent; + bool applyIconText = !xmlgui; // if xmlgui is used, global defaults won't apply + bool applyIconSize = !xmlgui; + + int iconSize = d->IconSizeDefault; + TQString iconText = d->IconTextDefault; + + // this is the first iteration + TQString grpToolbar(TQString::fromLatin1("Toolbar style")); + { // start block for TDEConfigGroupSaver + TDEConfigGroupSaver saver(gconfig, grpToolbar); + + // first, get the generic settings + highlight = gconfig->readBoolEntry(attrHighlight, true); + transparent = gconfig->readBoolEntry(attrTrans, true); + + // we read in the IconText property *only* if we intend on actually + // honoring it + if (d->m_honorStyle) + d->IconTextDefault = gconfig->readEntry(attrIconText, d->IconTextDefault); + else + d->IconTextDefault = "IconOnly"; + + // Use the default icon size for toolbar icons. + d->IconSizeDefault = gconfig->readNumEntry(attrIconSize, d->IconSizeDefault); + + iconSize = d->IconSizeDefault; + iconText = d->IconTextDefault; + + if ( !forceGlobal && config->hasGroup(configGroup) ) + { + config->setGroup(configGroup); + + // first, get the generic settings + highlight = config->readBoolEntry(attrHighlight, highlight); + transparent = config->readBoolEntry(attrTrans, transparent); + + // read in the IconText property + if ( config->hasKey( attrIconText ) ) { + iconText = config->readEntry(attrIconText); + applyIconText = true; + //kdDebug(220) << name() << " read icontext=" << d->IconTextDefault << ", that will be the default" << endl; + } + + // now get the size + if ( config->hasKey( attrIconSize ) ) { + iconSize = config->readNumEntry(attrIconSize); + applyIconSize = true; + } + } + + // revert back to the old group + } // end block for TDEConfigGroupSaver + + bool doUpdate = false; + + IconText icon_text; + if ( iconText == "IconTextRight" ) + icon_text = IconTextRight; + else if ( iconText == "IconTextBottom" ) + icon_text = IconTextBottom; + else if ( iconText == "TextOnly" ) + icon_text = TextOnly; + else + icon_text = IconOnly; + + // check if the icon/text has changed + if (icon_text != d->m_iconText && applyIconText) { + //kdDebug(220) << name() << " applyAppearanceSettings setIconText " << icon_text << endl; + setIconText(icon_text, false); + doUpdate = true; + } + + // ...and check if the icon size has changed + if (iconSize != d->m_iconSize && applyIconSize) { + setIconSize(iconSize, false); + doUpdate = true; + } + + TQMainWindow *mw = mainWindow(); + + // ...and if we should highlight + if ( highlight != d->m_highlight ) { + d->m_highlight = highlight; + doUpdate = true; + } + + // ...and if we should move transparently + if ( mw && transparent != (!mw->opaqueMoving()) ) { + mw->setOpaqueMoving( !transparent ); + } + + if (doUpdate) + doModeChange(); // tell buttons what happened + + if (isVisible ()) + updateGeometry(); +} + +void TDEToolBar::applySettings(TDEConfig *config, const TQString &_configGroup) +{ + return applySettings(config,_configGroup,false); +} + +void TDEToolBar::applySettings(TDEConfig *config, const TQString &_configGroup, bool force) +{ + //kdDebug(220) << name() << " applySettings group=" << _configGroup << endl; + + TQString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup; + + /* + Let's explain this a bit more in details. + The order in which we apply settings is : + Global config / user settings if no XMLGUI is used + Global config / App-XML attributes / user settings if XMLGUI is used + + So in the first case, we simply read everything from TDEConfig as below, + but in the second case we don't do anything here if there is no app-specific config, + and the XMLGUI-related code (loadState()) uses the static methods of this class + to get the global defaults. + + Global config doesn't include position (index, offset, newline and hidden/shown). + */ + + // First the appearance stuff - the one which has a global config + applyAppearanceSettings( config, configGroup ); + + // ...and now the position stuff + if ( config->hasGroup(configGroup) || force ) + { + TDEConfigGroupSaver cgs(config, configGroup); + + static const TQString &attrPosition = TDEGlobal::staticQString("Position"); + static const TQString &attrIndex = TDEGlobal::staticQString("Index"); + static const TQString &attrOffset = TDEGlobal::staticQString("Offset"); + static const TQString &attrNewLine = TDEGlobal::staticQString("NewLine"); + static const TQString &attrHidden = TDEGlobal::staticQString("Hidden"); + + TQString position = config->readEntry(attrPosition, d->PositionDefault); + int index = config->readNumEntry(attrIndex, -1); + int offset = config->readNumEntry(attrOffset, d->OffsetDefault); + bool newLine = config->readBoolEntry(attrNewLine, d->NewLineDefault); + bool hidden = config->readBoolEntry(attrHidden, d->HiddenDefault); + + Dock pos(DockTop); + if ( position == "Top" ) + pos = DockTop; + else if ( position == "Bottom" ) + pos = DockBottom; + else if ( position == "Left" ) + pos = DockLeft; + else if ( position == "Right" ) + pos = DockRight; + else if ( position == "Floating" ) + pos = DockTornOff; + else if ( position == "Flat" ) + pos = DockMinimized; + + //kdDebug(220) << name() << " applySettings hidden=" << hidden << endl; + if (hidden) + hide(); + else + show(); + + if ( mainWindow() ) + { + //kdDebug(220) << name() << " applySettings updating ToolbarInfo" << endl; + d->toolBarInfo = TDEToolBarPrivate::ToolBarInfo( pos, index, newLine, offset ); + positionYourself( true ); + } + if (isVisible ()) + updateGeometry(); + } +} + +bool TDEToolBar::event( TQEvent *e ) +{ + if ( (e->type() == TQEvent::LayoutHint) && isUpdatesEnabled() ) + d->repaintTimer.start( 100, true ); + + if (e->type() == TQEvent::ChildInserted ) + { + // Bypass TQToolBar::event, + // it will show() the inserted child and we don't want to + // do that until we have rebuilt the layout. + childEvent((TQChildEvent *)e); + return true; + } + + return TQToolBar::event( e ); +} + +void TDEToolBar::slotRepaint() +{ + setUpdatesEnabled( false ); + // Send a resizeEvent to update the "toolbar extension arrow" + // (The button you get when your toolbar-items don't fit in + // the available space) + TQResizeEvent ev(size(), size()); + resizeEvent(&ev); + TQApplication::sendPostedEvents( this, TQEvent::LayoutHint ); + setUpdatesEnabled( true ); + repaint( true ); +} + +void TDEToolBar::toolBarPosChanged( TQToolBar *tb ) +{ + if ( tb != this ) + return; + if ( d->oldPos == DockMinimized ) + rebuildLayout(); + d->oldPos = (TQMainWindow::ToolBarDock)barPos(); + TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); + if ( kmw ) + kmw->setSettingsDirty(); +} + +static TDEToolBar::Dock stringToDock( const TQString& attrPosition ) +{ + TDEToolBar::Dock dock = TDEToolBar::DockTop; + if ( !attrPosition.isEmpty() ) { + if ( attrPosition == "top" ) + dock = TDEToolBar::DockTop; + else if ( attrPosition == "left" ) + dock = TDEToolBar::DockLeft; + else if ( attrPosition == "right" ) + dock = TDEToolBar::DockRight; + else if ( attrPosition == "bottom" ) + dock = TDEToolBar::DockBottom; + else if ( attrPosition == "floating" ) + dock = TDEToolBar::DockTornOff; + else if ( attrPosition == "flat" ) + dock = TDEToolBar::DockMinimized; + } + return dock; +} + + +void TDEToolBar::loadState( const TQDomElement &element ) +{ + TQMainWindow *mw = mainWindow(); + + if ( !mw ) + return; + + { + TQCString text = element.namedItem( "text" ).toElement().text().utf8(); + if ( text.isEmpty() ) + text = element.namedItem( "Text" ).toElement().text().utf8(); + if ( !text.isEmpty() ) + setText( i18n( text ) ); + } + + { + TQCString attrFullWidth = element.attribute( "fullWidth" ).lower().latin1(); + if ( !attrFullWidth.isEmpty() ) + setFullSize( attrFullWidth == "true" ); + } + + /* + This method is called in order to load toolbar settings from XML. + However this can be used in two rather different cases: + - for the initial loading of the app's XML. In that case the settings + are only the defaults, the user's TDEConfig settings will override them + (KDE4 TODO: how about saving those user settings into the local XML file instead? + Then this whole thing would be simpler, no TDEConfig settings to apply afterwards. + OTOH we'd have to migrate those settings when the .rc version increases, + like we do for shortcuts) + + - for later re-loading when switching between parts in KXMLGUIFactory. + In that case the XML contains the final settings, not the defaults. + We do need the defaults, and the toolbar might have been completely + deleted and recreated meanwhile. So we store the app-default settings + into the XML. + */ + bool loadingAppDefaults = true; + if ( element.hasAttribute( "offsetDefault" ) ) + { + // this isn't the first time, so the defaults have been saved into the (in-memory) XML + loadingAppDefaults = false; + d->OffsetDefault = element.attribute( "offsetDefault" ).toInt(); + d->NewLineDefault = element.attribute( "newlineDefault" ) == "true"; + d->HiddenDefault = element.attribute( "hiddenDefault" ) == "true"; + d->IconSizeDefault = element.attribute( "iconSizeDefault" ).toInt(); + d->PositionDefault = element.attribute( "positionDefault" ); + d->IconTextDefault = element.attribute( "iconTextDefault" ); + } + //kdDebug(220) << name() << " loadState loadingAppDefaults=" << loadingAppDefaults << endl; + + Dock dock = stringToDock( element.attribute( "position" ).lower() ); + + { + TQCString attrIconText = element.attribute( "iconText" ).lower().latin1(); + if ( !attrIconText.isEmpty() ) { + //kdDebug(220) << name() << " loadState attrIconText=" << attrIconText << endl; + if ( attrIconText == "icontextright" ) + setIconText( TDEToolBar::IconTextRight ); + else if ( attrIconText == "textonly" ) + setIconText( TDEToolBar::TextOnly ); + else if ( attrIconText == "icontextbottom" ) + setIconText( TDEToolBar::IconTextBottom ); + else if ( attrIconText == "icononly" ) + setIconText( TDEToolBar::IconOnly ); + } else + { + //kdDebug(220) << name() << " loadState no iconText attribute in XML, using iconTextSetting=" << iconTextSetting() << endl; + // Use global setting + if (d->m_honorStyle) + setIconText( iconTextSetting() ); + else + setIconText( d->IconTextDefault ); + } + } + + TQString attrIconSize = element.attribute( "iconSize" ).lower(); + int iconSize = d->IconSizeDefault; + if ( !attrIconSize.isEmpty() ) + iconSize = attrIconSize.toInt(); + setIconSize( iconSize ); + + int index = -1; // append by default. This is very important, otherwise + // with all 0 indexes, we keep reversing the toolbars. + { + TQString attrIndex = element.attribute( "index" ).lower(); + if ( !attrIndex.isEmpty() ) + index = attrIndex.toInt(); + } + + int offset = d->OffsetDefault; + bool newLine = d->NewLineDefault; + bool hidden = d->HiddenDefault; + + { + TQString attrOffset = element.attribute( "offset" ); + if ( !attrOffset.isEmpty() ) + offset = attrOffset.toInt(); + } + + { + TQString attrNewLine = element.attribute( "newline" ).lower(); + if ( !attrNewLine.isEmpty() ) + newLine = attrNewLine == "true"; + } + + { + TQString attrHidden = element.attribute( "hidden" ).lower(); + if ( !attrHidden.isEmpty() ) { + hidden = attrHidden == "true"; + } + } + + d->toolBarInfo = TDEToolBarPrivate::ToolBarInfo( dock, index, newLine, offset ); + mw->addDockWindow( this, dock, newLine ); + mw->moveDockWindow( this, dock, newLine, index, offset ); + + // Apply the highlight button setting + d->m_highlight = highlightSetting(); + + if ( hidden ) + hide(); + else + show(); + + if ( loadingAppDefaults ) + { + getAttributes( d->PositionDefault, d->IconTextDefault, index ); + //kdDebug(220) << name() << " loadState IconTextDefault=" << d->IconTextDefault << endl; + d->OffsetDefault = offset; + d->NewLineDefault = newLine; + d->HiddenDefault = hidden; + d->IconSizeDefault = iconSize; + } + //kdDebug(220) << name() << " loadState hidden=" << hidden << endl; + + // Apply transparent-toolbar-moving setting (ok, this is global to the mainwindow, + // but we do it only if there are toolbars...) + // KDE4: move to TDEMainWindow + if ( transparentSetting() != !mw->opaqueMoving() ) + mw->setOpaqueMoving( !transparentSetting() ); +} + +int TDEToolBar::dockWindowIndex() +{ + int index = 0; + Q_ASSERT( mainWindow() ); + if ( mainWindow() ) { + TQMainWindow::ToolBarDock dock; + bool newLine; + int offset; + mainWindow()->getLocation( this, dock, index, newLine, offset ); + } + return index; +} + +void TDEToolBar::getAttributes( TQString &position, TQString &icontext, int &index ) +{ + // get all of the stuff to save + switch ( barPos() ) { + case TDEToolBar::Flat: + position = "Flat"; + break; + case TDEToolBar::Bottom: + position = "Bottom"; + break; + case TDEToolBar::Left: + position = "Left"; + break; + case TDEToolBar::Right: + position = "Right"; + break; + case TDEToolBar::Floating: + position = "Floating"; + break; + case TDEToolBar::Top: + default: + position = "Top"; + break; + } + + index = dockWindowIndex(); + + switch (d->m_iconText) { + case TDEToolBar::IconTextRight: + icontext = "IconTextRight"; + break; + case TDEToolBar::IconTextBottom: + icontext = "IconTextBottom"; + break; + case TDEToolBar::TextOnly: + icontext = "TextOnly"; + break; + case TDEToolBar::IconOnly: + default: + icontext = "IconOnly"; + break; + } + //kdDebug(220) << name() << " getAttributes: icontext=" << icontext << endl; +} + +void TDEToolBar::saveState( TQDomElement ¤t ) +{ + Q_ASSERT( !current.isNull() ); + TQString position, icontext; + int index = -1; + getAttributes( position, icontext, index ); + + current.setAttribute( "noMerge", "1" ); + current.setAttribute( "position", position ); + current.setAttribute( "iconText", icontext ); + current.setAttribute( "index", index ); + current.setAttribute( "offset", offset() ); + current.setAttribute( "newline", newLine() ); + if ( isHidden() ) + current.setAttribute( "hidden", "true" ); + d->modified = true; + + // TODO if this method is used by more than KXMLGUIBuilder, e.g. to save XML settings to *disk*, + // then the stuff below shouldn't always be done. + current.setAttribute( "offsetDefault", d->OffsetDefault ); + current.setAttribute( "newlineDefault", d->NewLineDefault ); + current.setAttribute( "hiddenDefault", d->HiddenDefault ? "true" : "false" ); + current.setAttribute( "iconSizeDefault", d->IconSizeDefault ); + current.setAttribute( "positionDefault", d->PositionDefault ); + current.setAttribute( "iconTextDefault", d->IconTextDefault ); + + //kdDebug(220) << name() << " saveState: saving index=" << index << " iconText=" << icontext << " hidden=" << isHidden() << endl; +} + +// Called by TDEMainWindow::finalizeGUI +void TDEToolBar::positionYourself( bool force ) +{ + if (force) + d->positioned = false; + + if ( d->positioned || !mainWindow() ) + { + //kdDebug(220) << name() << " positionYourself d->positioned=true ALREADY DONE" << endl; + return; + } + // we can't test for ForceHide after moveDockWindow because QDockArea + // does a reparent() with showIt == true + bool hidden = isHidden(); + //kdDebug(220) << name() << " positionYourself dock=" << d->toolBarInfo.dock << " newLine=" << d->toolBarInfo.newline << " index=" << d->toolBarInfo.index << " offset=" << d->toolBarInfo.offset << endl; + mainWindow()->moveDockWindow( this, d->toolBarInfo.dock, + d->toolBarInfo.newline, + d->toolBarInfo.index, + d->toolBarInfo.offset ); + + //kdDebug(220) << name() << " positionYourself dockWindowIndex=" << dockWindowIndex() << endl; + if ( hidden ) + hide(); + else + show(); + // This method can only have an effect once - unless force is set + d->positioned = true; +} + +TDEPopupMenu *TDEToolBar::contextMenu() +{ + if ( context ) + return context; + // Construct our context popup menu. Name it qt_dockwidget_internal so it + // won't be deleted by TQToolBar::clear(). + context = new TDEPopupMenu( this, "qt_dockwidget_internal" ); + context->insertTitle(i18n("Toolbar Menu")); + + TDEPopupMenu *orient = new TDEPopupMenu( context, "orient" ); + orient->insertItem( i18n("toolbar position string","Top"), CONTEXT_TOP ); + orient->insertItem( i18n("toolbar position string","Left"), CONTEXT_LEFT ); + orient->insertItem( i18n("toolbar position string","Right"), CONTEXT_RIGHT ); + orient->insertItem( i18n("toolbar position string","Bottom"), CONTEXT_BOTTOM ); + orient->insertSeparator(-1); + orient->insertItem( i18n("toolbar position string","Floating"), CONTEXT_FLOAT ); + orient->insertItem( i18n("min toolbar", "Flat"), CONTEXT_FLAT ); + + TDEPopupMenu *mode = new TDEPopupMenu( context, "mode" ); + mode->insertItem( i18n("Icons Only"), CONTEXT_ICONS ); + mode->insertItem( i18n("Text Only"), CONTEXT_TEXT ); + mode->insertItem( i18n("Text Alongside Icons"), CONTEXT_TEXTRIGHT ); + mode->insertItem( i18n("Text Under Icons"), CONTEXT_TEXTUNDER ); + + TDEPopupMenu *size = new TDEPopupMenu( context, "size" ); + size->insertItem( i18n("Default"), CONTEXT_ICONSIZES ); + // Query the current theme for available sizes + KIconTheme *theme = TDEGlobal::instance()->iconLoader()->theme(); + TQValueList avSizes; + if (theme) + { + if (!::qstrcmp(name(), "mainToolBar")) + avSizes = theme->querySizes( KIcon::MainToolbar); + else + avSizes = theme->querySizes( KIcon::Toolbar); + } + + d->iconSizes = avSizes; + qHeapSort(avSizes); + + TQValueList::Iterator it; + if (avSizes.count() < 10) { + // Fixed or threshold type icons + TQValueList::Iterator end(avSizes.end()); + for (it=avSizes.begin(); it!=end; ++it) { + TQString text; + if ( *it < 19 ) + text = i18n("Small (%1x%2)").arg(*it).arg(*it); + else if (*it < 25) + text = i18n("Medium (%1x%2)").arg(*it).arg(*it); + else if (*it < 35) + text = i18n("Large (%1x%2)").arg(*it).arg(*it); + else + text = i18n("Huge (%1x%2)").arg(*it).arg(*it); + //we use the size as an id, with an offset + size->insertItem( text, CONTEXT_ICONSIZES + *it ); + } + } + else { + // Scalable icons. + const int progression[] = {16, 22, 32, 48, 64, 96, 128, 192, 256}; + + it = avSizes.begin(); + for (uint i = 0; i < 9; i++) { + while (it++ != avSizes.end()) { + if (*it >= progression[i]) { + TQString text; + if ( *it < 19 ) + text = i18n("Small (%1x%2)").arg(*it).arg(*it); + else if (*it < 25) + text = i18n("Medium (%1x%2)").arg(*it).arg(*it); + else if (*it < 35) + text = i18n("Large (%1x%2)").arg(*it).arg(*it); + else + text = i18n("Huge (%1x%2)").arg(*it).arg(*it); + //we use the size as an id, with an offset + size->insertItem( text, CONTEXT_ICONSIZES + *it ); + break; + } + } + } + } + + context->insertItem( i18n("Orientation"), orient ); + orient->setItemChecked(CONTEXT_TOP, true); + context->insertItem( i18n("Text Position"), mode ); + context->setItemChecked(CONTEXT_ICONS, true); + context->insertItem( i18n("Icon Size"), size ); + + connect( context, TQT_SIGNAL( aboutToShow() ), this, TQT_SLOT( slotContextAboutToShow() ) ); + // Unplugging a submenu from abouttohide leads to the popupmenu floating around + // So better simply call that code from after exec() returns (DF) + //connect( context, TQT_SIGNAL( aboutToHide() ), this, TQT_SLOT( slotContextAboutToHide() ) ); + return context; +} + +void TDEToolBar::slotContextAboutToShow() +{ + // The idea here is to reuse the "static" part of the menu to save time. + // But the "Toolbars" action is dynamic (can be a single action or a submenu) + // and ToolBarHandler::setupActions() deletes it, so better not keep it around. + // So we currently plug/unplug the last two actions of the menu. + // Another way would be to keep around the actions and plug them all into a (new each time) popupmenu. + TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); + if ( kmw ) { + kmw->setupToolbarMenuActions(); + // Only allow hiding a toolbar if the action is also plugged somewhere else (e.g. menubar) + TDEAction *tbAction = kmw->toolBarMenuAction(); + if ( tbAction && tbAction->containerCount() > 0 ) + tbAction->plug(context); + } + + // try to find "configure toolbars" action + TDEAction *configureAction = 0; + const char* actionName = KStdAction::name(KStdAction::ConfigureToolbars); + if ( d->m_xmlguiClient ) + configureAction = d->m_xmlguiClient->actionCollection()->action(actionName); + if ( !configureAction && kmw ) + configureAction = kmw->actionCollection()->action(actionName); + if ( configureAction ) + configureAction->plug(context); + KEditToolbar::setDefaultToolbar(name()); + + for(int i = CONTEXT_ICONS; i <= CONTEXT_TEXTUNDER; ++i) + context->setItemChecked(i, false); + + switch( d->m_iconText ) + { + case IconOnly: + default: + context->setItemChecked(CONTEXT_ICONS, true); + break; + case IconTextRight: + context->setItemChecked(CONTEXT_TEXTRIGHT, true); + break; + case TextOnly: + context->setItemChecked(CONTEXT_TEXT, true); + break; + case IconTextBottom: + context->setItemChecked(CONTEXT_TEXTUNDER, true); + break; + } + + TQValueList::ConstIterator iIt = d->iconSizes.begin(); + TQValueList::ConstIterator iEnd = d->iconSizes.end(); + for (; iIt != iEnd; ++iIt ) + context->setItemChecked( CONTEXT_ICONSIZES + *iIt, false ); + + context->setItemChecked( CONTEXT_ICONSIZES, false ); + + context->setItemChecked( CONTEXT_ICONSIZES + d->m_iconSize, true ); + + for ( int i = CONTEXT_TOP; i <= CONTEXT_FLAT; ++i ) + context->setItemChecked( i, false ); + + switch ( barPos() ) + { + case TDEToolBar::Flat: + context->setItemChecked( CONTEXT_FLAT, true ); + break; + case TDEToolBar::Bottom: + context->setItemChecked( CONTEXT_BOTTOM, true ); + break; + case TDEToolBar::Left: + context->setItemChecked( CONTEXT_LEFT, true ); + break; + case TDEToolBar::Right: + context->setItemChecked( CONTEXT_RIGHT, true ); + break; + case TDEToolBar::Floating: + context->setItemChecked( CONTEXT_FLOAT, true ); + break; + case TDEToolBar::Top: + context->setItemChecked( CONTEXT_TOP, true ); + break; + default: break; + } +} + +void TDEToolBar::slotContextAboutToHide() +{ + // We have to unplug whatever slotContextAboutToShow plugged into the menu. + // Unplug the toolbar menu action + TDEMainWindow *kmw = tqt_dynamic_cast(mainWindow()); + if ( kmw && kmw->toolBarMenuAction() ) + if ( kmw->toolBarMenuAction()->containerCount() > 1 ) + kmw->toolBarMenuAction()->unplug(context); + + // Unplug the configure toolbars action too, since it's afterwards anyway + TDEAction *configureAction = 0; + const char* actionName = KStdAction::name(KStdAction::ConfigureToolbars); + if ( d->m_xmlguiClient ) + configureAction = d->m_xmlguiClient->actionCollection()->action(actionName); + if ( !configureAction && kmw ) + configureAction = kmw->actionCollection()->action(actionName); + if ( configureAction ) + configureAction->unplug(context); + + TQPtrListIterator it( widgets ); + TQWidget *wdg; + while ( ( wdg = it.current() ) != 0 ) { + if ( wdg->inherits( TQTOOLBUTTON_OBJECT_NAME_STRING ) ) + static_cast( wdg )->setDown( false ); + ++it; + } +} + +void TDEToolBar::widgetDestroyed() +{ + removeWidgetInternal( (TQWidget*)sender() ); +} + +void TDEToolBar::removeWidgetInternal( TQWidget * w ) +{ + widgets.removeRef( w ); + TQMap< TQWidget*, int >::Iterator it = widget2id.find( w ); + if ( it == widget2id.end() ) + return; + id2widget.remove( *it ); + widget2id.remove( it ); +} + +void TDEToolBar::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +#include "ktoolbar.moc" + diff --git a/tdeui/tdetoolbar.h b/tdeui/tdetoolbar.h new file mode 100644 index 000000000..43362f512 --- /dev/null +++ b/tdeui/tdetoolbar.h @@ -0,0 +1,1130 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 Reginald Stadlbauer (reggie@kde.org) + (C) 1997, 1998 Stephan Kulow (coolo@kde.org) + (C) 1997, 1998 Sven Radej (radej@kde.org) + (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) + (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) + (C) 1999, 2000 Kurt Granroth (granroth@kde.org) + + 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 KTOOLBAR_H +#define KTOOLBAR_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +class TQDomElement; +class TQSize; +class TQPixmap; +class TQPopupMenu; +class TQStringList; +class TQDomDocument; +class TQTimer; + +class KLineEdit; +class TDEToolBar; +class TDEToolBarButton; +class TDEToolBoxManager; +class KAnimWidget; +class TDEPopupMenu; +class TDEInstance; +class KComboBox; +class KXMLGUIClient; + +class TDEToolBarPrivate; + +class TDEUI_EXPORT TDEToolBarSeparator : public TQFrame +{ + Q_OBJECT + +public: + TDEToolBarSeparator( Orientation, bool l, TQToolBar *parent, const char* name=0 ); + + TQSize sizeHint() const; + Orientation orientation() const { return orient; } + TQSizePolicy sizePolicy() const; + bool showLine() const { return line; } +public slots: + void setOrientation( Orientation ); +protected: + void styleChange( TQStyle& ); + void drawContents( TQPainter* ); +private: + Orientation orient; + bool line; +}; + + + /** + * @short Floatable toolbar with auto resize. + * + * A KDE-style toolbar. + * + * TDEToolBar can be dragged around in and between different docks. + * + * A TDEToolBar can contain all sorts of widgets. + * + * TDEToolBar can be used as a standalone widget, but TDEMainWindow + * provides easy factories and management of one or more toolbars. + * Once you have a TDEToolBar object, you can insert items into it with the + * insert... methods, or remove them with the removeItem() method. This + * can be done at any time; the toolbar will be automatically updated. + * There are also many methods to set per-child properties like alignment + * and toggle behavior. + * + * TDEToolBar uses a global config group to load toolbar settings on + * construction. It will reread this config group on a + * TDEApplication::appearanceChanged() signal. + * + * @author Reginald Stadlbauer , Stephan Kulow , Sven Radej . + */ + +class TDEUI_EXPORT TDEToolBar : public TQToolBar +{ + Q_OBJECT + + TQ_ENUMS( IconText BarPosition ) + TQ_PROPERTY( IconText iconText READ iconText WRITE setIconText ) + TQ_PROPERTY( BarPosition barPos READ barPos WRITE setBarPos ) + TQ_PROPERTY( bool fullSize READ fullSize WRITE setFullSize ) + TQ_PROPERTY( int iconSize READ iconSize WRITE setIconSize ) + TQ_PROPERTY( TQString text READ text WRITE setText ) + +public: + enum IconText{IconOnly = 0, IconTextRight, TextOnly, IconTextBottom}; + /** + * The state of the status bar. + * @deprecated + */ + enum BarStatus{Toggle, Show, Hide}; + /** + * Possible bar positions. + */ + enum BarPosition{ Unmanaged, Floating, Top, Bottom, Right, Left, Flat}; + + /** + * Normal constructor. + * This constructor is used by the XML-GUI. If you use it, you need + * to call TQMainWindow::addToolBar to specify the position of the toolbar. + * So it's simpler to use the other constructor. + * + * The toolbar will read in various global config settings for + * things like icon size and text position, etc. However, some of + * the settings will be honored only if @p honorStyle is set to + * true. All other toolbars will be IconOnly and use Medium icons. + * + * @param parent The standard toolbar parent (usually a + * TDEMainWindow) + * @param name The standard internal name + * @param honorStyle If true, then global settings for IconSize and IconText will be honored + * @param readConfig whether to apply the configuration (global and application-specific) + */ + TDEToolBar( TQWidget *parent, const char *name = 0, bool honorStyle = false, bool readConfig = true ); + + /** + * Constructor for non-XML-GUI applications. + * + * The toolbar will read in various global config settings for + * things like icon size and text position, etc. However, some of + * the settings will be honored only if @p honorStyle is set to + * true. All other toolbars will be IconOnly and use Medium icons. + * + * @param parentWindow The window that should be the parent of this toolbar + * @param dock The position of the toolbar. Usually TQMainWindow::Top. + * @param newLine If true, start a new line in the dock for this toolbar. + * @param name The standard internal name + * @param honorStyle If true, then global settings for IconSize and IconText will be honored + * @param readConfig whether to apply the configuration (global and application-specific) + */ + TDEToolBar( TQMainWindow *parentWindow, TQMainWindow::ToolBarDock dock /*= TQMainWindow::Top*/, bool newLine = false, + const char *name = 0, bool honorStyle = false, bool readConfig = true ); + + /** + * Constructor for non-XML-GUI applications. + * + * The toolbar will read in various global config settings for + * things like icon size and text position, etc. However, some of + * the settings will be honored only if @p honorStyle is set to + * true. All other toolbars will be IconOnly and use Medium icons. + * + * @param parentWindow The window that should be the parent of this toolbar + * @param dock Another widget than the mainwindow to dock toolbar to. + * @param newLine If true, start a new line in the dock for this toolbar. + * @param name The standard internal name + * @param honorStyle If true, then global settings for IconSize and IconText will be honored + * @param readConfig whether to apply the configuration (global and application-specific) + */ + TDEToolBar( TQMainWindow *parentWindow, TQWidget *dock, bool newLine = false, + const char *name = 0, bool honorStyle = false, bool readConfig = true ); + + /** + * Destructor + */ + virtual ~TDEToolBar(); + + /** + * Insert a button (a TDEToolBarButton) with a pixmap. The + * pixmap is loaded by the button itself based on the global icon + * settings. + * + * You should connect to one or more signals in TDEToolBar: + * clicked() , pressed() , released() , or + * highlighted() and if the button is a toggle button + * ( setToggle() ) toggled() . Those signals have @p id + * of a button that caused the signal. If you want to bind a popup + * to button, see setButton(). + * + * @param icon The name of the icon to use as the active pixmap + * @param id The id of this button + * @param enabled Enable or disable the button at startup + * @param text The tooltip or toolbar text (depending on state) + * @param index The position of the button. (-1 = at end). + * @param _instance instance this button will belong to + * + * @return The item index. + */ + int insertButton(const TQString& icon, int id, bool enabled = true, + const TQString& text = TQString::null, int index=-1, + TDEInstance *_instance = TDEGlobal::instance()); + + /** + * This is the same as above, but with specified signals and + * slots to which this button will be connected. + * + * You can add more signals with addConnection(). + * + * @param icon The name of the icon to use as the active pixmap + * @param id The id of this button + * @param signal The signal to connect to + * @param receiver The slot's parent + * @param slot The slot to receive the signal specified in that argument. + * @param enabled Enable or disable the button at startup + * @param text The tooltip or toolbar text (depending on state) + * @param index The position of the button. (-1 = at end). + * @param _instance instance this button will belong to + * + * @return The item index. + */ + int insertButton(const TQString& icon, int id, const char *signal, + const TQObject *receiver, const char *slot, + bool enabled = true, const TQString& text = TQString::null, + int index=-1, TDEInstance *_instance = TDEGlobal::instance() ); + + /** + * Inserts a button (a TDEToolBarButton) with the specified + * pixmap. This pixmap will be used as the "active" one and the + * disabled and default ones will be autogenerated. + * + * It is recommended that you use the insertButton function that + * allows you to specify the icon name rather then the pixmap + * itself. Specifying the icon name is much more flexible. + * + * You should connect to one or more signals in TDEToolBar: + * clicked() , pressed() , released() , or + * highlighted() and if the button is a toggle button + * ( setToggle() ) toggled() . Those signals have @p id + * of a button that caused the signal. If you want to bind a popup + * to button, see setButton(). + * + * @param pixmap The active pixmap + * @param id The id of this button + * @param enabled Enable or disable the button at startup + * @param text The tooltip or toolbar text (depending on state) + * @param index The position of the button. (-1 = at end). + * + * @return The item index. + */ + int insertButton(const TQPixmap& pixmap, int id, bool enabled = true, + const TQString& text = TQString::null, int index=-1 ); + + /** + * This is the same as above, but with specified signals and + * slots to which this button will be connected. + * + * You can add more signals with addConnection(). + * + * @param pixmap The name of the icon to use as the active pixmap + * @param id The id of this button + * @param signal The signal to connect to + * @param receiver The slot's parent + * @param slot The slot to receive the signal specified in that argument. + * @param enabled Enable or disable the button at startup + * @param text The tooltip or toolbar text (depending on state) + * @param index The position of the button. (-1 = at end). + * + * @return The item index. + */ + int insertButton(const TQPixmap& pixmap, int id, const char *signal, + const TQObject *receiver, const char *slot, + bool enabled = true, const TQString& text = TQString::null, + int index=-1 ); + + /** + * Inserts a button with popupmenu. + * + * Button will have small + * triangle. You have to connect to popup's signals. The + * signals KButton::pressed(), KButton::released(), + * KButton::clicked() or KButton::doubleClicked() are @p not + * emmited by + * this button (see setDelayedPopup() for that). + * You can add custom popups which inherit TQPopupMenu to get popups + * with tables, drawings etc. Just don't fiddle with events there. + */ + int insertButton(const TQString& icon, int id, TQPopupMenu *popup, + bool enabled, const TQString&_text, int index=-1); + + /** + * Inserts a button with popupmenu. + * + * Button will have small + * triangle. You have to connect to popup's signals. The + * signals KButton::pressed(), KButton::released(), + * KButton::clicked() or KButton::doubleClicked() are @p not + * emmited by + * this button (see setDelayedPopup() for that). + * You can add custom popups which inherit TQPopupMenu to get popups + * with tables, drawings etc. Just don't fiddle with events there. + */ + int insertButton(const TQPixmap& pixmap, int id, TQPopupMenu *popup, + bool enabled, const TQString&_text, int index=-1); + + /** + * Inserts a KLineEdit. You have to specify signals and slots to + * which KLineEdit will be connected. KLineEdit has all slots QLineEdit + * has, plus signals KLineEdit::completion and KLineEdit::textRotation + * KLineEdit can be set to autoresize itself to full free width + * in toolbar, that is to last right aligned item. For that, + * toolbar must be set to full width (which it is by default). + * @see setFullWidth() + * @see setItemAutoSized() + * @see KLineEdit + * @return Item index. + */ + int insertLined (const TQString& text, int id, + const char *signal, + const TQObject *receiver, const char *slot, + bool enabled = true, + const TQString& toolTipText = TQString::null, + int size = 70, int index =-1); + + /** + * Inserts a KComboBox with list. + * + * Can be writable, but cannot contain + * pixmaps. By default inserting policy is AtBottom, i.e. typed items + * are placed at the bottom of the list. Can be autosized. If the size + * argument is specified as -1, the width of the combobox is automatically + * computed. + * + * @see setFullWidth() + * @see setItemAutoSized() + * @see KComboBox + * @return Item index. + */ + int insertCombo (const TQStringList &list, int id, bool writable, + const char *signal, const TQObject *receiver, + const char *slot, bool enabled=true, + const TQString& tooltiptext=TQString::null, + int size=70, int index=-1, + TQComboBox::Policy policy = TQComboBox::AtBottom); + + /** + * Insert a KComboBox with text. + * + * The rest is the same as above. + * @see setItemAutoSized() + * + * @see KComboBox + * @return Item index. + */ + int insertCombo (const TQString& text, int id, bool writable, + const char *signal, TQObject *receiver, + const char *slot, bool enabled=true, + const TQString& tooltiptext=TQString::null, + int size=70, int index=-1, + TQComboBox::Policy policy = TQComboBox::AtBottom); + + /** + * Inserts a separator into the toolbar with the given @p id. + * @return the separator's index + */ + int insertSeparator( int index = -1, int id = -1 ); + + /** + * Inserts a line separator into the toolbar with the given @p id. + * @return the separator's index + */ + int insertLineSeparator( int index = -1, int id = -1 ); + + /** + * Inserts a user-defined widget. The widget @p must have this + * toolbar as its parent. + * + * Widget must have a TQWidget for base class. Widget can be + * autosized to full width. If you forget about it, you can get a + * pointer to this widget with getWidget(). + * @see setItemAutoSized() + * @return Item index. + */ + int insertWidget(int id, int width, TQWidget *_widget, int index=-1); + + /** + * Inserts an animated widget. A KAnimWidget will be created + * internally using the icon name you provide. + * This will emit a signal (clicked()) whenever the + * animation widget is clicked. + * + * @see animatedWidget() + * + * @param id The id for this toolbar item + * @param receiver The parent of your slot + * @param slot The slot to receive the clicked() signal + * @param icons The name of the animation icon group to use + * @param index The item index + * + * @return The item index + */ + int insertAnimatedWidget(int id, TQObject *receiver, const char *slot, + const TQString& icons, int index = -1); + + /** + * This will return a pointer to the animated widget with the + * given @p id, if it exists. + * + * @see insertAnimatedWidget + * @param id The id for the widget you want to get a pointer to + * @return A pointer to the current animated widget or 0L + */ + KAnimWidget *animatedWidget( int id ); + + /** + * Adds connections to items. + * + * It is important that you + * know the @p id of particular item. Nothing happens if you forget @p id. + */ + void addConnection (int id, const char *signal, + const TQObject *receiver, const char *slot); + /** + * Enables/disables item. + */ + void setItemEnabled( int id, bool enabled ); + + /** + * Sets the icon for a button. + * + * Can be used while button is visible. + */ + void setButtonIcon( int id, const TQString& _icon ); + + /** + * Sets button pixmap. + * + * Can be used while button is visible. + */ + void setButtonPixmap( int id, const TQPixmap& _pixmap ); + + /** + * Sets a button icon from a TQIconSet. + * + * Can be used while button is visible. + */ + void setButtonIconSet( int id, const TQIconSet& iconset ); + + /** + * Sets a delayed popup for a button. + * + * Delayed popup is what you see in + * Netscape Navigator's Previous and Next buttons: If you click them you + * go back + * or forth. If you press them long enough, you get a history-menu. + * This is exactly what we do here. + * + * You will insert a normal button with connection (or use signals from + * toolbar): + * \code + * bar->insertButton(icon, id, TQT_SIGNAL(clicked ()), this, + * TQT_SLOT (slotClick()), true, "click or wait for popup"); + * \endcode + * And then add a delayed popup: + * \code + * bar->setDelayedPopup (id, historyPopup); + * \endcode + * + * Don't add delayed popups to buttons which have normal popups. + * + * You may add popups which are derived from TQPopupMenu. You may + * add popups that are already in the menu bar or are submenus of + * other popups. + */ + void setDelayedPopup (int id , TQPopupMenu *_popup, bool toggle = false); + + /** + * Turns a button into an autorepeat button. + * + * Toggle buttons, buttons with menus, or + * buttons with delayed menus cannot be made into autorepeat buttons. + * Moreover, you can and will receive + * only the signal clicked(), but not pressed() or released(). + * When the user presses this button, you will receive the signal clicked(), + * and if the button is still pressed after some time, + * you will receive more clicked() signals separated by regular + * intervals. Since this uses TQButton::setAutoRepeat() , + * I can't quantify 'some'. + */ + void setAutoRepeat (int id, bool flag=true); + + + /** + * Turns button into a toggle button if @p flag is true. + */ + void setToggle (int id, bool flag = true); + + /** + * Toggles a togglebutton. + * + * If the button is a toggle button (see setToggle()) + * the button state will be toggled. This will also cause the toolbar to + * emit the signal KButton::toggled() with parameter @p id. You must connect to + * this signal, or use addConnection() to connect directly to the + * button signal KButton::toggled(). + */ + void toggleButton (int id); + + /** + * Sets a toggle button state. + * + * If the button is a toggle button (see setToggle()) + * this will set its state flag. This will also emit the signal + * KButton::toggled(). + * + * @see setToggle() + */ + void setButton (int id, bool flag); + + /** + * Returns @p true if button is on and is a toggle button + * @return @p true if button is on and is a toggle button + * @see setToggle() + */ + bool isButtonOn (int id) const; + + /** + * Sets the text of a line editor. + * + * Cursor is set at end of text. + */ + void setLinedText (int id, const TQString& text); + + /** + * Returns the line editor text. + * @return the line editor text. + */ + TQString getLinedText (int id) const; + + /** + * Inserts @p text in combobox @p id at position @p index. + */ + void insertComboItem (int id, const TQString& text, int index); + + /** + * Inserts @p list in combobox @p id at position @p index. + */ + void insertComboList (int id, const TQStringList &list, int index); + + /** + * Removes item @p index from combobox @p id. + */ + void removeComboItem (int id, int index); + + /** + * Sets item @p index to be current item in combobox @p id. + */ + void setCurrentComboItem (int id, int index); + + /** + * Changes item @p index in combobox @p id to text. + * + * @p index = -1 refers current item (one displayed in the button). + */ + void changeComboItem (int id, const TQString& text, int index=-1); + + /** + * Clears the combobox @p id. + * + * Does not delete it or hide it. + */ + void clearCombo (int id); + + /** + * Returns text of item @p index from combobox @p id. + * @return text of item @p index from combobox @p id. + * + * @p index = -1 refers to current item. + */ + + TQString getComboItem (int id, int index=-1) const; + + /** + * Returns a pointer to the combobox with @p id. + * @return a pointer to the combobox with @p id. + * + * Example: + * \code + * KComboBox *combo = toolbar->getCombo(combo_id); + * \endcode + * That way you can get access to other public methods + * that KComboBox provides. + */ + KComboBox * getCombo(int id); + + /** + * Returns a pointer to TDEToolBarLined with @p id. + * @return a pointer to TDEToolBarLined with @p id. + * + * Example: + * \code + * KLineEdit * lined = toolbar->getTDEToolBarLined(lined_id); + * \endcode + * That way you can get access to other public methods + * that KLineEdit provides. KLineEdit is the same thing + * as TQLineEdit plus completion signals. + */ + KLineEdit * getLined (int id); + + /** + * Returns a pointer to TDEToolBarButton. + * + * Example: + * \code + * TDEToolBarButton * button = toolbar->getButton(button_id); + * \endcode + * That way you can get access to other public methods + * that TDEToolBarButton provides. + * + * Using this method is not recommended. + */ + TDEToolBarButton * getButton (int id); + + /** + * Align item to the right. + * + * This works only if toolbar is set to full width. + * @see setFullWidth() + */ + void alignItemRight (int id, bool right = true); + + /** + * Returns a pointer to the widget corresponding to @p id. + * @return a pointer to the widget corresponding to @p id. + * + * Wrong ids are not tested. + * You can do with this whatever you want, + * except change its height (hardcoded). If you change its width + * you will probably have to call TQToolBar::updateRects(true) + * @see QWidget + * @see updateRects() + */ + TQWidget *getWidget (int id); // ### KDE4: make this const! + + /** + * Set item autosized. + * + * This works only if the toolbar is set to full width. + * Only @p one item can be autosized, and it has to be + * the last left-aligned item. Items that come after this must be right + * aligned. Items that can be right aligned are Lineds, Frames, Widgets and + * Combos. An autosized item will resize itself whenever the toolbar geometry + * changes to the last right-aligned item (or to end of toolbar if there + * are no right-aligned items.) + * @see setFullWidth() + * @see alignItemRight() + */ + void setItemAutoSized (int id, bool yes = true); + + /** + * Remove all items. + * + * The toolbar is redrawn after it. + */ + void clear (); + + /** + * Remove item @p id. + * + * Item is deleted. Toolbar is redrawn after it. + */ + void removeItem (int id); + + /** + * Remove item @p id. + * + * Item is deleted when toolbar is redrawn. + */ + void removeItemDelayed (int id); + + /** + * Hide item @p id. + */ + void hideItem (int id); + + /** + * Show item @p id. + */ + void showItem (int id); + + /** + * Returns the index of the item @p id. + * @return the index of the item @p id. + * @since 3.2 + */ + int itemIndex (int id); // ### KDE4: make this const! + + /** + * Returns the id of the item at the given index. + * @since 3.2 + */ + int idAt(int index); // ### KDE4: make this const! + + /** + * Set toolbar to full parent size (default). + * + * In full size mode the bar extends over the parent's full width or height. + * If the mode is disabled the toolbar tries to take as much space as it + * needs without wrapping, but it does not exceed the parent box. You can + * force a certain width or height with setMaxWidth() or + * setMaxHeight(). + * + * If you want to use right-aligned items or auto-sized items you must use + * full size mode. + */ + void setFullSize(bool flag = true); + + /** + * Returns the full-size mode enabled flag. + * @return @p true if the full-size mode is enabled. + */ + bool fullSize() const; + + /** + * Enable or disable moving of toolbar. + * @deprecated use setMovingEnabled(bool) instead. + */ + void enableMoving(bool flag = true) KDE_DEPRECATED; + + /** + * Set position of toolbar. + * @see BarPosition() + */ + void setBarPos (BarPosition bpos); + + /** + * Returns the toolbar position. + * @return position of toolbar. + */ + BarPosition barPos() const; + + /** + * Show, hide, or toggle toolbar. + * + * This method is provided for compatibility only, + * please use show() and/or hide() instead. + * @see BarStatus + * @deprecated + */ + bool enable(BarStatus stat) KDE_DEPRECATED; + + /** + * Use setMaximumHeight() instead. + * @deprecated + */ + void setMaxHeight (int h) KDE_DEPRECATED; // Set max height for vertical toolbars + + /** + * Returns the value set with setMaxHeight(). + * @deprecated + * Use maximumHeight() instead. + * @return the value set with setMaxHeight(). + */ + int maxHeight() KDE_DEPRECATED; + + /** + * Use setMaximumWidth() instead. + * Set maximal width of horizontal (top or bottom) toolbar. + * @deprecated + */ + void setMaxWidth (int dw) KDE_DEPRECATED; + + /** + * Returns the value set with setMaxWidth(). + * Use maximumWidth() instead. + * @return the value set with setMaxWidth(). + * @deprecated + */ + int maxWidth() KDE_DEPRECATED; + + /** + * Set title for toolbar when it floats. + * + * Titles are however not (yet) + * visible. You can't change toolbar's title while it's floating. + */ + void setTitle (const TQString& _title); + + /** + * Use setMovingEnabled(bool) instead. + * @deprecated + */ + void enableFloating (bool flag) KDE_DEPRECATED; + + /** + * Set the kind of painting for buttons. + * + * Choose from: + * @li IconOnly (only icons), + * @li IconTextRight (icon and text, text is left from icons), + * @li TextOnly (only text), + * @li IconTextBottom (icons and text, text is under icons). + * @see IconText + * + */ + void setIconText(IconText it); + // Note: don't merge with the next one, it breaks Qt properties + + /** + * Similar to setIconText(IconText it) but allows you to + * disable or enable updating. If @p update is false, then the + * buttons will not be updated. This is useful only if you know + * that you will be forcing an update later. + */ + void setIconText(IconText it, bool update); + + /** + * Returns the current text style for buttons. + * @return the current text style for buttons. + */ + IconText iconText() const; + + /** + * Set the icon size to load. Usually you should not call + * this, the icon size is taken care of by KIconLoader + * and globally configured. + * By default, the toolbar will load icons of size 32 for main + * toolbars and 22 for other toolbars + * @see KIconLoader. + * + * @param size The size to use + */ + void setIconSize(int size); + // Note: don't merge with the next one, it breaks Qt properties + + /** + * Same as setIconText(int size) but allows you + * to disable the toolbar update. + * + * @param size The size to use + * @param update If true, then the toolbar will be updated after + * this + */ + void setIconSize(int size, bool update); + + /** + * Returns the current icon size for buttons. + * @return the current icon size for buttons. + */ + int iconSize() const; + + /** + * Returns the default size for this type of toolbar. + * @return the default size for this type of toolbar. + */ + int iconSizeDefault() const; + + /** + * This allows you to enable or disable the context menu. + * + * @param enable If false, then the context menu will be disabled + */ + void setEnableContextMenu(bool enable = true); + + /** + * Returns the context menu enabled flag + * @return true if the context menu is disabled + */ + bool contextMenuEnabled() const; + + /** + * This will inform a toolbar button to ignore certain style + * changes. Specifically, it will ignore IconText (always IconOnly) + * and will not allow image effects to apply. + * + * @param id The button to exclude from styles + * @param no_style If true, then it is excluded (default: true). + */ + void setItemNoStyle(int id, bool no_style = true); + + void setFlat (bool flag); + + /** + * Returns the total number of items in the toolbar + * @return the total number of items in the toolbar + */ + int count() const; + + /** + * Instruct the toolbar to save it's current state to either the app + * config file or to the XML-GUI resource file (whichever has + * precedence). + */ + void saveState(); // BIC: remove for KDE4? This doesn't appear to be used internally, + // and apps use saveMainWindowSettings in TDEMainWindow anyway. + + /** + * Save the toolbar settings to group @p configGroup in @p config. + */ + void saveSettings(TDEConfig *config, const TQString &configGroup); + + /** + * Read the toolbar settings from group @p configGroup in @p config + * and apply them. Even default settings are re-applied if @p force is set. + */ + void applySettings(TDEConfig *config, const TQString &configGroup,bool force); + // KDE4 merge with force=false + void applySettings(TDEConfig *config, const TQString &configGroup); + + /* + * Tell the toolbar what XML-GUI resource file it should use to save + * it's state. The state of the toolbar (position, size, etc) is + * saved in TDEConfig files if the application does not use XML-GUI + * but if the app does, then it's saved the XML file. This function + * allows this to happen. + * + * @param xmlfile The XML-GUI resource file to write to + * @param xml The DOM document for the XML-GUI building + * @internal + */ + // void setXML(const TQString& xmlfile, const TQDomDocument& xml); + + void setXMLGUIClient( KXMLGUIClient *client ); + + /** + * Assign a (translated) text to this toolbar. This is used + * for the tooltip on the handle, and when listing the toolbars. + */ + void setText( const TQString & txt ); + + /** + * Returns the toolbar's text. + * @return the toolbar's text. + */ + TQString text() const; + + void setStretchableWidget( TQWidget *w ); + TQSizePolicy sizePolicy() const; + bool highlight() const; + TQSize sizeHint() const; + TQSize minimumSizeHint() const; + TQSize minimumSize() const; + + void hide(); + void show(); + + void updateRects( bool = false ) {} + + /** + * Load state from an XML element, called by KXMLGUIBuilder + */ + void loadState( const TQDomElement &e ); + /* + * Save state into an XML element, called by KXMLGUIBuilder + */ + void saveState( TQDomElement &e ); + + /** + * @internal + */ + void positionYourself( bool force = false); + +signals: + /** + * Emitted when button @p id is clicked. + */ + void clicked(int id); + + /** + * Emitted when button @p id is double-clicked. + * + * Note: you will always + * recive two clicked() , pressed() and released() signals. + * There is no way to avoid it - at least no easy way. + * If you need to resolve this all you can do is set up timers + * which wait for TQApplication::doubleClickInterval() to expire. + * If in that time you don't get this signal, you may belive that + * button was only clicked and not double-clicked. + * And please note that butons with popup menus do not emit this signal, + * but those with delayed popup do. + */ + void doubleClicked (int id); + + /** + * Emitted when button @p id is pressed. + */ + void pressed(int); + + /** + * Emits when button @p id is released. + */ + void released(int); + + /** + * Emitted when a toggle button changes state. + * + * Emitted also if you change state + * with setButton() or toggleButton() + * If you make a button normal again, with + * setToggle(false), this signal won't + * be emitted. + */ + void toggled(int); + + /** + * This signal is emitted when item @p id gets highlighted/unhighlighted + * (i.e when mouse enters/exits). + * + * Note that this signal is emitted from + * all buttons (normal, disabled and toggle) even when there is no visible + * change in buttons (i.e., buttons do not raise when mouse enters). + * The parameter @p isHighlighted is @p true when mouse enters and @p false when + * mouse exits. + */ + void highlighted(int id, bool isHighlighted); + + /** + * This signal is emitted when item @p id gets highlighted/unhighlighted + * (i.e when mouse enters/exits). + * + * Note that this signal is emitted from + * all buttons (normal, disabled and toggle) even when there is no visible + * change in buttons (i.e., buttons do not raise when mouse enters). + */ + void highlighted(int id ); + + /** + * Emitted when toolbar changes position, or when + * an item is removed from toolbar. + * + * If you subclass TDEMainWindow and reimplement + * TDEMainWindow::resizeEvent() be sure to connect to + * this signal. Note: You can connect this signal to a slot that + * doesn't take parameter. + */ + void moved( BarPosition ); + + /** + * This signal is emitted when toolbar detects changing of + * following parameters: + * highlighting, button-size, button-mode. This signal is + * internal, aimed to buttons. + * @internal + */ + void modechange (); + + /** + * This signal is emitted when the toolbar is getting deleted, + * and before ~TDEToolbar finishes (so it's still time to remove + * widgets from the toolbar). + * Used by KWidgetAction. + * @since 3.2 + */ + void toolbarDestroyed(); + +public: + /** + * Returns the global setting for "Highlight buttons under mouse" + * @return global setting for "Highlight buttons under mouse" + */ + static bool highlightSetting(); + + /** + * Returns the global setting for "Toolbars transparent when moving" + * @return global setting for "Toolbars transparent when moving" + */ + static bool transparentSetting(); + + /** + * Returns the global setting for "Icon Text" + * @return global setting for "Icon Text" + */ + static IconText iconTextSetting(); + +public slots: + virtual void setIconText( const TQString &txt ) + { TQToolBar::setIconText( txt ); } + +protected: + void mousePressEvent( TQMouseEvent * ); + void childEvent( TQChildEvent *e ); + void showEvent( TQShowEvent *e ); + void resizeEvent( TQResizeEvent *e ); + bool event( TQEvent *e ); + void applyAppearanceSettings(TDEConfig *config, const TQString &_configGroup, bool forceGlobal = false); + TQString settingsGroup() const; + +private slots: + void rebuildLayout(); + void slotReadConfig (); + void slotAppearanceChanged(); + void slotIconChanged(int); + void slotRepaint(); + void toolBarPosChanged( TQToolBar *tb ); + void slotContextAboutToShow(); + void slotContextAboutToHide(); + void widgetDestroyed(); + +private: + void init( bool readConfig = true, bool honorStyle = false ); + void doConnections( TDEToolBarButton *button ); + void insertWidgetInternal( TQWidget *w, int &index, int id ); + void removeWidgetInternal( TQWidget *w ); + void getAttributes( TQString &position, TQString &icontext, int &index ); + int dockWindowIndex(); + TDEPopupMenu *contextMenu(); + void doModeChange(); + + TQMap widget2id; + typedef TQMap Id2WidgetMap; + Id2WidgetMap id2widget; + TDEPopupMenu *context; + TQPtrList widgets; + TQTimer *layoutTimer; + TQGuardedPtr stretchableWidget, rightAligned; +protected: + virtual void virtual_hook( int id, void* data ); +private: + TDEToolBarPrivate *d; +}; + +#endif diff --git a/tdeui/tdetoolbarbutton.cpp b/tdeui/tdetoolbarbutton.cpp new file mode 100644 index 000000000..49ceb57fa --- /dev/null +++ b/tdeui/tdetoolbarbutton.cpp @@ -0,0 +1,781 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) + (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) + (C) 1997, 1998 Sven Radej (radej@kde.org) + (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) + (C) 1999 Chris Schlaeger (cs@kde.org) + (C) 1999 Kurt Granroth (granroth@kde.org) + + 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. +*/ + +#include +#include + +#include "ktoolbarbutton.h" +#include "ktoolbar.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +// needed to get our instance +#include + +template class TQIntDict; + +class TDEToolBarButtonPrivate +{ +public: + TDEToolBarButtonPrivate() + { + m_buttonDown = false; + + m_noStyle = false; + m_isSeparator = false; + m_isRadio = false; + m_highlight = false; + m_isRaised = false; + m_isActive = false; + + m_iconName = TQString::null; + m_iconText = TDEToolBar::IconOnly; + m_iconSize = 0; + + m_parent = 0; + m_instance = TDEGlobal::instance(); + } + ~TDEToolBarButtonPrivate() + { + } + + int m_id; + bool m_buttonDown : 1; + bool m_noStyle: 1; + bool m_isSeparator: 1; + bool m_isRadio: 1; + bool m_highlight: 1; + bool m_isRaised: 1; + bool m_isActive: 1; + + TQString m_iconName; + + TDEToolBar *m_parent; + TDEToolBar::IconText m_iconText; + int m_iconSize; + TQSize size; + + TQPoint m_mousePressPos; + + TDEInstance *m_instance; +}; + +// This will construct a separator +TDEToolBarButton::TDEToolBarButton( TQWidget *_parent, const char *_name ) + : TQToolButton( _parent , _name) +{ + d = new TDEToolBarButtonPrivate; + + resize(6,6); + hide(); + d->m_isSeparator = true; +} + +TDEToolBarButton::TDEToolBarButton( const TQString& _icon, int _id, + TQWidget *_parent, const char *_name, + const TQString &_txt, TDEInstance *_instance ) + : TQToolButton( _parent, _name ), d( 0 ) +{ + d = new TDEToolBarButtonPrivate; + + d->m_id = _id; + TQToolButton::setTextLabel(_txt); + d->m_instance = _instance; + + d->m_parent = tqt_dynamic_cast(_parent); + if (d->m_parent) { + connect(d->m_parent, TQT_SIGNAL( modechange() ), + this, TQT_SLOT( modeChange() )); + } + + setFocusPolicy( TQ_NoFocus ); + + // connect all of our slots and start trapping events + connect(this, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( slotClicked() ) ); + connect(this, TQT_SIGNAL( pressed() ), + this, TQT_SLOT( slotPressed() ) ); + connect(this, TQT_SIGNAL( released() ), + this, TQT_SLOT( slotReleased() ) ); + installEventFilter(this); + + d->m_iconName = _icon; + + // do our initial setup + modeChange(); +} + +TDEToolBarButton::TDEToolBarButton( const TQPixmap& pixmap, int _id, + TQWidget *_parent, const char *name, + const TQString& txt) + : TQToolButton( _parent, name ), d( 0 ) +{ + d = new TDEToolBarButtonPrivate; + + d->m_id = _id; + TQToolButton::setTextLabel(txt); + + d->m_parent = tqt_dynamic_cast(_parent); + if (d->m_parent) { + connect(d->m_parent, TQT_SIGNAL( modechange() ), + this, TQT_SLOT( modeChange() )); + } + + setFocusPolicy( TQ_NoFocus ); + + // connect all of our slots and start trapping events + connect(this, TQT_SIGNAL( clicked() ), + this, TQT_SLOT( slotClicked() )); + connect(this, TQT_SIGNAL( pressed() ), + this, TQT_SLOT( slotPressed() )); + connect(this, TQT_SIGNAL( released() ), + this, TQT_SLOT( slotReleased() )); + installEventFilter(this); + + // set our pixmap and do our initial setup + setIconSet( TQIconSet( pixmap )); + modeChange(); +} + +TDEToolBarButton::~TDEToolBarButton() +{ + delete d; d = 0; +} + +void TDEToolBarButton::modeChange() +{ + TQSize mysize; + + // grab a few global variables for use in this function and others + if (d->m_parent) { + d->m_highlight = d->m_parent->highlight(); + d->m_iconText = d->m_parent->iconText(); + + d->m_iconSize = d->m_parent->iconSize(); + } + if (!d->m_iconName.isNull()) + setIcon(d->m_iconName); + + // we'll start with the size of our pixmap + int pix_width = d->m_iconSize; + if ( d->m_iconSize == 0 ) { + if (d->m_parent && !strcmp(d->m_parent->name(), "mainToolBar")) + pix_width = IconSize( KIcon::MainToolbar ); + else + pix_width = IconSize( KIcon::Toolbar ); + } + int pix_height = pix_width; + + int text_height = 0; + int text_width = 0; + + TQToolTip::remove(this); + if (d->m_iconText != TDEToolBar::IconOnly) + { + // okay, we have to deal with fonts. let's get our information now + TQFont tmp_font = TDEGlobalSettings::toolBarFont(); + + // now parse out our font sizes from our chosen font + TQFontMetrics fm(tmp_font); + + text_height = fm.lineSpacing(); + text_width = fm.width(textLabel()); + + // none of the other modes want tooltips + } + else + { + TQToolTip::add(this, textLabel()); + } + + switch (d->m_iconText) + { + case TDEToolBar::IconOnly: + mysize = TQSize(pix_width, pix_height); + break; + + case TDEToolBar::IconTextRight: + mysize = TQSize(pix_width + text_width + 4, pix_height); + break; + + case TDEToolBar::TextOnly: + mysize = TQSize(text_width + 4, text_height); + break; + + case TDEToolBar::IconTextBottom: + mysize = TQSize((text_width + 4 > pix_width) ? text_width + 4 : pix_width, pix_height + text_height); + break; + + default: + break; + } + + mysize = style().tqsizeFromContents(TQStyle::CT_ToolButton, this, mysize). + expandedTo(TQApplication::globalStrut()); + + // make sure that this isn't taller then it is wide + if (mysize.height() > mysize.width()) + mysize.setWidth(mysize.height()); + + d->size = mysize; + updateGeometry(); +} + +void TDEToolBarButton::setTextLabel( const TQString& text, bool tipToo) +{ + if (text.isNull()) + return; + + TQString txt(text); + if (txt.endsWith(TQString::fromLatin1("..."))) + txt.truncate(txt.length() - 3); + + TQToolButton::setTextLabel(txt, tipToo); + update(); +} + +void TDEToolBarButton::setText( const TQString& text) +{ + setTextLabel(text, true); + modeChange(); +} + +void TDEToolBarButton::setIcon( const TQString &icon ) +{ + d->m_iconName = icon; + if (d->m_parent) + d->m_iconSize = d->m_parent->iconSize(); + // TQObject::name() return "const char *" instead of TQString. + if (d->m_parent && !strcmp(d->m_parent->name(), "mainToolBar")) + TQToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet( + d->m_iconName, KIcon::MainToolbar, d->m_iconSize )); + else + TQToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet( + d->m_iconName, KIcon::Toolbar, d->m_iconSize )); +} + +void TDEToolBarButton::setIconSet( const TQIconSet &iconset ) +{ + TQToolButton::setIconSet( iconset ); +} + +// remove? +void TDEToolBarButton::setPixmap( const TQPixmap &pixmap ) +{ + if( pixmap.isNull()) // called by TQToolButton + { + TQToolButton::setPixmap( pixmap ); + return; + } + TQIconSet set = iconSet(); + set.setPixmap( pixmap, TQIconSet::Automatic, TQIconSet::Active ); + TQToolButton::setIconSet( set ); +} + +void TDEToolBarButton::setDefaultPixmap( const TQPixmap &pixmap ) +{ + TQIconSet set = iconSet(); + set.setPixmap( pixmap, TQIconSet::Automatic, TQIconSet::Normal ); + TQToolButton::setIconSet( set ); +} + +void TDEToolBarButton::setDisabledPixmap( const TQPixmap &pixmap ) +{ + TQIconSet set = iconSet(); + set.setPixmap( pixmap, TQIconSet::Automatic, TQIconSet::Disabled ); + TQToolButton::setIconSet( set ); +} + +void TDEToolBarButton::setDefaultIcon( const TQString& icon ) +{ + TQIconSet set = iconSet(); + TQPixmap pm; + if (d->m_parent && !strcmp(d->m_parent->name(), "mainToolBar")) + pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::MainToolbar, + d->m_iconSize ); + else + pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::Toolbar, + d->m_iconSize ); + set.setPixmap( pm, TQIconSet::Automatic, TQIconSet::Normal ); + TQToolButton::setIconSet( set ); +} + +void TDEToolBarButton::setDisabledIcon( const TQString& icon ) +{ + TQIconSet set = iconSet(); + TQPixmap pm; + if (d->m_parent && !strcmp(d->m_parent->name(), "mainToolBar")) + pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::MainToolbar, + d->m_iconSize ); + else + pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::Toolbar, + d->m_iconSize ); + set.setPixmap( pm, TQIconSet::Automatic, TQIconSet::Disabled ); + TQToolButton::setIconSet( set ); +} + +TQPopupMenu *TDEToolBarButton::popup() +{ + // obsolete + // KDE4: remove me + return TQToolButton::popup(); +} + +void TDEToolBarButton::setPopup(TQPopupMenu *p, bool) +{ + TQToolButton::setPopup(p); + TQToolButton::setPopupDelay(-1); +} + + +void TDEToolBarButton::setDelayedPopup (TQPopupMenu *p, bool) +{ + TQToolButton::setPopup(p); + TQToolButton::setPopupDelay(TQApplication::startDragTime()); +} + +void TDEToolBarButton::leaveEvent(TQEvent *) +{ + if( d->m_isRaised || d->m_isActive ) + { + d->m_isRaised = false; + d->m_isActive = false; + repaint(false); + } + + emit highlighted(d->m_id, false); +} + +void TDEToolBarButton::enterEvent(TQEvent *) +{ + if (d->m_highlight) + { + if (isEnabled()) + { + d->m_isActive = true; + if (!isToggleButton()) + d->m_isRaised = true; + } + else + { + d->m_isRaised = false; + d->m_isActive = false; + } + + repaint(false); + } + emit highlighted(d->m_id, true); +} + +bool TDEToolBarButton::eventFilter(TQObject *o, TQEvent *ev) +{ + if (TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(this)) + { + + // Popup the menu when the left mousebutton is pressed and the mouse + // is moved by a small distance. + if (TQToolButton::popup()) + { + if (ev->type() == TQEvent::MouseButtonPress) + { + TQMouseEvent* mev = TQT_TQMOUSEEVENT(ev); + d->m_mousePressPos = mev->pos(); + } + else if (ev->type() == TQEvent::MouseMove) + { + TQMouseEvent* mev = TQT_TQMOUSEEVENT(ev); + if ((mev->pos() - d->m_mousePressPos).manhattanLength() + > TDEGlobalSettings::dndEventDelay()) + { + openPopup(); + return true; + } + } + } + + if (d->m_isRadio && + (ev->type() == TQEvent::MouseButtonPress || + ev->type() == TQEvent::MouseButtonRelease || + ev->type() == TQEvent::MouseButtonDblClick) && isOn()) + return true; + + // From Kai-Uwe Sattler + if (ev->type() == TQEvent::MouseButtonDblClick) + { + emit doubleClicked(d->m_id); + return false; + } + } + + return TQToolButton::eventFilter(o, ev); +} + +void TDEToolBarButton::mousePressEvent( TQMouseEvent * e ) +{ + d->m_buttonDown = true; + + if ( e->button() == Qt::MidButton ) + { + // Get TQToolButton to show the button being down while pressed + TQMouseEvent ev( TQEvent::MouseButtonPress, e->pos(), e->globalPos(), Qt::LeftButton, e->state() ); + TQToolButton::mousePressEvent(&ev); + return; + } + TQToolButton::mousePressEvent(e); +} + +void TDEToolBarButton::mouseReleaseEvent( TQMouseEvent * e ) +{ + TQt::ButtonState state = TQt::ButtonState(e->button() | (e->state() & KeyButtonMask)); + if ( e->button() == Qt::MidButton ) + { + TQMouseEvent ev( TQEvent::MouseButtonRelease, e->pos(), e->globalPos(), Qt::LeftButton, e->state() ); + TQToolButton::mouseReleaseEvent(&ev); + } + else + TQToolButton::mouseReleaseEvent(e); + + if ( !d->m_buttonDown ) + return; + d->m_buttonDown = false; + + if ( hitButton( e->pos() ) ) + emit buttonClicked( d->m_id, state ); +} + +void TDEToolBarButton::drawButton( TQPainter *_painter ) +{ + TQStyle::SFlags flags = TQStyle::Style_Default; + TQStyle::SCFlags active = TQStyle::SC_None; + + if (isDown()) { + flags |= TQStyle::Style_Down; + active |= TQStyle::SC_ToolButton; + } + if (isEnabled()) flags |= TQStyle::Style_Enabled; + if (isOn()) flags |= TQStyle::Style_On; + if (isEnabled() && hasMouse()) flags |= TQStyle::Style_Raised; + if (hasFocus()) flags |= TQStyle::Style_HasFocus; + + // Draw a styled toolbutton + style().drawComplexControl(TQStyle::CC_ToolButton, _painter, this, rect(), + colorGroup(), flags, TQStyle::SC_ToolButton, active, TQStyleOption()); + + int dx, dy; + TQFont tmp_font(TDEGlobalSettings::toolBarFont()); + TQFontMetrics fm(tmp_font); + TQRect textRect; + int textFlags = 0; + + if (d->m_iconText == TDEToolBar::IconOnly) // icon only + { + TQPixmap pixmap = iconSet().pixmap( TQIconSet::Automatic, + isEnabled() ? (d->m_isActive ? TQIconSet::Active : TQIconSet::Normal) : + TQIconSet::Disabled, + isOn() ? TQIconSet::On : TQIconSet::Off ); + if( !pixmap.isNull()) + { + dx = ( width() - pixmap.width() ) / 2; + dy = ( height() - pixmap.height() ) / 2; + if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) + { + ++dx; + ++dy; + } + _painter->drawPixmap( dx, dy, pixmap ); + } + } + else if (d->m_iconText == TDEToolBar::IconTextRight) // icon and text (if any) + { + TQPixmap pixmap = iconSet().pixmap( TQIconSet::Automatic, + isEnabled() ? (d->m_isActive ? TQIconSet::Active : TQIconSet::Normal) : + TQIconSet::Disabled, + isOn() ? TQIconSet::On : TQIconSet::Off ); + if( !pixmap.isNull()) + { + dx = 4; + dy = ( height() - pixmap.height() ) / 2; + if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) + { + ++dx; + ++dy; + } + _painter->drawPixmap( dx, dy, pixmap ); + } + + if (!textLabel().isNull()) + { + textFlags = AlignVCenter|AlignLeft; + if (!pixmap.isNull()) + dx = 4 + pixmap.width() + 2; + else + dx = 4; + dy = 0; + if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) + { + ++dx; + ++dy; + } + textRect = TQRect(dx, dy, width()-dx, height()); + } + } + else if (d->m_iconText == TDEToolBar::TextOnly) + { + if (!textLabel().isNull()) + { + textFlags = AlignVCenter|AlignLeft; + dx = (width() - fm.width(textLabel())) / 2; + dy = (height() - fm.lineSpacing()) / 2; + if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) + { + ++dx; + ++dy; + } + textRect = TQRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() ); + } + } + else if (d->m_iconText == TDEToolBar::IconTextBottom) + { + TQPixmap pixmap = iconSet().pixmap( TQIconSet::Automatic, + isEnabled() ? (d->m_isActive ? TQIconSet::Active : TQIconSet::Normal) : + TQIconSet::Disabled, + isOn() ? TQIconSet::On : TQIconSet::Off ); + if( !pixmap.isNull()) + { + dx = (width() - pixmap.width()) / 2; + dy = (height() - fm.lineSpacing() - pixmap.height()) / 2; + if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) + { + ++dx; + ++dy; + } + _painter->drawPixmap( dx, dy, pixmap ); + } + + if (!textLabel().isNull()) + { + textFlags = AlignBottom|AlignHCenter; + dx = (width() - fm.width(textLabel())) / 2; + dy = height() - fm.lineSpacing() - 4; + + if ( isDown() && style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle ) + { + ++dx; + ++dy; + } + textRect = TQRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() ); + } + } + + // Draw the text at the position given by textRect, and using textFlags + if (!textLabel().isNull() && !textRect.isNull()) + { + _painter->setFont(TDEGlobalSettings::toolBarFont()); + if (!isEnabled()) + _painter->setPen(palette().disabled().dark()); + else if(d->m_isRaised) + _painter->setPen(TDEGlobalSettings::toolBarHighlightColor()); + else + _painter->setPen( colorGroup().buttonText() ); + _painter->drawText(textRect, textFlags, textLabel()); + } + + if (TQToolButton::popup()) + { + TQStyle::SFlags arrowFlags = TQStyle::Style_Default; + + if (isDown()) arrowFlags |= TQStyle::Style_Down; + if (isEnabled()) arrowFlags |= TQStyle::Style_Enabled; + + style().tqdrawPrimitive(TQStyle::PE_ArrowDown, _painter, + TQRect(width()-7, height()-7, 7, 7), colorGroup(), + arrowFlags, TQStyleOption() ); + } +} + +void TDEToolBarButton::paletteChange(const TQPalette &) +{ + if(!d->m_isSeparator) + { + modeChange(); + repaint(false); // no need to delete it first therefore only false + } +} + +bool TDEToolBarButton::event(TQEvent *e) +{ + if (e->type() == TQEvent::ParentFontChange || e->type() == TQEvent::ApplicationFontChange) + { + //If we use toolbar text, apply the settings again, to relayout... + if (d->m_iconText != TDEToolBar::IconOnly) + modeChange(); + return true; + } + + return TQToolButton::event(e); +} + + +void TDEToolBarButton::showMenu() +{ + // obsolete + // KDE4: remove me +} + +void TDEToolBarButton::slotDelayTimeout() +{ + // obsolete + // KDE4: remove me +} + +void TDEToolBarButton::slotClicked() +{ + emit clicked( d->m_id ); + + // emit buttonClicked when the button was clicked while being in an extension popupmenu + if ( d->m_parent && !d->m_parent->rect().contains( geometry().center() ) ) { + ButtonState state = TDEApplication::keyboardMouseState(); + if ( ( state & Qt::MouseButtonMask ) == Qt::NoButton ) + state = ButtonState( Qt::LeftButton | state ); + emit buttonClicked( d->m_id, state ); // Doesn't work with MidButton + } +} + +void TDEToolBarButton::slotPressed() +{ + emit pressed( d->m_id ); +} + +void TDEToolBarButton::slotReleased() +{ + emit released( d->m_id ); +} + +void TDEToolBarButton::slotToggled() +{ + emit toggled( d->m_id ); +} + +void TDEToolBarButton::setNoStyle(bool no_style) +{ + d->m_noStyle = no_style; + + modeChange(); + d->m_iconText = TDEToolBar::IconTextRight; + repaint(false); +} + +void TDEToolBarButton::setRadio (bool f) +{ + if ( d ) + d->m_isRadio = f; +} + +void TDEToolBarButton::on(bool flag) +{ + if(isToggleButton()) + setOn(flag); + else + { + setDown(flag); + leaveEvent((TQEvent *) 0); + } + repaint(); +} + +void TDEToolBarButton::toggle() +{ + setOn(!isOn()); + repaint(); +} + +void TDEToolBarButton::setToggle(bool flag) +{ + setToggleButton(flag); + if (flag) + connect(this, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggled())); + else + disconnect(this, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggled())); +} + +TQSize TDEToolBarButton::sizeHint() const +{ + return d->size; +} + +TQSize TDEToolBarButton::minimumSizeHint() const +{ + return d->size; +} + +TQSize TDEToolBarButton::minimumSize() const +{ + return d->size; +} + +bool TDEToolBarButton::isRaised() const +{ + return d->m_isRaised; +} + +bool TDEToolBarButton::isActive() const +{ + return d->m_isActive; +} + +int TDEToolBarButton::iconTextMode() const +{ + return static_cast( d->m_iconText ); +} + +int TDEToolBarButton::id() const +{ + return d->m_id; +} + +// TDEToolBarButtonList +TDEToolBarButtonList::TDEToolBarButtonList() +{ + setAutoDelete(false); +} + +void TDEToolBarButton::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +#include "ktoolbarbutton.moc" diff --git a/tdeui/tdetoolbarbutton.h b/tdeui/tdetoolbarbutton.h new file mode 100644 index 000000000..49e906e6e --- /dev/null +++ b/tdeui/tdetoolbarbutton.h @@ -0,0 +1,331 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) + (C) 1997, 1998 Sven Radej (radej@kde.org) + (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) + (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) + (C) 2000 Kurt Granroth (granroth@kde.org) + + 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 _KTOOLBARBUTTON_H +#define _KTOOLBARBUTTON_H + +#include +#include +#include +#include +#include + +class TDEToolBar; +class TDEToolBarButtonPrivate; +class TDEInstance; +class TQEvent; +class TQPopupMenu; +class TQPainter; + +/** + * A toolbar button. This is used internally by TDEToolBar, use the + * TDEToolBar methods instead. + * @internal + */ +class TDEUI_EXPORT TDEToolBarButton : public TQToolButton +{ + Q_OBJECT + + +public: + /** + * Construct a button with an icon loaded by the button itself. + * This will trust the button to load the correct icon with the + * correct size. + * + * @param icon Name of icon to load (may be absolute or relative) + * @param id Id of this button + * @param parent This button's parent + * @param name This button's internal name + * @param txt This button's text (in a tooltip or otherwise) + * @param _instance the instance to use for this button + */ + TDEToolBarButton(const TQString& icon, int id, TQWidget *parent, + const char *name=0L, const TQString &txt=TQString::null, + TDEInstance *_instance = TDEGlobal::instance()); + + /** + * Construct a button with an existing pixmap. It is not + * recommended that you use this as the internal icon loading code + * will almost always get it "right". + * + * @param pixmap Name of icon to load (may be absolute or relative) + * @param id Id of this button + * @param parent This button's parent + * @param name This button's internal name + * @param txt This button's text (in a tooltip or otherwise) + */ + TDEToolBarButton(const TQPixmap& pixmap, int id, TQWidget *parent, + const char *name=0L, const TQString &txt=TQString::null); + + /** + * Construct a separator button + * + * @param parent This button's parent + * @param name This button's internal name + */ + TDEToolBarButton(TQWidget *parent=0L, const char *name=0L); + + /** + * Standard destructor + */ + ~TDEToolBarButton(); + +#ifndef KDE_NO_COMPAT + /** + * @deprecated + * Set the pixmap directly for this button. This pixmap should be + * the active one... the dimmed and disabled pixmaps are constructed + * based on this one. However, don't use this function unless you + * are positive that you don't want to use setIcon. + * + * @param pixmap The active pixmap + */ + // this one is from TQButton, so #ifdef-ing it out doesn't break BC + virtual void setPixmap(const TQPixmap &pixmap) KDE_DEPRECATED; + + /** + * @deprecated + * Force the button to use this pixmap as the default one rather + * then generating it using effects. + * + * @param pixmap The pixmap to use as the default (normal) one + */ + void setDefaultPixmap(const TQPixmap& pixmap) KDE_DEPRECATED; + + /** + * @deprecated + * Force the button to use this pixmap when disabled one rather then + * generating it using effects. + * + * @param pixmap The pixmap to use when disabled + */ + void setDisabledPixmap(const TQPixmap& pixmap) KDE_DEPRECATED; +#endif + + /** + * Set the text for this button. The text will be either used as a + * tooltip (IconOnly) or will be along side the icon + * + * @param text The button (or tooltip) text + */ + virtual void setText(const TQString &text); + + /** + * Set the icon for this button. The icon will be loaded internally + * with the correct size. This function is preferred over setIconSet + * + * @param icon The name of the icon + */ + virtual void setIcon(const TQString &icon); + + /// @since 3.1 + virtual void setIcon( const TQPixmap &pixmap ) + { TQToolButton::setIcon( pixmap ); } + + /** + * Set the pixmaps for this toolbar button from a TQIconSet. + * If you call this you don't need to call any of the other methods + * that set icons or pixmaps. + * @param iconset The iconset to use + */ + virtual void setIconSet( const TQIconSet &iconset ); + +#ifndef KDE_NO_COMPAT + /** + * @deprecated + * Set the active icon for this button. The pixmap itself is loaded + * internally based on the icon size... .. the disabled and default + * pixmaps, however will only be constructed if generate is + * true. This function is preferred over setPixmap + * + * @param icon The name of the active icon + * @param generate If true, then the other icons are automagically + * generated from this one + */ + KDE_DEPRECATED void setIcon(const TQString &icon, bool generate ) { Q_UNUSED(generate); setIcon( icon ); } + + /** + * @deprecated + * Force the button to use this icon as the default one rather + * then generating it using effects. + * + * @param icon The icon to use as the default (normal) one + */ + void setDefaultIcon(const TQString& icon) KDE_DEPRECATED; + + /** + * @deprecated + * Force the button to use this icon when disabled one rather then + * generating it using effects. + * + * @param icon The icon to use when disabled + */ + void setDisabledIcon(const TQString& icon) KDE_DEPRECATED; +#endif + + /** + * Turn this button on or off + * + * @param flag true or false + */ + void on(bool flag = true); + + /** + * Toggle this button + */ + void toggle(); + + /** + * Turn this button into a toggle button or disable the toggle + * aspects of it. This does not toggle the button itself. + * Use toggle() for that. + * + * @param toggle true or false + */ + void setToggle(bool toggle = true); + + /** + * Return a pointer to this button's popup menu (if it exists) + */ + TQPopupMenu *popup(); + + /** + * Returns the button's id. + * @since 3.2 + */ + int id() const; + + /** + * Give this button a popup menu. There will not be a delay when + * you press the button. Use setDelayedPopup if you want that + * behavior. + * + * @param p The new popup menu + * @param unused Has no effect - ignore it. + */ + void setPopup (TQPopupMenu *p, bool unused = false); + + /** + * Gives this button a delayed popup menu. + * + * This function allows you to add a delayed popup menu to the button. + * The popup menu is then only displayed when the button is pressed and + * held down for about half a second. + * + * @param p the new popup menu + * @param unused Has no effect - ignore it. + */ + void setDelayedPopup(TQPopupMenu *p, bool unused = false); + + /** + * Turn this button into a radio button + * + * @param f true or false + */ + void setRadio(bool f = true); + + /** + * Toolbar buttons naturally will assume the global styles + * concerning icons, icons sizes, etc. You can use this function to + * explicitly turn this off, if you like. + * + * @param no_style Will disable styles if true + */ + void setNoStyle(bool no_style = true); + +signals: + /** + * Emitted when the toolbar button is clicked (with LMB or MMB) + */ + void clicked(int); + /** + * Emitted when the toolbar button is clicked (with any mouse button) + * @param state makes it possible to find out which button was pressed, + * and whether any keyboard modifiers were held. + * @since 3.4 + */ + void buttonClicked(int, TQt::ButtonState state); + void doubleClicked(int); + void pressed(int); + void released(int); + void toggled(int); + void highlighted(int, bool); + +public slots: + /** + * This slot should be called whenever the toolbar mode has + * potentially changed. This includes such events as text changing, + * orientation changing, etc. + */ + void modeChange(); + virtual void setTextLabel(const TQString&, bool tipToo); + +protected: + bool event(TQEvent *e); + void paletteChange(const TQPalette &); + void leaveEvent(TQEvent *e); + void enterEvent(TQEvent *e); + void drawButton(TQPainter *p); + bool eventFilter (TQObject *o, TQEvent *e); + /// @since 3.4 + void mousePressEvent( TQMouseEvent * ); + /// @since 3.4 + void mouseReleaseEvent( TQMouseEvent * ); + void showMenu(); + TQSize sizeHint() const; + TQSize minimumSizeHint() const; + TQSize minimumSize() const; + + /// @since 3.1 + bool isRaised() const; + /// @since 3.1 + bool isActive() const; + /// @since 3.1 + int iconTextMode() const; + +protected slots: + void slotClicked(); + void slotPressed(); + void slotReleased(); + void slotToggled(); + void slotDelayTimeout(); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + TDEToolBarButtonPrivate *d; +}; + +/** +* List of TDEToolBarButton objects. +* @internal +* @version $Id$ +*/ +class TDEUI_EXPORT TDEToolBarButtonList : public TQIntDict +{ +public: + TDEToolBarButtonList(); + ~TDEToolBarButtonList() {} +}; + +#endif diff --git a/tdeui/tdetoolbarhandler.cpp b/tdeui/tdetoolbarhandler.cpp new file mode 100644 index 000000000..1d08565d7 --- /dev/null +++ b/tdeui/tdetoolbarhandler.cpp @@ -0,0 +1,246 @@ +/* This file is part of the KDE libraries + Copyright (C) 2002 Simon Hausmann + + 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. +*/ + +#include "ktoolbarhandler.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + const char *actionListName = "show_menu_and_toolbar_actionlist"; + + const char *guiDescription = "" + "" + "" + "

" + " " + " " + "" + ""; + + const char *resourceFileName = "barhandler.rc"; + + class BarActionBuilder + { + public: + BarActionBuilder( TDEActionCollection *actionCollection, TDEMainWindow *mainWindow, TQPtrList &oldToolBarList ) + : m_actionCollection( actionCollection ), m_mainWindow( mainWindow ), m_needsRebuild( false ) + { + TQPtrList dockWindows = m_mainWindow->dockWindows(); + TQPtrListIterator dockWindowIt( dockWindows ); + for ( ; dockWindowIt.current(); ++dockWindowIt ) { + + TDEToolBar *toolBar = tqt_dynamic_cast( dockWindowIt.current() ); + if ( !toolBar ) + continue; + + if ( oldToolBarList.findRef( toolBar ) == -1 ) + m_needsRebuild = true; + + m_toolBars.append( toolBar ); + } + + if ( !m_needsRebuild ) + m_needsRebuild = ( oldToolBarList.count() != m_toolBars.count() ); + } + + bool needsRebuild() const { return m_needsRebuild; } + + TQPtrList create() + { + if ( !m_needsRebuild ) + return TQPtrList(); + + TQPtrListIterator toolBarIt( m_toolBars ); + for ( ; toolBarIt.current(); ++toolBarIt ) + handleToolBar( toolBarIt.current() ); + + TQPtrList actions; + + if ( m_toolBarActions.count() == 0 ) + return actions; + + if ( m_toolBarActions.count() == 1 ) { + TDEToggleToolBarAction* action = static_cast( m_toolBarActions.getFirst() ); + action->setText( i18n( "Show Toolbar" ) ); + action->setCheckedState( i18n( "Hide Toolbar" ) ); + return m_toolBarActions; + } + + TDEActionMenu *menuAction = new TDEActionMenu( i18n( "Toolbars" ), m_actionCollection, "toolbars_submenu_action" ); + + TQPtrListIterator actionIt( m_toolBarActions ); + for ( ; actionIt.current(); ++actionIt ) + menuAction->insert( actionIt.current() ); + + actions.append( menuAction ); + return actions; + } + + const TQPtrList &toolBars() const { return m_toolBars; } + + private: + void handleToolBar( TDEToolBar *toolBar ) + { + TDEToggleToolBarAction *action = new TDEToggleToolBarAction( + toolBar, + toolBar->label(), + m_actionCollection, + toolBar->name() ); + // ## tooltips, whatsthis? + m_toolBarActions.append( action ); + } + + TDEActionCollection *m_actionCollection; + TDEMainWindow *m_mainWindow; + + TQPtrList m_toolBars; + TQPtrList m_toolBarActions; + + bool m_needsRebuild : 1; + }; +} + +using namespace KDEPrivate; + +ToolBarHandler::ToolBarHandler( TDEMainWindow *mainWindow, const char *name ) + : TQObject( mainWindow, name ), KXMLGUIClient( mainWindow ) +{ + init( mainWindow ); +} + +ToolBarHandler::ToolBarHandler( TDEMainWindow *mainWindow, TQObject *parent, const char *name ) + : TQObject( parent, name ), KXMLGUIClient( mainWindow ) +{ + init( mainWindow ); +} + +ToolBarHandler::~ToolBarHandler() +{ + m_actions.setAutoDelete( true ); + m_actions.clear(); +} + +TDEAction *ToolBarHandler::toolBarMenuAction() +{ + assert( m_actions.count() == 1 ); + return m_actions.getFirst(); +} + +void ToolBarHandler::setupActions() +{ + if ( !factory() || !m_mainWindow ) + return; + + BarActionBuilder builder( actionCollection(), m_mainWindow, m_toolBars ); + + if ( !builder.needsRebuild() ) + return; + + unplugActionList( actionListName ); + + m_actions.setAutoDelete( true ); + m_actions.clear(); + m_actions.setAutoDelete( false ); + + m_actions = builder.create(); + + /* + for ( TQPtrListIterator toolBarIt( m_toolBars ); + toolBarIt.current(); ++toolBarIt ) + toolBarIt.current()->disconnect( this ); + */ + + m_toolBars = builder.toolBars(); + + /* + for ( TQPtrListIterator toolBarIt( m_toolBars ); + toolBarIt.current(); ++toolBarIt ) + connect( toolBarIt.current(), TQT_SIGNAL( destroyed() ), + this, TQT_SLOT( setupActions() ) ); + */ + + if (kapp && kapp->authorizeTDEAction("options_show_toolbar")) + plugActionList( actionListName, m_actions ); + + connectToActionContainers(); +} + +void ToolBarHandler::clientAdded( KXMLGUIClient *client ) +{ + if ( client == this ) + setupActions(); +} + +void ToolBarHandler::init( TDEMainWindow *mainWindow ) +{ + d = 0; + m_mainWindow = mainWindow; + + connect( m_mainWindow->guiFactory(), TQT_SIGNAL( clientAdded( KXMLGUIClient * ) ), + this, TQT_SLOT( clientAdded( KXMLGUIClient * ) ) ); + + /* re-use an existing resource file if it exists. can happen if the user launches the + * toolbar editor */ + /* + setXMLFile( resourceFileName ); + */ + + if ( domDocument().documentElement().isNull() ) { + + TQString completeDescription = TQString::fromLatin1( guiDescription ) + .arg( actionListName ); + + setXML( completeDescription, false /*merge*/ ); + } +} + +void ToolBarHandler::connectToActionContainers() +{ + TQPtrListIterator actionIt( m_actions ); + for ( ; actionIt.current(); ++actionIt ) + connectToActionContainer( actionIt.current() ); +} + +void ToolBarHandler::connectToActionContainer( TDEAction *action ) +{ + uint containerCount = action->containerCount(); + for ( uint i = 0; i < containerCount; ++i ) + connectToActionContainer( action->container( i ) ); +} + +void ToolBarHandler::connectToActionContainer( TQWidget *container ) +{ + TQPopupMenu *popupMenu = tqt_dynamic_cast( container ); + if ( !popupMenu ) + return; + + connect( popupMenu, TQT_SIGNAL( aboutToShow() ), + this, TQT_SLOT( setupActions() ) ); +} + +#include "ktoolbarhandler.moc" + +/* vim: et sw=4 ts=4 + */ diff --git a/tdeui/tdetoolbarhandler.h b/tdeui/tdetoolbarhandler.h new file mode 100644 index 000000000..729129a67 --- /dev/null +++ b/tdeui/tdetoolbarhandler.h @@ -0,0 +1,69 @@ +/* This file is part of the KDE libraries + Copyright (C) 2002 Simon Hausmann + + 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 KBARHANDLER_H +#define KBARHANDLER_H + +#include +#include +#include + +class TDEMainWindow; +class TDEToolBar; + +namespace KDEPrivate +{ + +/// @since 3.1 +class ToolBarHandler : public TQObject, + public KXMLGUIClient +{ + Q_OBJECT +public: + ToolBarHandler( TDEMainWindow *mainWindow, const char *name = 0 ); + ToolBarHandler( TDEMainWindow *mainWindow, TQObject *parent, const char *name = 0 ); + virtual ~ToolBarHandler(); + + TDEAction *toolBarMenuAction(); + +public slots: + void setupActions(); + +private slots: + void clientAdded( KXMLGUIClient *client ); + +private: + void init( TDEMainWindow *mainWindow ); + void connectToActionContainers(); + void connectToActionContainer( TDEAction *action ); + void connectToActionContainer( TQWidget *container ); + + struct Data; + Data *d; + + TQGuardedPtr m_mainWindow; + TQPtrList m_actions; + TQPtrList m_toolBars; +}; + +} // namespace KDEPrivate + +#endif // KBARHANDLER_H + +/* vim: et sw=4 ts=4 + */ diff --git a/tdeui/tdetoolbarlabelaction.cpp b/tdeui/tdetoolbarlabelaction.cpp new file mode 100644 index 000000000..1716a64e8 --- /dev/null +++ b/tdeui/tdetoolbarlabelaction.cpp @@ -0,0 +1,117 @@ +/* This file is part of the KDE libraries + Copyright (C) 2004 Felix Berger + + 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. +*/ + +#include "ktoolbarlabelaction.h" + +#include +#include + +class TDEToolBarLabelAction::TDEToolBarLabelActionPrivate +{ +public: + TDEToolBarLabelActionPrivate() + : m_label(0) + { + } + TQLabel* m_label; +}; + + +TDEToolBarLabelAction::TDEToolBarLabelAction(const TQString &text, + const TDEShortcut &cut, + const TQObject *receiver, + const char *slot, + TDEActionCollection *parent, + const char *name) + : KWidgetAction(new TQLabel(text, 0, "kde toolbar widget"), text, cut, + receiver, slot, parent, name), + d(new TDEToolBarLabelActionPrivate) +{ + init(); +} + +TDEToolBarLabelAction::TDEToolBarLabelAction(TQWidget* buddy, + const TQString &text, + const TDEShortcut &cut, + const TQObject *receiver, + const char *slot, + TDEActionCollection *parent, + const char *name) + : KWidgetAction(new TQLabel(buddy, text, 0, "kde toolbar widget"), text, + cut, receiver, slot, parent, name), + d(new TDEToolBarLabelActionPrivate) +{ + init(); +} + +TDEToolBarLabelAction::TDEToolBarLabelAction(TQLabel* label, + const TDEShortcut &cut, + const TQObject *receiver, + const char *slot, + TDEActionCollection* parent, + const char *name) + : KWidgetAction(label, label->text(), cut, receiver, slot, parent, name), + d(new TDEToolBarLabelActionPrivate) +{ + Q_ASSERT(TQString::fromLatin1("kde toolbar widget") == label->name()); + init(); +} + +TDEToolBarLabelAction::~TDEToolBarLabelAction() +{ + delete d; + d = 0; +} + +void TDEToolBarLabelAction::init() +{ + d->m_label = static_cast(widget()); + /* these lines were copied from Konqueror's KonqDraggableLabel class in + konq_misc.cc */ + d->m_label->setBackgroundMode(TQt::PaletteButton); + d->m_label->setAlignment((TQApplication::reverseLayout() + ? Qt::AlignRight : Qt::AlignLeft) | + Qt::AlignVCenter | TQt::ShowPrefix ); + d->m_label->adjustSize(); +} + +void TDEToolBarLabelAction::setText(const TQString& text) +{ + KWidgetAction::setText(text); + d->m_label->setText(text); +} + +void TDEToolBarLabelAction::setBuddy(TQWidget* buddy) +{ + d->m_label->setBuddy(buddy); +} + +TQWidget* TDEToolBarLabelAction::buddy() const +{ + return d->m_label->buddy(); +} + +TQLabel* TDEToolBarLabelAction::label() const +{ + return d->m_label; +} + +void TDEToolBarLabelAction::virtual_hook(int, void*) +{ + +} diff --git a/tdeui/tdetoolbarlabelaction.h b/tdeui/tdetoolbarlabelaction.h new file mode 100644 index 000000000..02b1cd28c --- /dev/null +++ b/tdeui/tdetoolbarlabelaction.h @@ -0,0 +1,137 @@ +/* This file is part of the KDE libraries + Copyright (C) 2004 Felix Berger + + 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 KTOOLBARLABELACTION_H +#define KTOOLBARLABELACTION_H + +#include + +class TQLabel; + +/** + * @short Class to display a label in a toolbar. + * + * TDEToolBarLabelAction is a convenience class for displaying a label in a + * toolbar. + * + * It provides easy access to the label's #setBuddy(TQWidget*) and #buddy() + * methods and can be used as follows: + * + * \code + * + * KHistoryCombo* findCombo = new KHistoryCombo(true, this); + * KWidgetAction* action + * = new KWidgetAction(findCombo, i18n("F&ind Combo"), Qt::Key_F6, this, + * TQT_SLOT(slotFocus()), actionCollection(), "find_combo"); + * + * new TDEToolBarLabelAction(findCombo, i18n("F&ind "), 0, this, + * TQT_SLOT(slotFocus()), actionCollection(), + * "find_label"); + * + * \endcode + * + * @author Felix Berger + */ +class TDEUI_EXPORT TDEToolBarLabelAction : public KWidgetAction +{ +public: + /** + * Constructs a toolbar label. + * + * @param text The label's and the action's text. + * @param cut The action's shortcut. + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToolBarLabelAction(const TQString &text, + const TDEShortcut &cut, + const TQObject *receiver, const char *slot, + TDEActionCollection *parent, const char *name); + /** + * Constructs a toolbar label setting a buddy for the label. + * + * @param buddy The widget which is focused when the label's accelerator is + * typed. + * @param text The label's and the action's text. + * @param cut The action's shortcut. + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToolBarLabelAction(TQWidget* buddy, const TQString &text, + const TDEShortcut &cut, + const TQObject *receiver, const char *slot, + TDEActionCollection *parent, const char *name); + /** + * Constructs a toolbar label for a label. + * + * You can use this constructor if you want to display a class which is + * derived from TQLabel in the toolbar. Note that ownership of the label is + * transferred to the action and the label is deleted when the action is + * deleted. So you shouldn't hold any pointers to the label. + * + * It's important that the label's name is set to "kde toolbar widget" in + * its constructor, otherwise it is not correctly rendered in some kde + * styles. + * + * @param label the label which is displayed in the toolbar. + * @param cut The action's shortcut. + * @param receiver The SLOT's parent. + * @param slot The TQT_SLOT to invoke to execute this action. + * @param parent This action's parent. + * @param name An internal name for this action. + */ + TDEToolBarLabelAction(TQLabel* label, const TDEShortcut &cut, + const TQObject *receiver, const char *slot, + TDEActionCollection* parent, const char *name); + + virtual ~TDEToolBarLabelAction(); + /** + * Reimplemented to update both the action's text and the label's text. + */ + virtual void setText(const TQString& text); + /** + * Sets the label's buddy to buddy. + * + * See QLabel#setBuddy() for details. + */ + virtual void setBuddy(TQWidget* buddy); + /** + * Returns the label's buddy or 0 if no buddy is currently set. + * + * See QLabel#buddy() and QLabel#setBuddy() for more information. + */ + TQWidget* buddy() const; + /** + * Returns the label which is used internally. + */ + TQLabel* label() const; + +protected: + virtual void virtual_hook(int id, void* data); + +private: + class TDEToolBarLabelActionPrivate; + TDEToolBarLabelActionPrivate *d; + void init(); +}; + + +#endif diff --git a/tdeui/tdetoolbarradiogroup.cpp b/tdeui/tdetoolbarradiogroup.cpp new file mode 100644 index 000000000..7526158b9 --- /dev/null +++ b/tdeui/tdetoolbarradiogroup.cpp @@ -0,0 +1,77 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) + (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) + (C) 1997, 1998 Sven Radej (radej@kde.org) + (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) + (C) 1999 Chris Schlaeger (cs@kde.org) + + 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. +*/ + +#include + +#include "ktoolbarradiogroup.h" +#include "ktoolbar.h" +#include "ktoolbarbutton.h" + +/************************************************************************* + * TDEToolBarRadioGroup * + *************************************************************************/ + + +TDEToolBarRadioGroup::TDEToolBarRadioGroup (TDEToolBar *_parent, const char *_name) +: TQObject(_parent, _name) +{ + buttons = new TDEToolBarButtonList(); + tb = _parent; + connect (tb, TQT_SIGNAL(toggled(int)), this, TQT_SLOT(slotToggled(int))); +} + +TDEToolBarRadioGroup::~TDEToolBarRadioGroup() +{ + delete buttons; +} + +void TDEToolBarRadioGroup::addButton (int id) +{ + TDEToolBarButton *b = tb->getButton( id ); + b->setRadio( true ); + buttons->insert( id, b ); +} + +void TDEToolBarRadioGroup::removeButton (int id) +{ + if (!buttons->find(id)) + return; + buttons->find(id)->setRadio(false); + buttons->remove(id); +} + +void TDEToolBarRadioGroup::slotToggled(int id) +{ + if (buttons->find(id) && buttons->find(id)->isOn()) + { + TQIntDictIterator it(*buttons); + while (it.current()) + { + if (it.currentKey() != id) + it.current()->on(false); + ++it; + } + } +} + +#include "ktoolbarradiogroup.moc" + diff --git a/tdeui/tdetoolbarradiogroup.h b/tdeui/tdetoolbarradiogroup.h new file mode 100644 index 000000000..de567ae62 --- /dev/null +++ b/tdeui/tdetoolbarradiogroup.h @@ -0,0 +1,88 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) + (C) 1997, 1998 Sven Radej (radej@kde.org) + (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) + (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) + + 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 _KTOOLBARRADIOGROUP_H +#define _KTOOLBARRADIOGROUP_H + +#include + +#include + +class TDEToolBar; +class TDEToolBarButtonList; +class TDEToolBarRadioGroupPrivate; + +/************************************************************************* + * TDEToolBarRadioGroup * + *************************************************************************/ + /** + * @short Class for group of radio butons in toolbar. + * + * TDEToolBarRadioGroup is class for group of radio butons in toolbar. + * Take toggle buttons which you already inserted into toolbar, + * create TDEToolBarRadioGroup instance and add them here. + * All buttons will emit signals toggled (bool) (or you can + * use sitgnal toggled (int id) from toolbar). When one button is set + * down, all others are unset. All buttons emit signals - those who + * "go down" and those who "go up". + * + * @author Sven Radej + */ +class TDEUI_EXPORT TDEToolBarRadioGroup : public TQObject +{ + Q_OBJECT + +public: + /** + * Constructor. Parent must be TDEToolBar . + */ + TDEToolBarRadioGroup (TDEToolBar *_parent, const char *_name=0); + /** + * Destructor. + */ + ~TDEToolBarRadioGroup (); + + /** + * Adds button to group. Button cannot be unset by mouse clicks (you + * must press some other button tounset this one) + */ + void addButton (int id); + + /** + * Removes button from group, making it again toggle button (i.e. + * You can unset it with mouse). + */ + void removeButton (int id); + +public slots: + /** + * Internal - nothing for you here. + */ + void slotToggled (int); + +private: + TDEToolBarButtonList *buttons; + TDEToolBar *tb; + + TDEToolBarRadioGroupPrivate *d; +}; + +#endif diff --git a/tdeui/tests/kaccelgentest.cpp b/tdeui/tests/kaccelgentest.cpp deleted file mode 100644 index 783a0f36f..000000000 --- a/tdeui/tests/kaccelgentest.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "kaccelgen.h" - -#include - -#include - -using std::cout; -using std::endl; - -void check( const TQString &what, const TQStringList &expected, const TQStringList &received ) -{ - cout << "Testing " << what.latin1() << ": "; - if ( expected == received ) { - cout << "ok" << endl; - } else { - cout << "ERROR!" << endl; - cout << "Expected: " << expected.join( "," ).latin1() << endl; - cout << "Received: " << received.join( "," ).latin1() << endl; - } -} - -int main() -{ - TQStringList input; - input << "foo" << "bar item" << "&baz" << "bif" << "boz" << "boz 2" - << "yoyo && dyne"; - - TQStringList expected; - expected << "&foo" << "bar &item" << "&baz" << "bif" << "b&oz" << "boz &2" - << "&yoyo && dyne"; - - TQStringList output; - TDEAccelGen::generate( input, output ); - check( "TQStringList value generation", expected, output ); - - TQMap map; - for (TQStringList::ConstIterator it = input.begin(); it != input.end(); ++it) { - map.insert(*it, *it); - } - input.sort(); - expected.clear(); - TDEAccelGen::generate( input, expected ); - - output.clear(); - TDEAccelGen::generateFromValues( map, output ); - check( "map value generation", expected, output ); - - output.clear(); - TDEAccelGen::generateFromKeys( map, output ); - check( "map key generation", expected, output ); -} diff --git a/tdeui/tests/kactiontest.cpp b/tdeui/tests/kactiontest.cpp deleted file mode 100644 index 73a108ab0..000000000 --- a/tdeui/tests/kactiontest.cpp +++ /dev/null @@ -1,38 +0,0 @@ - -#include - -#include -#include - -#include - -int main( int argc, char **argv ) -{ - TDEApplication app( argc, argv, "kactiontest" ); - - TDEActionCollection coll( static_cast( 0 ) ); - - TQGuardedPtr action1 = new TDERadioAction("test",0, &coll); - TQGuardedPtr action2 = new TDERadioAction("test",0, &coll); - TQGuardedPtr action3 = new TDERadioAction("test",0, &coll); - TQGuardedPtr action4 = new TDERadioAction("test",0, &coll); - TQGuardedPtr action5 = new TDERadioAction("test",0, &coll); - TQGuardedPtr action6 = new TDERadioAction("test",0, &coll); - TQGuardedPtr action7 = new TDERadioAction("test",0, &coll); - - coll.clear(); - assert( coll.isEmpty() ); - - assert( action1.isNull() ); - assert( action2.isNull() ); - assert( action3.isNull() ); - assert( action4.isNull() ); - assert( action5.isNull() ); - assert( action6.isNull() ); - assert( action7.isNull() ); - - return 0; -} - -/* vim: et sw=4 ts=4 - */ diff --git a/tdeui/tests/kfontdialogtest.cpp b/tdeui/tests/kfontdialogtest.cpp deleted file mode 100644 index 66f0b3664..000000000 --- a/tdeui/tests/kfontdialogtest.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - $Id$ - - Requires the Qt widget libraries, available at no cost at - http://www.troll.no - - Copyright (C) 1996 Bernd Johannes Wuebben - wuebben@math.cornell.edu - - 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. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - - -#include -#include "kfontdialog.h" -#include - - - int main( int argc, char **argv ) -{ - TDEApplication app( argc, argv, "TDEFontDialogTest" ); - - TDEConfig aConfig; - aConfig.setGroup( "TDEFontDialog-test" ); - - app.setFont(TQFont("Helvetica",12)); - - // TQFont font = TQFont("Times",18,TQFont::Bold); - - TQFont font = aConfig.readFontEntry( "Chosen" ); - int nRet = TDEFontDialog::getFont(font); - int flags; - nRet = TDEFontDialog::getFontDiff(font, flags); - aConfig.writeEntry( "Chosen", font, true ); - - aConfig.sync(); - return nRet; -} diff --git a/tdeui/tests/klistviewtest.cpp b/tdeui/tests/klistviewtest.cpp deleted file mode 100644 index 4be086af6..000000000 --- a/tdeui/tests/klistviewtest.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -#include - - -int main( int argc, char **argv ) -{ - TDEApplication app( argc, argv, "klistviewtest" ); - KDialogBase dialog; - TDEListView *view = new TDEListView( dialog.makeVBoxMainWidget() ); - view->setSelectionModeExt( TDEListView::FileManager ); - view->setDragEnabled( true ); - view->setItemsMovable( false ); - view->setAcceptDrops( true ); - view->addColumn("Column 1"); - view->addColumn("Column 2"); - view->addColumn("Column 3"); - - new TDEListViewItem( view, "Item 1"); - new TDEListViewItem( view, "Item 1"); - new TDEListViewItem( view, "Item 1"); - new TDEListViewItem( view, "Item 1"); - new TDEListViewItem( view, "Item 1"); - new TDEListViewItem( view, "Item 1"); - new TDEListViewItem( view, "Item 1"); - new TDEListViewItem( view, "Item 1"); - new TDEListViewItem( view, "Item 1"); - new TDEListViewItem( view, "Item 2", "Some more", "Hi Mom :)" ); - - view->restoreLayout( TDEGlobal::config(), "ListView" ); - - new TDEListViewItem( view, "Item 3" ); - - dialog.exec(); - view->saveLayout( TDEGlobal::config(), "ListView" ); - - return 0; -} diff --git a/tdeui/tests/kmainwindowrestoretest.cpp b/tdeui/tests/kmainwindowrestoretest.cpp deleted file mode 100644 index 1ef265d92..000000000 --- a/tdeui/tests/kmainwindowrestoretest.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -#include "kmainwindowrestoretest.h" - -#include - -#include - -#define MAKE_WINDOW( kind, title ) do { \ - MainWin##kind * m = new MainWin##kind; \ - m->setCaption( title ); \ - m->setCentralWidget( new TQLabel( title, m ) ); \ - m->show(); \ -} while ( false ) - -int main( int argc, char * argv[] ) { - - TDEApplication app( argc, argv, "kmainwindowrestoretest" ); - - if ( kapp->isRestored() ) { - kRestoreMainWindows< MainWin1, MainWin2, MainWin3 >(); - kRestoreMainWindows< MainWin4, MainWin5 >(); - RESTORE(MainWin6); - //kRestoreMainWindows< MainWin6 >(); // should be equivalent to RESTORE() - } else { - MAKE_WINDOW( 1, "First 1" ); - MAKE_WINDOW( 1, "Second 1" ); - MAKE_WINDOW( 2, "Only 2" ); - MAKE_WINDOW( 3, "First 3" ); - MAKE_WINDOW( 4, "First 4" ); - MAKE_WINDOW( 4, "Second 4" ); - MAKE_WINDOW( 3, "Second 3" ); - MAKE_WINDOW( 4, "Third 4" ); - MAKE_WINDOW( 5, "First 5" ); - MAKE_WINDOW( 5, "Second 5" ); - MAKE_WINDOW( 1, "Only 6" ); - } - - return app.exec(); -} - -#include "kmainwindowrestoretest.moc" diff --git a/tdeui/tests/kmainwindowrestoretest.h b/tdeui/tests/kmainwindowrestoretest.h deleted file mode 100644 index 938311461..000000000 --- a/tdeui/tests/kmainwindowrestoretest.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _TDEUI_TESTS_KMAINWINDOWRESTORETEST_H_ -#define _TDEUI_TESTS_KMAINWINDOWRESTORETEST_H_ - -#include - -class MainWin1 : public TDEMainWindow { - Q_OBJECT -public: - MainWin1() : TDEMainWindow() {} - virtual ~MainWin1() {} -}; - -class MainWin2 : public TDEMainWindow { - Q_OBJECT -public: - MainWin2() : TDEMainWindow() {} - virtual ~MainWin2() {} -}; - -class MainWin3 : public TDEMainWindow { - Q_OBJECT -public: - MainWin3() : TDEMainWindow() {} - virtual ~MainWin3() {} -}; - -class MainWin4 : public TDEMainWindow { - Q_OBJECT -public: - MainWin4() : TDEMainWindow() {} - virtual ~MainWin4() {} -}; - -class MainWin5 : public TDEMainWindow { - Q_OBJECT -public: - MainWin5() : TDEMainWindow() {} - virtual ~MainWin5() {} -}; - -class MainWin6 : public TDEMainWindow { - Q_OBJECT -public: - MainWin6() : TDEMainWindow() {} - virtual ~MainWin6() {} -}; - -#endif // _TDEUI_TESTS_KMAINWINDOWRESTORETEST_H_ diff --git a/tdeui/tests/kmainwindowtest.cpp b/tdeui/tests/kmainwindowtest.cpp deleted file mode 100644 index 6606680e9..000000000 --- a/tdeui/tests/kmainwindowtest.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include - -#include -#include -#include - -#include "kmainwindowtest.h" - -MainWindow::MainWindow() -{ - TQTimer::singleShot( 2*1000, this, TQT_SLOT( showMessage() ) ); - - setCentralWidget( new TQLabel( "foo", this ) ); - - menuBar()->insertItem( "hi" ); -} - -void MainWindow::showMessage() -{ - statusBar()->show(); - statusBar()->message( "test" ); -} - -int main( int argc, char **argv ) -{ - TDEApplication app( argc, argv, "kmainwindowtest" ); - - MainWindow* mw = new MainWindow; // deletes itself when closed - mw->show(); - - return app.exec(); -} - -#include "kmainwindowtest.moc" - -/* vim: et sw=4 ts=4 - */ diff --git a/tdeui/tests/kmainwindowtest.h b/tdeui/tests/kmainwindowtest.h deleted file mode 100644 index 21ca2fe7e..000000000 --- a/tdeui/tests/kmainwindowtest.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef KMAINWINDOWTEST_H -#define KMAINWINDOWTEST_H - -#include - -class MainWindow : public TDEMainWindow -{ - Q_OBJECT -public: - MainWindow(); - -private slots: - void showMessage(); -}; - -#endif // KMAINWINDOWTEST_H -/* vim: et sw=4 ts=4 - */ diff --git a/tdeui/tests/kpopuptest.cpp b/tdeui/tests/kpopuptest.cpp deleted file mode 100644 index 89c932f46..000000000 --- a/tdeui/tests/kpopuptest.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include -#include "kpopupmenu.h" - -class DemoWidget : public TQWidget { -private: - TDEPopupMenu *menu; - -void mousePressEvent(TQMouseEvent *) -{ - menu->popup(TQCursor::pos()); -} - -void paintEvent(TQPaintEvent *) -{ - drawText(32, 32, "Press a Mouse Button!"); -} - -public: - DemoWidget() : TQWidget() - { - menu = new TDEPopupMenu("Popup Menu:"); - menu->insertItem("Item1"); - menu->insertItem("Item2"); - menu->insertSeparator(); - menu->insertItem("Quit", tqApp, TQT_SLOT(quit())); - } -}; - -int main(int argc, char **argv) -{ - TDEApplication app(argc, argv, "kpopupmenutest"); - DemoWidget w; - app.setMainWidget(&w); - w.setFont(TQFont("helvetica", 12, TQFont::Bold), true); - w.show(); - return app.exec(); -} - diff --git a/tdeui/tests/ktoolbarlabelactiontest.cpp b/tdeui/tests/ktoolbarlabelactiontest.cpp deleted file mode 100644 index 9596e9d32..000000000 --- a/tdeui/tests/ktoolbarlabelactiontest.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2004 Felix Berger - - 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. -*/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -class MainWindow : public TDEMainWindow -{ -public: - MainWindow() - { - TQVBox* main = new TQVBox(this); - setCentralWidget(main); - - KSqueezedTextLabel* accel = new KSqueezedTextLabel - ("&Really long, long, long and boring text goes here", main, - "kde toolbar widget"); - new KSqueezedTextLabel - ("Really long, long, long and boring text goes here", main, - "kde toolbar widget"); - - - // first constructor - TDEToolBarLabelAction* label1 = new TDEToolBarLabelAction("&Label 1", 0, - 0, 0, - actionCollection(), - "label1"); - // second constructor - KLineEdit* lineEdit = new KLineEdit(this); - new KWidgetAction(lineEdit, "Line Edit", 0, this, 0, - actionCollection(), "lineEdit"); - TDEToolBarLabelAction* label2 = - new TDEToolBarLabelAction(lineEdit, "L&abel 2", 0, 0, 0, - actionCollection(), - "label2"); - - // set buddy for label1 - label1->setBuddy(lineEdit); - accel->setBuddy(lineEdit); - - // third constructor - TQLabel* customLabel = new KSqueezedTextLabel - ("&Really long, long, long and boring text goes here", this, - "kde toolbar widget"); - - TDEToolBarLabelAction* label3 = new TDEToolBarLabelAction(customLabel, 0, 0, 0, - actionCollection(), - "label3"); - - // set buddy for label3 - label3->setBuddy(lineEdit); - - // customLabel->setText("&test me again some time soon"); - - createGUI("ktoolbarlabelactiontestui.rc"); - } -}; - -int main( int argc, char **argv ) -{ - TDEApplication app( argc, argv, "ktoolbarlabelactiontest" ); - - TDEGlobal::instance()->dirs()->addResourceDir("data", "."); - - MainWindow* mw = new MainWindow; - app.setMainWidget(mw); - mw->show(); - - return app.exec(); -} - diff --git a/tdeui/tests/ktoolbarlabelactiontestui.rc b/tdeui/tests/ktoolbarlabelactiontestui.rc deleted file mode 100644 index 75d02e54e..000000000 --- a/tdeui/tests/ktoolbarlabelactiontestui.rc +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/tdeui/tests/tdeaccelgentest.cpp b/tdeui/tests/tdeaccelgentest.cpp new file mode 100644 index 000000000..783a0f36f --- /dev/null +++ b/tdeui/tests/tdeaccelgentest.cpp @@ -0,0 +1,51 @@ +#include "kaccelgen.h" + +#include + +#include + +using std::cout; +using std::endl; + +void check( const TQString &what, const TQStringList &expected, const TQStringList &received ) +{ + cout << "Testing " << what.latin1() << ": "; + if ( expected == received ) { + cout << "ok" << endl; + } else { + cout << "ERROR!" << endl; + cout << "Expected: " << expected.join( "," ).latin1() << endl; + cout << "Received: " << received.join( "," ).latin1() << endl; + } +} + +int main() +{ + TQStringList input; + input << "foo" << "bar item" << "&baz" << "bif" << "boz" << "boz 2" + << "yoyo && dyne"; + + TQStringList expected; + expected << "&foo" << "bar &item" << "&baz" << "bif" << "b&oz" << "boz &2" + << "&yoyo && dyne"; + + TQStringList output; + TDEAccelGen::generate( input, output ); + check( "TQStringList value generation", expected, output ); + + TQMap map; + for (TQStringList::ConstIterator it = input.begin(); it != input.end(); ++it) { + map.insert(*it, *it); + } + input.sort(); + expected.clear(); + TDEAccelGen::generate( input, expected ); + + output.clear(); + TDEAccelGen::generateFromValues( map, output ); + check( "map value generation", expected, output ); + + output.clear(); + TDEAccelGen::generateFromKeys( map, output ); + check( "map key generation", expected, output ); +} diff --git a/tdeui/tests/tdeactiontest.cpp b/tdeui/tests/tdeactiontest.cpp new file mode 100644 index 000000000..73a108ab0 --- /dev/null +++ b/tdeui/tests/tdeactiontest.cpp @@ -0,0 +1,38 @@ + +#include + +#include +#include + +#include + +int main( int argc, char **argv ) +{ + TDEApplication app( argc, argv, "kactiontest" ); + + TDEActionCollection coll( static_cast( 0 ) ); + + TQGuardedPtr action1 = new TDERadioAction("test",0, &coll); + TQGuardedPtr action2 = new TDERadioAction("test",0, &coll); + TQGuardedPtr action3 = new TDERadioAction("test",0, &coll); + TQGuardedPtr action4 = new TDERadioAction("test",0, &coll); + TQGuardedPtr action5 = new TDERadioAction("test",0, &coll); + TQGuardedPtr action6 = new TDERadioAction("test",0, &coll); + TQGuardedPtr action7 = new TDERadioAction("test",0, &coll); + + coll.clear(); + assert( coll.isEmpty() ); + + assert( action1.isNull() ); + assert( action2.isNull() ); + assert( action3.isNull() ); + assert( action4.isNull() ); + assert( action5.isNull() ); + assert( action6.isNull() ); + assert( action7.isNull() ); + + return 0; +} + +/* vim: et sw=4 ts=4 + */ diff --git a/tdeui/tests/tdefontdialogtest.cpp b/tdeui/tests/tdefontdialogtest.cpp new file mode 100644 index 000000000..66f0b3664 --- /dev/null +++ b/tdeui/tests/tdefontdialogtest.cpp @@ -0,0 +1,51 @@ +/* + $Id$ + + Requires the Qt widget libraries, available at no cost at + http://www.troll.no + + Copyright (C) 1996 Bernd Johannes Wuebben + wuebben@math.cornell.edu + + 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. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + + +#include +#include "kfontdialog.h" +#include + + + int main( int argc, char **argv ) +{ + TDEApplication app( argc, argv, "TDEFontDialogTest" ); + + TDEConfig aConfig; + aConfig.setGroup( "TDEFontDialog-test" ); + + app.setFont(TQFont("Helvetica",12)); + + // TQFont font = TQFont("Times",18,TQFont::Bold); + + TQFont font = aConfig.readFontEntry( "Chosen" ); + int nRet = TDEFontDialog::getFont(font); + int flags; + nRet = TDEFontDialog::getFontDiff(font, flags); + aConfig.writeEntry( "Chosen", font, true ); + + aConfig.sync(); + return nRet; +} diff --git a/tdeui/tests/tdelistviewtest.cpp b/tdeui/tests/tdelistviewtest.cpp new file mode 100644 index 000000000..4be086af6 --- /dev/null +++ b/tdeui/tests/tdelistviewtest.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include + + +int main( int argc, char **argv ) +{ + TDEApplication app( argc, argv, "klistviewtest" ); + KDialogBase dialog; + TDEListView *view = new TDEListView( dialog.makeVBoxMainWidget() ); + view->setSelectionModeExt( TDEListView::FileManager ); + view->setDragEnabled( true ); + view->setItemsMovable( false ); + view->setAcceptDrops( true ); + view->addColumn("Column 1"); + view->addColumn("Column 2"); + view->addColumn("Column 3"); + + new TDEListViewItem( view, "Item 1"); + new TDEListViewItem( view, "Item 1"); + new TDEListViewItem( view, "Item 1"); + new TDEListViewItem( view, "Item 1"); + new TDEListViewItem( view, "Item 1"); + new TDEListViewItem( view, "Item 1"); + new TDEListViewItem( view, "Item 1"); + new TDEListViewItem( view, "Item 1"); + new TDEListViewItem( view, "Item 1"); + new TDEListViewItem( view, "Item 2", "Some more", "Hi Mom :)" ); + + view->restoreLayout( TDEGlobal::config(), "ListView" ); + + new TDEListViewItem( view, "Item 3" ); + + dialog.exec(); + view->saveLayout( TDEGlobal::config(), "ListView" ); + + return 0; +} diff --git a/tdeui/tests/tdemainwindowrestoretest.cpp b/tdeui/tests/tdemainwindowrestoretest.cpp new file mode 100644 index 000000000..1ef265d92 --- /dev/null +++ b/tdeui/tests/tdemainwindowrestoretest.cpp @@ -0,0 +1,41 @@ + +#include "kmainwindowrestoretest.h" + +#include + +#include + +#define MAKE_WINDOW( kind, title ) do { \ + MainWin##kind * m = new MainWin##kind; \ + m->setCaption( title ); \ + m->setCentralWidget( new TQLabel( title, m ) ); \ + m->show(); \ +} while ( false ) + +int main( int argc, char * argv[] ) { + + TDEApplication app( argc, argv, "kmainwindowrestoretest" ); + + if ( kapp->isRestored() ) { + kRestoreMainWindows< MainWin1, MainWin2, MainWin3 >(); + kRestoreMainWindows< MainWin4, MainWin5 >(); + RESTORE(MainWin6); + //kRestoreMainWindows< MainWin6 >(); // should be equivalent to RESTORE() + } else { + MAKE_WINDOW( 1, "First 1" ); + MAKE_WINDOW( 1, "Second 1" ); + MAKE_WINDOW( 2, "Only 2" ); + MAKE_WINDOW( 3, "First 3" ); + MAKE_WINDOW( 4, "First 4" ); + MAKE_WINDOW( 4, "Second 4" ); + MAKE_WINDOW( 3, "Second 3" ); + MAKE_WINDOW( 4, "Third 4" ); + MAKE_WINDOW( 5, "First 5" ); + MAKE_WINDOW( 5, "Second 5" ); + MAKE_WINDOW( 1, "Only 6" ); + } + + return app.exec(); +} + +#include "kmainwindowrestoretest.moc" diff --git a/tdeui/tests/tdemainwindowrestoretest.h b/tdeui/tests/tdemainwindowrestoretest.h new file mode 100644 index 000000000..938311461 --- /dev/null +++ b/tdeui/tests/tdemainwindowrestoretest.h @@ -0,0 +1,48 @@ +#ifndef _TDEUI_TESTS_KMAINWINDOWRESTORETEST_H_ +#define _TDEUI_TESTS_KMAINWINDOWRESTORETEST_H_ + +#include + +class MainWin1 : public TDEMainWindow { + Q_OBJECT +public: + MainWin1() : TDEMainWindow() {} + virtual ~MainWin1() {} +}; + +class MainWin2 : public TDEMainWindow { + Q_OBJECT +public: + MainWin2() : TDEMainWindow() {} + virtual ~MainWin2() {} +}; + +class MainWin3 : public TDEMainWindow { + Q_OBJECT +public: + MainWin3() : TDEMainWindow() {} + virtual ~MainWin3() {} +}; + +class MainWin4 : public TDEMainWindow { + Q_OBJECT +public: + MainWin4() : TDEMainWindow() {} + virtual ~MainWin4() {} +}; + +class MainWin5 : public TDEMainWindow { + Q_OBJECT +public: + MainWin5() : TDEMainWindow() {} + virtual ~MainWin5() {} +}; + +class MainWin6 : public TDEMainWindow { + Q_OBJECT +public: + MainWin6() : TDEMainWindow() {} + virtual ~MainWin6() {} +}; + +#endif // _TDEUI_TESTS_KMAINWINDOWRESTORETEST_H_ diff --git a/tdeui/tests/tdemainwindowtest.cpp b/tdeui/tests/tdemainwindowtest.cpp new file mode 100644 index 000000000..6606680e9 --- /dev/null +++ b/tdeui/tests/tdemainwindowtest.cpp @@ -0,0 +1,38 @@ +#include +#include + +#include +#include +#include + +#include "kmainwindowtest.h" + +MainWindow::MainWindow() +{ + TQTimer::singleShot( 2*1000, this, TQT_SLOT( showMessage() ) ); + + setCentralWidget( new TQLabel( "foo", this ) ); + + menuBar()->insertItem( "hi" ); +} + +void MainWindow::showMessage() +{ + statusBar()->show(); + statusBar()->message( "test" ); +} + +int main( int argc, char **argv ) +{ + TDEApplication app( argc, argv, "kmainwindowtest" ); + + MainWindow* mw = new MainWindow; // deletes itself when closed + mw->show(); + + return app.exec(); +} + +#include "kmainwindowtest.moc" + +/* vim: et sw=4 ts=4 + */ diff --git a/tdeui/tests/tdemainwindowtest.h b/tdeui/tests/tdemainwindowtest.h new file mode 100644 index 000000000..21ca2fe7e --- /dev/null +++ b/tdeui/tests/tdemainwindowtest.h @@ -0,0 +1,18 @@ +#ifndef KMAINWINDOWTEST_H +#define KMAINWINDOWTEST_H + +#include + +class MainWindow : public TDEMainWindow +{ + Q_OBJECT +public: + MainWindow(); + +private slots: + void showMessage(); +}; + +#endif // KMAINWINDOWTEST_H +/* vim: et sw=4 ts=4 + */ diff --git a/tdeui/tests/tdepopuptest.cpp b/tdeui/tests/tdepopuptest.cpp new file mode 100644 index 000000000..89c932f46 --- /dev/null +++ b/tdeui/tests/tdepopuptest.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include "kpopupmenu.h" + +class DemoWidget : public TQWidget { +private: + TDEPopupMenu *menu; + +void mousePressEvent(TQMouseEvent *) +{ + menu->popup(TQCursor::pos()); +} + +void paintEvent(TQPaintEvent *) +{ + drawText(32, 32, "Press a Mouse Button!"); +} + +public: + DemoWidget() : TQWidget() + { + menu = new TDEPopupMenu("Popup Menu:"); + menu->insertItem("Item1"); + menu->insertItem("Item2"); + menu->insertSeparator(); + menu->insertItem("Quit", tqApp, TQT_SLOT(quit())); + } +}; + +int main(int argc, char **argv) +{ + TDEApplication app(argc, argv, "kpopupmenutest"); + DemoWidget w; + app.setMainWidget(&w); + w.setFont(TQFont("helvetica", 12, TQFont::Bold), true); + w.show(); + return app.exec(); +} + diff --git a/tdeui/tests/tdetoolbarlabelactiontest.cpp b/tdeui/tests/tdetoolbarlabelactiontest.cpp new file mode 100644 index 000000000..9596e9d32 --- /dev/null +++ b/tdeui/tests/tdetoolbarlabelactiontest.cpp @@ -0,0 +1,97 @@ +/* This file is part of the KDE libraries + Copyright (C) 2004 Felix Berger + + 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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +class MainWindow : public TDEMainWindow +{ +public: + MainWindow() + { + TQVBox* main = new TQVBox(this); + setCentralWidget(main); + + KSqueezedTextLabel* accel = new KSqueezedTextLabel + ("&Really long, long, long and boring text goes here", main, + "kde toolbar widget"); + new KSqueezedTextLabel + ("Really long, long, long and boring text goes here", main, + "kde toolbar widget"); + + + // first constructor + TDEToolBarLabelAction* label1 = new TDEToolBarLabelAction("&Label 1", 0, + 0, 0, + actionCollection(), + "label1"); + // second constructor + KLineEdit* lineEdit = new KLineEdit(this); + new KWidgetAction(lineEdit, "Line Edit", 0, this, 0, + actionCollection(), "lineEdit"); + TDEToolBarLabelAction* label2 = + new TDEToolBarLabelAction(lineEdit, "L&abel 2", 0, 0, 0, + actionCollection(), + "label2"); + + // set buddy for label1 + label1->setBuddy(lineEdit); + accel->setBuddy(lineEdit); + + // third constructor + TQLabel* customLabel = new KSqueezedTextLabel + ("&Really long, long, long and boring text goes here", this, + "kde toolbar widget"); + + TDEToolBarLabelAction* label3 = new TDEToolBarLabelAction(customLabel, 0, 0, 0, + actionCollection(), + "label3"); + + // set buddy for label3 + label3->setBuddy(lineEdit); + + // customLabel->setText("&test me again some time soon"); + + createGUI("ktoolbarlabelactiontestui.rc"); + } +}; + +int main( int argc, char **argv ) +{ + TDEApplication app( argc, argv, "ktoolbarlabelactiontest" ); + + TDEGlobal::instance()->dirs()->addResourceDir("data", "."); + + MainWindow* mw = new MainWindow; + app.setMainWidget(mw); + mw->show(); + + return app.exec(); +} + diff --git a/tdeui/tests/tdetoolbarlabelactiontestui.rc b/tdeui/tests/tdetoolbarlabelactiontestui.rc new file mode 100644 index 000000000..75d02e54e --- /dev/null +++ b/tdeui/tests/tdetoolbarlabelactiontestui.rc @@ -0,0 +1,9 @@ + + + + + + + + + -- cgit v1.2.3