summaryrefslogtreecommitdiffstats
path: root/src/komposefullscreenwidget.cpp
blob: 1d0b7e15c50b29506e6e1e225ed00d224067b076 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
//
// C++ Implementation: komposefullscreenwidget
//
// Description:
//
//
// Author: Hans Oischinger <hans.oischinger@kde-mail.net>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "komposefullscreenwidget.h"

#include "komposedesktopwidget.h"
#include "komposetaskwidget.h"
#include "komposeviewmanager.h"
#include "komposetaskmanager.h"
#include "komposeglobal.h"
#include "komposelayout.h"

#include <tqobjectlist.h>
#include <tqptrlist.h>
#include <tqpainter.h>
#include <tqdesktopwidget.h>

#include <twin.h>
#include <tdeapplication.h>
#include <tdepopupmenu.h>
#include <tdeaction.h>
#include <ksharedpixmap.h>
#include <kcursor.h>
#include <tdeglobalsettings.h>
#include <kdebug.h>
#include <krootpixmap.h>

KomposeFullscreenWidget::KomposeFullscreenWidget( int displayType, KomposeLayout *l )
    : KomposeTaskContainerWidget( -1, 0, l ),
    type(displayType)
{
  //   if ( TQT_VERSION < 0x030300 )

  /* use showMaximized instead of setWindowState to make it compile on qt 3.1 or whatever */
  //   showMaximized();
  //   KWin::setState( winId(), NET::KeepAbove );

  // Set Desktop background as our background
  setBackgroundMode( TQt::FixedPixmap );
//   setBackgroundPixmap(*(KomposeGlobal::instance()->getDesktopBgPixmap()));
  rootpix = new KRootPixmap (this);

  // Background blur -- exactly like done in Kicker
  if (KomposeSettings::instance()->getBlurBackground())
    rootpix->setBlurEffect(0.0, 2.0);
  else
    rootpix->setBlurEffect(0.0, 0.0);

  rootpix->start();
  initMenu();
  initView();
  //showFullScreen();

  // Alternate showFullscreen
  setWindowState(windowState() | WindowFullScreen);
  //setWFlags(WStyle_NoBorder);

    kdDebug() << KomposeSettings::instance()->getViewScreen() << endl;
  if (KomposeSettings::instance()->getViewScreen() == -1)
    setGeometry( TDEGlobalSettings::desktopGeometry( this ) );
  else
  {
    TQDesktopWidget deskwidget;
    TQRect deskRect = deskwidget.screenGeometry(KomposeSettings::instance()->getViewScreen());
    setGeometry(deskRect);
    kdDebug() << deskRect << endl;
  }

  if (!isTopLevel())
    TQApplication::sendPostedEvents(this, TQEvent::ShowFullScreen);
  setActiveWindow();

  KWin::setOnAllDesktops( winId(), true );
}

KomposeFullscreenWidget::~KomposeFullscreenWidget()
{
  menu->deleteLater();
}


void KomposeFullscreenWidget::initMenu()
{
  menu = new TDEPopupMenu();

  KomposeGlobal::instance()->getActShowWorldView()->plug(menu);
  KomposeGlobal::instance()->getActShowVirtualDesktopView()->plug(menu);
  KomposeGlobal::instance()->getActShowCurrentDesktopView()->plug(menu);
  menu->insertSeparator();
  KomposeGlobal::instance()->getActPreferencesDialog()->plug(menu);
  KomposeGlobal::instance()->getActConfigGlobalShortcuts()->plug(menu);
  KomposeGlobal::instance()->getActAboutDlg()->plug(menu);
  //menu->insertSeparator();
  //KomposeGlobal::instance()->getActQuit()->plug(menu);
}


void KomposeFullscreenWidget::destroyChildWidgets()
{
  setUpdatesEnabled( false );
  KomposeWidget *child;
  TQPtrListIterator<KomposeWidget> it( *(layout->getManagedWidgets()));
  while ( (child = it.current()) != 0 )
  {
    ++it;
    layout->remove(child);
    dynamic_cast<TQWidget*>(child)->deleteLater();
  }
  setUpdatesEnabled( true );
  kdDebug() << "KomposeFullscreenWidget::destroyChildWidgets() - all children destroyed" << endl;
}

void KomposeFullscreenWidget::initView()
{
  setCursor( KCursor::waitCursor() );

  destroyChildWidgets();

  if ( type == KOMPOSEDISPLAY_VIRTUALDESKS )
  {
    disconnect( KomposeTaskManager::instance(), SIGNAL( newTask( KomposeTask* ) ), this, SLOT( createTaskWidget( KomposeTask* ) ) );
    layout->setType( TLAYOUT_TASKCONTAINERS );
    setDesktop( -2 );
    createDesktopWidgets();
  }
  else if ( type == KOMPOSEDISPLAY_WORLD )
  {
    layout->setType( TLAYOUT_GENERIC );
    setDesktop( -1 );
    createTaskWidgets();
    connect( KomposeTaskManager::instance(), SIGNAL( newTask( KomposeTask* ) ), this, SLOT( createTaskWidget( KomposeTask* ) ) );
  }
  else if ( type == KOMPOSEDISPLAY_CURRENTDESK )
  {
    layout->setType( TLAYOUT_GENERIC );
    setDesktop( KomposeViewManager::instance()->getDesktopBeforeSnaps() );
    createTaskWidgets();
    connect( KomposeTaskManager::instance(), SIGNAL( newTask( KomposeTask* ) ), this, SLOT( createTaskWidget( KomposeTask* ) ) );
  }

  unsetCursor();
}

void KomposeFullscreenWidget::createDesktopWidgets()
{
  kdDebug() << "KomposeFullscreenWidget::createDesktopWidgets()" << endl;
  // Create a Widget for every desktop
  for (int i=0; i < KomposeTaskManager::instance()->getNumDesktops(); ++i)
  {
    //int row = i / 2;
    //int col = i % 2;
    //kdDebug() << "rc %d %d", row, col);
    KomposeDesktopWidget *desktop = new KomposeDesktopWidget(i, this );
    connect( desktop, SIGNAL(contentsChanged()), layout, SLOT(arrangeLayout()) );
    connect( desktop, SIGNAL(activated(KomposeDesktopWidget*)), this, SLOT(desktopChanged(KomposeDesktopWidget*)) );
    desktop->show();
  }
}

void KomposeFullscreenWidget::mouseReleaseEvent (TQMouseEvent * )
{}

void KomposeFullscreenWidget::mousePressEvent ( TQMouseEvent * e )
{
  if ( !rect().contains( e->pos() ) )
    return;

  switch ( e->button() )
  {
  case LeftButton:
    kdDebug() << "KomposeFullscreenWidget::mousePressEvent - Clicked outside of all tasks - Closing view" << endl;
    KomposeViewManager::instance()->closeCurrentView();
    break;
  case MidButton:
    // fall through
  case RightButton:
    menu->popup( e->globalPos() );
    break;
  default:
    // nothing
    break;
  }
}

void KomposeFullscreenWidget::keyPressEvent( TQKeyEvent *e )
{
  if ( e->key() == TQt::Key_Control )
  {
    e->accept();
  }
}

void KomposeFullscreenWidget::keyReleaseEvent ( TQKeyEvent *e )
{
  if ( e->key() == TQt::Key_Escape )
  {
    kdDebug() << "KomposeFullscreenWidget::keyReleaseEvent - Esc key pressed - Closing view" << endl;
    KomposeViewManager::instance()->closeCurrentView();
    e->accept();
  }

  else if ( e->key() == TQt::Key_Control )
  {
    e->accept();
    return;
  }

  // Movement keys
  else if ( e->key() == TQt::Key_Right || e->key() == TQt::Key_D || e->key() == TQt::Key_H ||
            e->key() == TQt::Key_Left  || e->key() == TQt::Key_A || e->key() == TQt::Key_J ||
            e->key() == TQt::Key_Up    || e->key() == TQt::Key_W || e->key() == TQt::Key_K ||
            e->key() == TQt::Key_Down  || e->key() == TQt::Key_S || e->key() == TQt::Key_L )
  {
        // Map keys to directions
    int direction = DLAYOUT_RIGHT;
    switch( e->key() )
    {
    case TQt::Key_Right:
    case TQt::Key_D:
    case TQt::Key_L:
      direction = DLAYOUT_RIGHT;
      break;
    case TQt::Key_Left:
    case TQt::Key_A:
    case TQt::Key_H:
      direction = DLAYOUT_LEFT;
      break;
    case TQt::Key_Up:
    case TQt::Key_W:
    case TQt::Key_K:
      direction = DLAYOUT_TOP;
      break;
    case TQt::Key_Down:
    case TQt::Key_S:
    case TQt::Key_J:
      direction = DLAYOUT_BOTTOM;
      break;
    }

    focusNeighbourDesk( direction );
    e->accept();
    return;
  }

  else
  {
    kdDebug() << "KomposeFullscreenWidget::keyReleaseEvent - ignored..." << endl;
    e->ignore();
  }

  KomposeTaskContainerWidget::keyReleaseEvent(e);
}

bool KomposeFullscreenWidget::focusNeighbourDesk( int direction )
{
  bool successfull = false;
  KomposeWidget *widget;
  if ( ( widget = layout->getNeighbour( dynamic_cast<KomposeWidget*>(current), direction, WLAYOUT_BOTH  ) ) != 0 )
  {
    kdDebug() << "KomposeFullscreenWidget::keyReleaseEvent - Focussing " << widget->className() << endl;
    dynamic_cast<KomposeDesktopWidget*>(widget)->setActive();
    successfull = true;
  }

  return successfull;
}

void KomposeFullscreenWidget::desktopChanged( KomposeDesktopWidget* desk )
{
  kdDebug() << "KomposeFullscreenWidget: desktopChanged" << endl;
  // Remove highlight from all other desks
  const TQObjectList *lst = children();

  if( lst )
  {
    TQObjectListIterator it( *lst );
    TQWidget *widget;
    while ( (widget = (TQWidget*)it.current() ) )
    {
      if ( widget->inherits("KomposeDesktopWidget") )
      {
        dynamic_cast<KomposeDesktopWidget*>(widget)->clearHighlight();
      }
      ++it;
    }
  }

  desk->setHighlight();
  current = desk;
}

int KomposeFullscreenWidget::getHeightForWidth ( int w ) const
{
  return (int)(((double)w / (double)width()) * (double)height());
}

int KomposeFullscreenWidget::getWidthForHeight ( int h ) const
{
  return (int)(((double)h / (double)height()) * (double)width());
}

double KomposeFullscreenWidget::getAspectRatio()
{
  return (double)width() / (double)height();
}

// void KomposeFullscreenWidget::paintEvent ( TQPaintEvent * )
// {
//   TQPainter p( this );
//   p.drawPixmap(rect(), *(KomposeGlobal::instance()->getDesktopBgPixmap()));
//   p.end();
// }


#include "komposefullscreenwidget.moc"