Bibletime – a bible study tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmdiarea.cpp 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*********
  2. *
  3. * This file is part of BibleTime's source code, http://www.bibletime.info/.
  4. *
  5. * Copyright 1999-2006 by the BibleTime developers.
  6. * The BibleTime source code is licensed under the GNU General Public License version 2.0.
  7. *
  8. **********/
  9. #include "cmdiarea.h"
  10. #include "backend/cswordmoduleinfo.h"
  11. #include "backend/cswordversekey.h"
  12. #include "frontend/displaywindow/cdisplaywindow.h"
  13. #include "frontend/keychooser/ckeychooser.h"
  14. #include "config.h"
  15. //KDE includes
  16. #include <tdepopupmenu.h>
  17. #include <tdeapplication.h>
  18. #include <tdelocale.h>
  19. //QT includes
  20. #include <tqobjectlist.h>
  21. #include <tqtimer.h>
  22. #include <tqevent.h>
  23. #include <tqtimer.h>
  24. CMDIArea::CMDIArea(TQWidget *parent, const char *name )
  25. : TQWorkspace(parent, name),
  26. m_guiOption(Nothing),
  27. m_childEvent(false),
  28. m_appCaption(TQString()) {
  29. initView();
  30. initConnections();
  31. readSettings();
  32. }
  33. /** Initializes the view of the MDI area */
  34. void CMDIArea::initView() {
  35. setPaletteBackgroundColor( parentWidget()->paletteBackgroundColor() ); //work around a KDE bug (IMHO was in KDE 2.x)
  36. }
  37. /** Initilizes the connectiosn to SIGNALS */
  38. void CMDIArea::initConnections() {
  39. connect(this, TQT_SIGNAL(windowActivated(TQWidget*)),
  40. this, TQT_SLOT(slotClientActivated(TQWidget*)));
  41. }
  42. /** Called whan a client window was activated */
  43. void CMDIArea::slotClientActivated(TQWidget* client) {
  44. if (!client || !isUpdatesEnabled()) {
  45. return;
  46. }
  47. CDisplayWindow* sp = dynamic_cast<CDisplayWindow*>(client);
  48. Q_ASSERT(sp);
  49. if (!sp || !sp->isReady()) {
  50. return;
  51. }
  52. TQWidgetList windows = windowList();
  53. for ( TQWidget* w = windows.first(); w; w = windows.next() ) {
  54. //Don't use!! It would disable accel enabling for the active window, see CDisplayWindow::windowActivated
  55. /* if (w == client)
  56. continue;
  57. */
  58. CDisplayWindow* window = dynamic_cast<CDisplayWindow*>(w);
  59. window->windowActivated( (window == sp) ? true : false);
  60. }
  61. emit sigSetToplevelCaption( ( m_appCaption = client->caption().stripWhiteSpace() ) );
  62. }
  63. /** Reimplementation. Used to make use of the fixedGUIOption part. */
  64. void CMDIArea::childEvent( TQChildEvent * e ) {
  65. TQWorkspace::childEvent(e);
  66. if ( m_childEvent || !e) {
  67. return;
  68. }
  69. m_childEvent = true;
  70. if (!windowList().count()) {
  71. m_appCaption = TQString();
  72. emit sigSetToplevelCaption( TDEApplication::kApplication()->makeStdCaption(m_appCaption) );
  73. emit sigLastPresenterClosed();
  74. }
  75. if ((e->inserted() || e->removed()) ) {
  76. if (e->inserted() && e->child() && e->child()->inherits("CDisplayWindow")) {
  77. e->child()->installEventFilter(this); //make sure we catch the events of the new window
  78. }
  79. else if (e->removed() && e->child() && e->child()->inherits("CDisplayWindow")) {
  80. e->child()->removeEventFilter(this); //make sure we catch the events of the new window
  81. }
  82. triggerWindowUpdate();
  83. }
  84. m_childEvent = false;
  85. }
  86. /** Reimplementation */
  87. void CMDIArea::resizeEvent(TQResizeEvent* e) {
  88. TQWorkspace::resizeEvent(e);
  89. if (isUpdatesEnabled()) {
  90. triggerWindowUpdate();
  91. };
  92. }
  93. /** */
  94. void CMDIArea::saveSettings() {}
  95. /** */
  96. void CMDIArea::readSettings() {}
  97. /** Deletes all the presenters in the MDI area. */
  98. void CMDIArea::deleteAll() {
  99. closeAllWindows();
  100. }
  101. /** Enable / disable autoCascading */
  102. void CMDIArea::setGUIOption( const MDIOption& newOption ) {
  103. //now do the initial action
  104. m_guiOption = newOption;
  105. triggerWindowUpdate();
  106. }
  107. /** */
  108. void CMDIArea::myTileVertical() {
  109. if (!isUpdatesEnabled() || !usableWindowList().count() ) {
  110. return;
  111. }
  112. TQPtrList<TQWidget> windows = usableWindowList();
  113. if ((windows.count() == 1) && windows.at(0)) {
  114. m_appCaption = windows.at(0)->caption();
  115. windows.at(0)->showMaximized();
  116. }
  117. else {
  118. TQWidget* active = activeWindow();
  119. TQWorkspace::tile();
  120. active->setFocus();
  121. }
  122. }
  123. void CMDIArea::myTileHorizontal() {
  124. if (!isUpdatesEnabled() || !usableWindowList().count() ) {
  125. return;
  126. }
  127. TQPtrList<TQWidget> windows = usableWindowList();
  128. if ((windows.count() == 1) && windows.at(0)) {
  129. m_appCaption = windows.at(0)->caption();
  130. windows.at(0)/*->parentWidget()*/->showMaximized();
  131. }
  132. else {
  133. TQWidget* active = activeWindow();
  134. if (active->isMaximized()) {
  135. active->showNormal();
  136. }
  137. blockSignals(true);
  138. setUpdatesEnabled(false);
  139. int heightForEach = height() / windows.count();
  140. int y = 0;
  141. for ( int i = 0; i < int(windows.count()); ++i ) {
  142. TQWidget *window = windows.at(i);
  143. window->parentWidget()->showNormal();
  144. tqApp->sendPostedEvents( 0, TQEvent::ShowNormal );
  145. const int preferredHeight = window->minimumHeight() + window->parentWidget()->baseSize().height();
  146. const int actHeight = TQMAX(heightForEach, preferredHeight);
  147. window->parentWidget()->setGeometry( 0, y, width(), actHeight );
  148. y += actHeight;
  149. }
  150. setUpdatesEnabled(true);
  151. active->setFocus();
  152. blockSignals(false);
  153. }
  154. }
  155. /** */
  156. void CMDIArea::myCascade() {
  157. if (!isUpdatesEnabled() || !usableWindowList().count() ) {
  158. return;
  159. }
  160. TQPtrList<TQWidget> windows = usableWindowList();
  161. if ( !windows.count() ) {
  162. return;
  163. }
  164. if ((windows.count() == 1) && windows.at(0)) {
  165. m_appCaption = windows.at(0)->caption();
  166. windows.at(0)->parentWidget()->showMaximized();
  167. }
  168. else {
  169. const int offsetX = 40;
  170. const int offsetY = 40;
  171. const int windowWidth = width() - (windows.count()-1)*offsetX;
  172. const int windowHeight = height() - (windows.count()-1)*offsetY;
  173. int x = 0;
  174. int y = 0;
  175. TQWidget* const active = activeWindow();
  176. if (active->isMaximized()) {
  177. active->showNormal();
  178. }
  179. blockSignals(true);
  180. setUpdatesEnabled(false);
  181. for (int i(0); i < int(windows.count()); ++i) {
  182. TQWidget* window = windows.at(i);
  183. if (window == active) { //leave out the active window which should be the top window
  184. continue;
  185. }
  186. window->setUpdatesEnabled(false);
  187. window->parentWidget()->raise(); //make it the on-top-of-window-stack window to make sure they're in the right order
  188. window->parentWidget()->setGeometry(x, y, windowWidth, windowHeight);
  189. x += offsetX;
  190. y += offsetY;
  191. window->setUpdatesEnabled(true);
  192. }
  193. setUpdatesEnabled(true);
  194. active->parentWidget()->setGeometry(x, y, windowWidth, windowHeight);
  195. active->parentWidget()->raise();
  196. active->setActiveWindow();
  197. blockSignals(false);
  198. }
  199. }
  200. /*!
  201. \fn CMDIArea::emitWindowCaptionChanged()
  202. */
  203. void CMDIArea::emitWindowCaptionChanged() {
  204. if (activeWindow()) {
  205. m_appCaption = activeWindow()->caption();
  206. }
  207. emit sigSetToplevelCaption(currentApplicationCaption());
  208. }
  209. /*!
  210. \fn CMDIArea::usableWindowsCount()
  211. */
  212. TQPtrList<TQWidget> CMDIArea::usableWindowList() {
  213. TQPtrList<TQWidget> ret;
  214. TQWidgetList windows = windowList();
  215. for ( TQWidget* w = windows.first(); w; w = windows.next() ) {
  216. if (w->isMinimized() || w->isHidden()) { //not usable for us
  217. continue;
  218. }
  219. ret.append( w );
  220. }
  221. return ret;
  222. }
  223. bool CMDIArea::eventFilter( TQObject *o, TQEvent *e ) {
  224. Q_ASSERT(o);
  225. Q_ASSERT(e);
  226. TQWidget* w = dynamic_cast<TQWidget*>( o );
  227. bool ret = TQWorkspace::eventFilter(o,e);
  228. if ( w && (e->type() == TQEvent::WindowStateChange) ) {
  229. if (o->inherits("CDisplayWindow") && ((w->windowState() & TQt::WindowMinimized) || w->isHidden())) { //window was minimized, trigger a tile/cascade update if necessary
  230. triggerWindowUpdate();
  231. ret = false;
  232. }
  233. else if (!o->inherits("CDisplayWindow")){
  234. tqDebug("CMDIArea: bad mdi child classname: %s", o->className());
  235. //o->dumpObjectInfo();
  236. //o->dumpObjectTree();
  237. }
  238. }
  239. return ret; // standard event processing
  240. }
  241. /*!
  242. \fn CMDIArea::triggerWindowUpdate()
  243. */
  244. void CMDIArea::triggerWindowUpdate() {
  245. tqDebug("CMDIArea::triggerWindowUpfdate");
  246. if (isUpdatesEnabled() && usableWindowList().count() ) {
  247. switch (m_guiOption) {
  248. case autoTileVertical:
  249. TQTimer::singleShot(0, this, TQT_SLOT(myTileVertical()));
  250. break;
  251. case autoTileHorizontal:
  252. TQTimer::singleShot(0, this, TQT_SLOT(myTileHorizontal()));
  253. break;
  254. case autoCascade:
  255. TQTimer::singleShot(0, this, TQT_SLOT(myCascade()));
  256. break;
  257. default:
  258. tqDebug("CMDIArea::triggerWindowUpdate: no known m_guiType");
  259. break;
  260. }
  261. }
  262. }
  263. #include "cmdiarea.moc"