summaryrefslogtreecommitdiffstats
path: root/src/komposefullscreenwidget.cpp
blob: 4e656c24ebdc6ee030190c5f97a63a1421c99eed (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
//
// 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);
  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()) );
    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::keyReleaseEvent ( TQKeyEvent * e )
{
  if ( e->key() == TQt::Key_Escape )
  {
    kdDebug() << "KomposeFullscreenWidget::keyReleaseEvent - Esc key pressed - Closing view" << endl;
    KomposeViewManager::instance()->closeCurrentView();
    e->accept();
  }
  else
  {
    kdDebug() << "KomposeFullscreenWidget::keyReleaseEvent - ignored..." << endl;
    e->ignore();
  }
  KomposeTaskContainerWidget::keyReleaseEvent(e);
}

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"