~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/kvirc/ui/KviMdiManager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   File : KviMdiManager.cpp
 
4
//   Creation date : Wed Jun 21 2000 17:28:04 by Szymon Stefanek
 
5
//
 
6
//   This file is part of the KVIrc irc client distribution
 
7
//   Copyright (C) 2000 Szymon Stefanek (pragma at kvirc dot net)
 
8
//   Copyright (C) 2008 TheXception (kvirc at thexception dot net)
 
9
//
 
10
//   This program is FREE software. You can redistribute it and/or
 
11
//   modify it under the terms of the GNU General Public License
 
12
//   as published by the Free Software Foundation; either version 2
 
13
//   of the License, or (at your opinion) any later version.
 
14
//
 
15
//   This program is distributed in the HOPE that it will be USEFUL,
 
16
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
18
//   See the GNU General Public License for more details.
 
19
//
 
20
//   You should have received a copy of the GNU General Public License
 
21
//   along with this program. If not, write to the Free Software Foundation,
 
22
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
23
//
 
24
//=============================================================================
 
25
 
 
26
/**
 
27
* \file KviMdiManager.cpp
 
28
* \brief The MDI-manager
 
29
*/
 
30
 
 
31
 
 
32
#include "kvi_debug.h"
 
33
#include "kvi_settings.h"
 
34
#include "KviMdiManager.h"
 
35
#include "KviMdiChild.h"
 
36
#include "KviLocale.h"
 
37
#include "KviOptions.h"
 
38
#include "KviIconManager.h"
 
39
#include "KviMainWindow.h"
 
40
#include "KviMenuBar.h"
 
41
#include "KviApplication.h"
 
42
#include "KviTalPopupMenu.h"
 
43
#include "KviTalHBox.h"
 
44
 
 
45
#include <QMenuBar>
 
46
#include <QLayout>
 
47
#include <QPainter>
 
48
#include <QCursor>
 
49
#include <QEvent>
 
50
#include <QMouseEvent>
 
51
#include <QLabel>
 
52
#include <QToolButton>
 
53
 
 
54
#ifdef COMPILE_PSEUDO_TRANSPARENCY
 
55
        #include <QPixmap>
 
56
        extern QPixmap * g_pShadedParentGlobalDesktopBackground;
 
57
#endif
 
58
 
 
59
#include <math.h>
 
60
 
 
61
 
 
62
/**
 
63
* \def KVI_MDICHILD_MIN_WIDTH Defines the minimum width of the child
 
64
* \def KVI_MDICHILD_MIN_HEIGHT Defines the minimum height of the child
 
65
*/
 
66
#define KVI_MDICHILD_MIN_WIDTH 100
 
67
#define KVI_MDICHILD_MIN_HEIGHT 40
 
68
 
 
69
KviMdiManager::KviMdiManager(QWidget * parent,KviMainWindow * pFrm,const char *)
 
70
: QMdiArea(parent)
 
71
{
 
72
        setFrameShape(NoFrame);
 
73
        m_bInSDIMode = KVI_OPTION_BOOL(KviOption_boolMdiManagerInSdiMode);
 
74
        m_pFrm = pFrm;
 
75
 
 
76
        m_pWindowPopup = new KviTalPopupMenu(this);
 
77
        connect(m_pWindowPopup,SIGNAL(activated(int)),this,SLOT(menuActivated(int)));
 
78
        connect(m_pWindowPopup,SIGNAL(aboutToShow()),this,SLOT(fillWindowPopup()));
 
79
        m_pTileMethodPopup = new KviTalPopupMenu(this);
 
80
        connect(m_pTileMethodPopup,SIGNAL(activated(int)),this,SLOT(tileMethodMenuActivated(int)));
 
81
        connect(this, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(slotSubWindowActivated(QMdiSubWindow *)));
 
82
        
 
83
        setAutoFillBackground(false);
 
84
        viewport()->setAutoFillBackground(false);
 
85
 
 
86
        setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
 
87
        setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
 
88
}
 
89
 
 
90
KviMdiManager::~KviMdiManager()
 
91
{
 
92
}
 
93
 
 
94
void KviMdiManager::paintEvent(QPaintEvent * e)
 
95
{
 
96
        QPainter p(viewport());
 
97
 
 
98
#ifdef COMPILE_PSEUDO_TRANSPARENCY
 
99
        if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing())
 
100
        {
 
101
                p.save();
 
102
                p.setCompositionMode(QPainter::CompositionMode_Source);
 
103
                QColor col=KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade);
 
104
                col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyParentFadeFactor) / (float)100));
 
105
                p.fillRect(e->rect(), col);
 
106
                p.restore();
 
107
                return;
 
108
        } else if(g_pShadedParentGlobalDesktopBackground)
 
109
        {
 
110
                QPoint pnt = viewport()->mapTo(g_pMainWindow, e->rect().topLeft() + scrollBarsOffset());
 
111
                p.drawTiledPixmap(e->rect(),*(g_pShadedParentGlobalDesktopBackground), pnt);
 
112
                return;
 
113
        }
 
114
#endif
 
115
        if(KVI_OPTION_PIXMAP(KviOption_pixmapMdiBackground).pixmap())
 
116
        {
 
117
                QPoint pnt = viewport()->mapTo(g_pMainWindow, e->rect().topLeft() + scrollBarsOffset());
 
118
                p.drawTiledPixmap(e->rect(),*(KVI_OPTION_PIXMAP(KviOption_pixmapMdiBackground).pixmap()), pnt);
 
119
        } else {
 
120
                p.fillRect(e->rect(),KVI_OPTION_COLOR(KviOption_colorMdiBackground));
 
121
        }
 
122
}
 
123
 
 
124
void KviMdiManager::manageChild(KviMdiChild * lpC, bool, QRect *)
 
125
{
 
126
        addSubWindow((QMdiSubWindow*)lpC);
 
127
 
 
128
        if(!m_bInSDIMode)
 
129
                if(KVI_OPTION_BOOL(KviOption_boolAutoTileWindows))
 
130
                        tile();
 
131
}
 
132
 
 
133
void KviMdiManager::showAndActivate(KviMdiChild * lpC)
 
134
{
 
135
        if(m_bInSDIMode)
 
136
        {
 
137
                lpC->showMaximized();
 
138
        } else {
 
139
                //qDebug("Showing window %x->%x",lpC,lpC->client());
 
140
                lpC->show();
 
141
                //qDebug("Window %x->%x is visible is %d",lpC,lpC->client(),lpC->isVisible());
 
142
                if(KVI_OPTION_BOOL(KviOption_boolAutoTileWindows))
 
143
                        tile();
 
144
        }
 
145
        setActiveSubWindow(lpC);
 
146
        lpC->setFocus();
 
147
 
 
148
        //qDebug("show and activate window %x->%x: geometry is %d,%d,%d,%d, visible is %d",lpC,lpC->client(),lpC->geometry().x(),lpC->geometry().y(),lpC->geometry().width(),lpC->geometry().height(),lpC->isVisible());
 
149
}
 
150
 
 
151
KviMdiChild * KviMdiManager::topChild()
 
152
{
 
153
        return (KviMdiChild*)activeSubWindow();
 
154
}
 
155
 
 
156
void KviMdiManager::hideChild(KviMdiChild *lpC)
 
157
{
 
158
        focusPreviousTopChild(lpC);
 
159
        lpC->hide();
 
160
}
 
161
 
 
162
void KviMdiManager::destroyChild(KviMdiChild *lpC)
 
163
{
 
164
        removeSubWindow(lpC);
 
165
        delete lpC;
 
166
        
 
167
        if(!m_bInSDIMode)
 
168
        {
 
169
                if(KVI_OPTION_BOOL(KviOption_boolAutoTileWindows))
 
170
                        tile();
 
171
        }
 
172
}
 
173
 
 
174
void KviMdiManager::setIsInSDIMode(bool bMode)
 
175
{
 
176
//      qDebug("Sdi Mode %d", bMode);
 
177
        m_bInSDIMode = bMode;
 
178
        if(!m_bInSDIMode)
 
179
                if(KVI_OPTION_BOOL(KviOption_boolAutoTileWindows))tile();
 
180
};
 
181
 
 
182
void KviMdiManager::focusPreviousTopChild(KviMdiChild * pExcludeThis)
 
183
{
 
184
        KviMdiChild * lpC = NULL;
 
185
 
 
186
        //QList<QMdiSubWindow *> tmp = subWindowList(QMdiArea::ActivationHistoryOrder);
 
187
        QList<QMdiSubWindow *> tmp = subWindowList(QMdiArea::StackingOrder);
 
188
        QListIterator<QMdiSubWindow*> wl(tmp);
 
189
        wl.toBack();
 
190
 
 
191
        while(wl.hasPrevious())
 
192
        {
 
193
                QMdiSubWindow * pSubWindow = wl.previous();
 
194
 
 
195
                if(!pSubWindow->inherits("KviMdiChild"))
 
196
                        continue;
 
197
 
 
198
                lpC = static_cast<KviMdiChild *>(pSubWindow);
 
199
 
 
200
                if(lpC == pExcludeThis)
 
201
                        continue;
 
202
 
 
203
                if(!lpC->isVisible())
 
204
                        continue;
 
205
 
 
206
                if(lpC->state() != KviMdiChild::Minimized)
 
207
                        break;
 
208
        }
 
209
 
 
210
        if(!lpC)
 
211
                return;
 
212
 
 
213
        if(isInSDIMode())
 
214
                lpC->maximize();
 
215
        else {
 
216
                if(KVI_OPTION_BOOL(KviOption_boolAutoTileWindows))
 
217
                        tile();
 
218
        }
 
219
        lpC->raise();
 
220
        if(!lpC->hasFocus())
 
221
                lpC->setFocus();
 
222
}
 
223
 
 
224
#define KVI_TILE_METHOD_ANODINE 0
 
225
#define KVI_TILE_METHOD_PRAGMA4HOR 1
 
226
#define KVI_TILE_METHOD_PRAGMA4VER 2
 
227
#define KVI_TILE_METHOD_PRAGMA6HOR 3
 
228
#define KVI_TILE_METHOD_PRAGMA6VER 4
 
229
#define KVI_TILE_METHOD_PRAGMA9HOR 5
 
230
#define KVI_TILE_METHOD_PRAGMA9VER 6
 
231
 
 
232
#define KVI_NUM_TILE_METHODS 7
 
233
 
 
234
void KviMdiManager::fillWindowPopup()
 
235
{
 
236
        m_pWindowPopup->clear();
 
237
 
 
238
        m_pWindowPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::CascadeWindows)),(__tr2qs("&Cascade Windows")),this,SLOT(cascadeWindows()));
 
239
        m_pWindowPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::CascadeWindows)),(__tr2qs("Cascade &Maximized")),this,SLOT(cascadeMaximized()));
 
240
 
 
241
        m_pWindowPopup->insertSeparator();
 
242
        m_pWindowPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::TileWindows)),(__tr2qs("&Tile Windows")),this,SLOT(tile()));
 
243
 
 
244
        m_pTileMethodPopup->clear();
 
245
        int id = m_pTileMethodPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::AutoTileWindows)),(__tr2qs("&Auto Tile")),this,SLOT(toggleAutoTile()));
 
246
        m_pTileMethodPopup->setItemChecked(id,KVI_OPTION_BOOL(KviOption_boolAutoTileWindows));
 
247
        m_pTileMethodPopup->setItemParameter(id,-1);
 
248
        m_pTileMethodPopup->insertSeparator();
 
249
        int ids[KVI_NUM_TILE_METHODS];
 
250
        ids[KVI_TILE_METHOD_ANODINE] = m_pTileMethodPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::TileWindows)),(__tr2qs("Anodine's Full Grid")));
 
251
        m_pTileMethodPopup->setItemParameter(ids[KVI_TILE_METHOD_ANODINE],KVI_TILE_METHOD_ANODINE);
 
252
        ids[KVI_TILE_METHOD_PRAGMA4HOR] = m_pTileMethodPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::TileWindows)),(__tr2qs("Pragma's Horizontal 4-Grid")));
 
253
        m_pTileMethodPopup->setItemParameter(ids[KVI_TILE_METHOD_PRAGMA4HOR],KVI_TILE_METHOD_PRAGMA4HOR);
 
254
        ids[KVI_TILE_METHOD_PRAGMA4VER] = m_pTileMethodPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::TileWindows)),(__tr2qs("Pragma's Vertical 4-Grid")));
 
255
        m_pTileMethodPopup->setItemParameter(ids[KVI_TILE_METHOD_PRAGMA4VER],KVI_TILE_METHOD_PRAGMA4VER);
 
256
        ids[KVI_TILE_METHOD_PRAGMA6HOR] = m_pTileMethodPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::TileWindows)),(__tr2qs("Pragma's Horizontal 6-Grid")));
 
257
        m_pTileMethodPopup->setItemParameter(ids[KVI_TILE_METHOD_PRAGMA6HOR],KVI_TILE_METHOD_PRAGMA6HOR);
 
258
        ids[KVI_TILE_METHOD_PRAGMA6VER] = m_pTileMethodPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::TileWindows)),(__tr2qs("Pragma's Vertical 6-Grid")));
 
259
        m_pTileMethodPopup->setItemParameter(ids[KVI_TILE_METHOD_PRAGMA6VER],KVI_TILE_METHOD_PRAGMA6VER);
 
260
        ids[KVI_TILE_METHOD_PRAGMA9HOR] = m_pTileMethodPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::TileWindows)),(__tr2qs("Pragma's Horizontal 9-Grid")));
 
261
        m_pTileMethodPopup->setItemParameter(ids[KVI_TILE_METHOD_PRAGMA9HOR],KVI_TILE_METHOD_PRAGMA9HOR);
 
262
        ids[KVI_TILE_METHOD_PRAGMA9VER] = m_pTileMethodPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::TileWindows)),(__tr2qs("Pragma's Vertical 9-Grid")));
 
263
        m_pTileMethodPopup->setItemParameter(ids[KVI_TILE_METHOD_PRAGMA9VER],KVI_TILE_METHOD_PRAGMA9VER);
 
264
 
 
265
        if(KVI_OPTION_UINT(KviOption_uintTileMethod) >= KVI_NUM_TILE_METHODS)KVI_OPTION_UINT(KviOption_uintTileMethod) = KVI_TILE_METHOD_PRAGMA9HOR;
 
266
        m_pTileMethodPopup->setItemChecked(ids[KVI_OPTION_UINT(KviOption_uintTileMethod)],true);
 
267
 
 
268
        m_pWindowPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::TileWindows)),(__tr2qs("Tile Met&hod")),m_pTileMethodPopup);
 
269
 
 
270
        m_pWindowPopup->insertSeparator();
 
271
        m_pWindowPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::MaxVertical)),(__tr2qs("Expand &Vertically")),this,SLOT(expandVertical()));
 
272
        m_pWindowPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::MaxHorizontal)),(__tr2qs("Expand &Horizontally")),this,SLOT(expandHorizontal()));
 
273
 
 
274
        m_pWindowPopup->insertSeparator();
 
275
        m_pWindowPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Minimize)),(__tr2qs("Mi&nimize All")),this,SLOT(minimizeAll()));
 
276
        m_pWindowPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Restore)),(__tr2qs("&Restore all")),this,SLOT(restoreAll()));
 
277
 
 
278
        m_pWindowPopup->insertSeparator();
 
279
        int i = 100;
 
280
        QString szItem;
 
281
        QString szCaption;
 
282
        QList<QMdiSubWindow*> tmp = subWindowList(QMdiArea::StackingOrder);
 
283
        QListIterator<QMdiSubWindow*> it(tmp);
 
284
 
 
285
        KviMdiChild * lpC;
 
286
 
 
287
        while (it.hasNext())
 
288
        {
 
289
                lpC = (KviMdiChild *) it.next();
 
290
 
 
291
                if (!lpC->inherits("KviMdiChild"))
 
292
                {
 
293
                        i++;
 
294
                        continue;
 
295
                }
 
296
 
 
297
                szItem.setNum(((uint)i)-99);
 
298
                szItem+=". ";
 
299
 
 
300
                szCaption = lpC->windowTitle();
 
301
                if(szCaption.length() > 30)
 
302
                {
 
303
                        QString trail = szCaption.right(12);
 
304
                        szCaption.truncate(12);
 
305
                        szCaption+="...";
 
306
                        szCaption+=trail;
 
307
                }
 
308
 
 
309
                if(lpC->state()==KviMdiChild::Minimized)
 
310
                {
 
311
                        szItem+="(";
 
312
                        szItem+=szCaption;
 
313
                        szItem+=")";
 
314
                } else szItem+=szCaption;
 
315
 
 
316
                const QPixmap * pix = lpC->icon();
 
317
 
 
318
                if (pix && !(pix->isNull()))
 
319
                {
 
320
                        m_pWindowPopup->insertItem(*pix, szItem,i);
 
321
                } else {
 
322
                        m_pWindowPopup->insertItem(szItem);
 
323
                }
 
324
 
 
325
                //this is useless, since the windows are listed in stacking order, the active one
 
326
                //will always be the last anyway.
 
327
                //if(lpC==currentSubWindow())
 
328
                //      m_pWindowPopup->setItemChecked(i, true );
 
329
                i++;
 
330
        }
 
331
}
 
332
 
 
333
void KviMdiManager::menuActivated(int id)
 
334
{
 
335
        if(id<100)return;
 
336
        id-=100;
 
337
        QList<QMdiSubWindow *> tmp = subWindowList(QMdiArea::StackingOrder);
 
338
 
 
339
        if(id >= tmp.count()) return;
 
340
        if (!tmp.at(id)->inherits("KviMdiChild")) return;
 
341
 
 
342
        KviMdiChild * lpC = (KviMdiChild *) tmp.at(id);
 
343
 
 
344
        if(!lpC) return;
 
345
        if(lpC->state() == KviMdiChild::Minimized)
 
346
                lpC->restore();
 
347
 
 
348
        setActiveSubWindow(lpC);
 
349
}
 
350
 
 
351
void KviMdiManager::ensureNoMaximized()
 
352
{
 
353
        QList<QMdiSubWindow *> tmp = subWindowList(QMdiArea::StackingOrder);
 
354
 
 
355
        KviMdiChild * lpC;
 
356
 
 
357
        for(int i = 0; i < tmp.count(); i++)
 
358
        {
 
359
                if (tmp.at(i)->inherits("KviMdiChild"))
 
360
                {
 
361
                        lpC = (KviMdiChild *) tmp.at(i);
 
362
                        if(lpC->state() == KviMdiChild::Maximized)lpC->restore();
 
363
                }
 
364
        }
 
365
}
 
366
 
 
367
void KviMdiManager::tileMethodMenuActivated(int id)
 
368
{
 
369
        int idx = m_pTileMethodPopup->itemParameter(id);
 
370
 
 
371
        if(idx < 0) idx = 0;
 
372
        if(idx >= KVI_NUM_TILE_METHODS) idx = KVI_TILE_METHOD_PRAGMA9VER;
 
373
 
 
374
        KVI_OPTION_UINT(KviOption_uintTileMethod) = idx;
 
375
 
 
376
        //we don't check the m_bInSDIMode value here, since it was
 
377
        //the user forcing windows to be tiled
 
378
 
 
379
        if(KVI_OPTION_BOOL(KviOption_boolAutoTileWindows)) tile();
 
380
}
 
381
 
 
382
void KviMdiManager::cascadeWindows()
 
383
{
 
384
        cascadeSubWindows();
 
385
}
 
386
 
 
387
void KviMdiManager::cascadeMaximized()
 
388
{
 
389
        cascadeSubWindows();
 
390
        QList<QMdiSubWindow *> tmp = subWindowList();
 
391
        KviMdiChild * lpC;
 
392
 
 
393
        for(int i = 0; i < tmp.count(); i++)
 
394
        {
 
395
                if (tmp.at(i)->inherits("KviMdiChild"))
 
396
                {
 
397
                        lpC = (KviMdiChild *) tmp.at(i);
 
398
                        if(lpC->state() != KviMdiChild::Minimized)
 
399
                        {
 
400
                                QPoint pnt(lpC->pos());
 
401
                                QSize curSize(viewport()->width() - pnt.x(),viewport()->height() - pnt.y());
 
402
                                if((lpC->minimumSize().width() > curSize.width()) ||
 
403
                                        (lpC->minimumSize().height() > curSize.height()))lpC->resize(lpC->minimumSize());
 
404
                                else lpC->resize(curSize);
 
405
                        }
 
406
                }
 
407
        }
 
408
}
 
409
 
 
410
void KviMdiManager::expandVertical()
 
411
{
 
412
        ensureNoMaximized();
 
413
        QList<QMdiSubWindow *> tmp = subWindowList(QMdiArea::StackingOrder);
 
414
        KviMdiChild * lpC;
 
415
 
 
416
        for(int i = 0; i < tmp.count(); i++)
 
417
        {
 
418
                if (tmp.at(i)->inherits("KviMdiChild"))
 
419
                {
 
420
                        lpC = (KviMdiChild *) tmp.at(i);
 
421
                        if(lpC->state() != KviMdiChild::Minimized)
 
422
                        {
 
423
                                lpC->move(lpC->x(),0);
 
424
                                lpC->resize(lpC->width(),viewport()->height());
 
425
                        }
 
426
                }
 
427
        }
 
428
}
 
429
 
 
430
void KviMdiManager::expandHorizontal()
 
431
{
 
432
        ensureNoMaximized();
 
433
        QList<QMdiSubWindow *> tmp = subWindowList(QMdiArea::StackingOrder);
 
434
        KviMdiChild * lpC;
 
435
 
 
436
        for(int i = 0; i < tmp.count(); i++)
 
437
        {
 
438
                if (tmp.at(i)->inherits("KviMdiChild"))
 
439
                {
 
440
                        lpC = (KviMdiChild *) tmp.at(i);
 
441
                        if(lpC->state() != KviMdiChild::Minimized)
 
442
                        {
 
443
                                lpC->move(0,lpC->y());
 
444
                                lpC->resize(viewport()->width(),lpC->height());
 
445
                        }
 
446
                }
 
447
        }
 
448
}
 
449
 
 
450
void KviMdiManager::minimizeAll()
 
451
{
 
452
        QList<QMdiSubWindow *> tmp = subWindowList(QMdiArea::StackingOrder);
 
453
 
 
454
        KviMdiChild * lpC;
 
455
 
 
456
        for(int i = 0; i < tmp.count(); i++)
 
457
        {
 
458
                if (tmp.at(i)->inherits("KviMdiChild"))
 
459
                {
 
460
                        lpC = (KviMdiChild *) tmp.at(i);
 
461
                        if(lpC->state() != KviMdiChild::Minimized) lpC->minimize();
 
462
                }
 
463
        }
 
464
}
 
465
 
 
466
 
 
467
void KviMdiManager::restoreAll()
 
468
{
 
469
        QList<QMdiSubWindow *> tmp = subWindowList(QMdiArea::StackingOrder);
 
470
 
 
471
        KviMdiChild * lpC;
 
472
 
 
473
        for(int i = 0; i < tmp.count(); i++)
 
474
        {
 
475
                if (tmp.at(i)->inherits("KviMdiChild"))
 
476
                {
 
477
                        lpC = (KviMdiChild *) tmp.at(i);
 
478
                        if(lpC->state() == KviMdiChild::Minimized) lpC->restore();
 
479
                }
 
480
        }
 
481
        if(!m_bInSDIMode)
 
482
                if(KVI_OPTION_BOOL(KviOption_boolAutoTileWindows))tile();
 
483
}
 
484
 
 
485
int KviMdiManager::getVisibleChildCount()
 
486
{
 
487
        QList<QMdiSubWindow *> l = subWindowList();
 
488
 
 
489
        int cnt = 0;
 
490
        int i = 0;
 
491
        for(i = 0; i < l.count(); i++)
 
492
        {
 
493
                if(!l.at(i)->isMinimized()) cnt++;
 
494
        }
 
495
        return cnt;
 
496
}
 
497
 
 
498
void KviMdiManager::tile()
 
499
{
 
500
        switch(KVI_OPTION_UINT(KviOption_uintTileMethod))
 
501
        {
 
502
                case KVI_TILE_METHOD_ANODINE:      tileAnodine(); break;
 
503
                case KVI_TILE_METHOD_PRAGMA4HOR:   tileAllInternal(4,true); break;
 
504
                case KVI_TILE_METHOD_PRAGMA4VER:   tileAllInternal(4,false); break;
 
505
                case KVI_TILE_METHOD_PRAGMA6HOR:   tileAllInternal(6,true); break;
 
506
                case KVI_TILE_METHOD_PRAGMA6VER:   tileAllInternal(6,false); break;
 
507
                case KVI_TILE_METHOD_PRAGMA9HOR:   tileAllInternal(9,true); break;
 
508
                case KVI_TILE_METHOD_PRAGMA9VER:   tileAllInternal(9,false); break;
 
509
                default:
 
510
                        KVI_OPTION_UINT(KviOption_uintTileMethod) = KVI_TILE_METHOD_PRAGMA9HOR;
 
511
                        tileAllInternal(9,true);
 
512
                break;
 
513
        }
 
514
}
 
515
 
 
516
void KviMdiManager::toggleAutoTile()
 
517
{
 
518
        if(KVI_OPTION_BOOL(KviOption_boolAutoTileWindows))
 
519
        {
 
520
                KVI_OPTION_BOOL(KviOption_boolAutoTileWindows) = false;
 
521
        } else {
 
522
                KVI_OPTION_BOOL(KviOption_boolAutoTileWindows) = true;
 
523
                tile();
 
524
        }
 
525
}
 
526
 
 
527
void KviMdiManager::tileAllInternal(int maxWnds, bool bHorizontal) //int maxWnds,bool bHorizontal
 
528
{
 
529
 
 
530
        //NUM WINDOWS =           1,2,3,4,5,6,7,8,9
 
531
        static int colstable[9]={ 1,1,1,2,2,2,3,3,3 }; //num columns
 
532
        static int rowstable[9]={ 1,2,3,2,3,3,3,3,3 }; //num rows
 
533
        static int lastwindw[9]={ 1,1,1,1,2,1,3,2,1 }; //last window multiplier
 
534
        static int colrecall[9]={ 0,0,0,3,3,3,6,6,6 }; //adjust self
 
535
        static int rowrecall[9]={ 0,0,0,0,4,4,4,4,4 }; //adjust self
 
536
 
 
537
        int * pColstable = bHorizontal ? colstable : rowstable;
 
538
        int * pRowstable = bHorizontal ? rowstable : colstable;
 
539
        int * pColrecall = bHorizontal ? colrecall : rowrecall;
 
540
        int * pRowrecall = bHorizontal ? rowrecall : colrecall;
 
541
 
 
542
        ensureNoMaximized();
 
543
        if (g_pApp->kviClosingDown()) return;
 
544
 
 
545
        KviMdiChild * lpTop = topChild();
 
546
        if (!lpTop) return;
 
547
 
 
548
        int numVisible = getVisibleChildCount();
 
549
 
 
550
        if (numVisible < 1) return;
 
551
 
 
552
        int numToHandle = ((numVisible > maxWnds) ? maxWnds : numVisible);
 
553
        int xQuantum = viewport()->width() / pColstable[numToHandle-1];
 
554
 
 
555
        if(xQuantum < ((lpTop->minimumSize().width() > KVI_MDICHILD_MIN_WIDTH) ? lpTop->minimumSize().width() : KVI_MDICHILD_MIN_WIDTH))
 
556
        {
 
557
                if (pColrecall[numToHandle-1] == 0) qDebug("Tile : Not enouh space");
 
558
                        else tileAllInternal(pColrecall[numToHandle-1], bHorizontal);
 
559
                return;
 
560
        }
 
561
 
 
562
        int yQuantum = viewport()->height() / pRowstable[numToHandle-1];
 
563
 
 
564
        if(yQuantum < ((lpTop->minimumSize().height() > KVI_MDICHILD_MIN_HEIGHT) ? lpTop->minimumSize().height() : KVI_MDICHILD_MIN_HEIGHT))
 
565
        {
 
566
                if (pRowrecall[numToHandle-1] == 0) qDebug("Tile : Not enough space");
 
567
                        else tileAllInternal(pRowrecall[numToHandle-1], bHorizontal);
 
568
                return;
 
569
        }
 
570
 
 
571
        int curX = 0;
 
572
        int curY = 0;
 
573
        int curRow = 1;
 
574
        int curCol = 1;
 
575
        int curWin = 1;
 
576
 
 
577
        QList<QMdiSubWindow *> tmp = subWindowList(QMdiArea::StackingOrder);
 
578
 
 
579
        for(int i = 0; i < tmp.count(); i++)
 
580
        {
 
581
                KviMdiChild * lpC = (KviMdiChild*) tmp.at(i);
 
582
 
 
583
                if(lpC->state()!=KviMdiChild::Minimized)
 
584
                {
 
585
                        if((curWin%numToHandle)==0)
 
586
                        {
 
587
                                lpC->move(curX, curY);
 
588
                                lpC->resize(xQuantum * lastwindw[numToHandle-1], yQuantum);
 
589
                        } else {
 
590
                                lpC->move(curX, curY);
 
591
                                lpC->resize(xQuantum, yQuantum);
 
592
                        }
 
593
                        //example : 12 windows : 3 cols 3 rows
 
594
                        if (curCol < pColstable[numToHandle-1])
 
595
                        { //curCol < 3
 
596
                                curX += xQuantum; //add a column in the same row
 
597
                                curCol++;       //increase current column
 
598
                        } else {
 
599
                                curX = 0;         //new row
 
600
                                curCol = 1;       //column 1
 
601
                                if (curRow < pRowstable[numToHandle-1])
 
602
                                { //curRow < 3
 
603
                                        curY += yQuantum; //add a row
 
604
                                        curRow++;
 
605
                                } else {
 
606
                                        curY = 0;         //restart from beginning
 
607
                                        curRow = 1;
 
608
                                }
 
609
                        }
 
610
                        curWin++;
 
611
                }
 
612
        }
 
613
        if(lpTop)lpTop->setFocus();
 
614
}
 
615
 
 
616
void KviMdiManager::tileAnodine()
 
617
{
 
618
        this->tileSubWindows();
 
619
}
 
620
 
 
621
void KviMdiManager::slotSubWindowActivated(QMdiSubWindow * pMdiChild)
 
622
{
 
623
        if(pMdiChild)
 
624
        {
 
625
                if(((KviMdiChild*)pMdiChild)->client() && g_pMainWindow->isActiveWindow())
 
626
                {
 
627
                        //qDebug("subwindowactivated %p %s",pMdiChild, ((KviMdiChild*)pMdiChild)->plainCaption().toUtf8().data());
 
628
                        g_pMainWindow->childWindowActivated((KviWindow *)((KviMdiChild*)pMdiChild)->client());
 
629
                } else {
 
630
                        //qDebug("(inactive) subwindowactivated %p %s",pMdiChild, ((KviMdiChild*)pMdiChild)->plainCaption().toUtf8().data());
 
631
                }
 
632
        } else {
 
633
                //last subwindow deactivated
 
634
                //qDebug("subwindowactivated 0x0");
 
635
        }
 
636
}
 
637
 
 
638
bool KviMdiManager::eventFilter(QObject *obj, QEvent *event)
 
639
{
 
640
        if(
 
641
                (
 
642
                        (event->type() == QEvent::KeyPress) ||
 
643
                        (event->type() == QEvent::KeyRelease)
 
644
                ) &&
 
645
                m_bInSDIMode
 
646
        )
 
647
        {
 
648
                QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
 
649
                if (    (keyEvent->modifiers() & Qt::MetaModifier) ||
 
650
                        (keyEvent->modifiers() & Qt::ControlModifier)
 
651
                )
 
652
                {
 
653
                        // While in sdi mode, avoid qt4's internal window switching
 
654
                        if(keyEvent->key() == Qt::Key_Tab)
 
655
                        {
 
656
                                if(event->type() == QEvent::KeyRelease) g_pMainWindow->switchToNextWindow();
 
657
                                return true;
 
658
                        }
 
659
                        if(keyEvent->key() == Qt::Key_Backtab)
 
660
                        {
 
661
                                if(event->type() == QEvent::KeyRelease) g_pMainWindow->switchToPrevWindow();
 
662
                                return true;
 
663
                        }
 
664
                }
 
665
        } else {
 
666
                /*
 
667
                 * Filter out some (de)activation events from the QMdiArea handling
 
668
                 * this fixed #425 and #519 (unwanted mdichild activation when KviMainWindow is not the active window)
 
669
                 */
 
670
                if(     event->type() == QEvent::ApplicationActivate ||
 
671
                        event->type() == QEvent::ApplicationDeactivate
 
672
                ) return true;
 
673
        }
 
674
        return QMdiArea::eventFilter(obj, event);
 
675
}
 
676