1
2/*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28
29#define DEBUG_KP_THUMBNAIL 0
30
31
32#include <kpThumbnail.h>
33
34#include <QAction>
35#include <QLayout>
36
37#include <kdebug.h>
38#include <klocale.h>
39
40#include <kpDefs.h>
41#include <kpDocument.h>
42#include <kpMainWindow.h>
43#include <kpThumbnailView.h>
44#include <kpTool.h>
45
46
47struct kpThumbnailPrivate
48{
49 kpMainWindow *mainWindow;
50 kpThumbnailView *view;
51 QHBoxLayout *lay;
52};
53
54kpThumbnail::kpThumbnail (kpMainWindow *parent)
55 : kpSubWindow (parent),
56 d (new kpThumbnailPrivate ())
57{
58 Q_ASSERT (parent);
59
60 d->mainWindow = parent;
61 d->view = 0;
62 d->lay = new QHBoxLayout (this);
63
64
65 setMinimumSize (64, 64);
66
67
68 updateCaption ();
69}
70
71kpThumbnail::~kpThumbnail ()
72{
73 delete d;
74}
75
76
77// public
78kpThumbnailView *kpThumbnail::view () const
79{
80 return d->view;
81}
82
83// public
84void kpThumbnail::setView (kpThumbnailView *view)
85{
86#if DEBUG_KP_THUMBNAIL
87 kDebug () << "kpThumbnail::setView(" << view << ")";
88#endif
89
90 if (d->view == view)
91 return;
92
93
94 if (d->view)
95 {
96 disconnect (d->view, SIGNAL (destroyed ()),
97 this, SLOT (slotViewDestroyed ()));
98 disconnect (d->view, SIGNAL (zoomLevelChanged (int, int)),
99 this, SLOT (updateCaption ()));
100
101 d->lay->removeWidget (d->view);
102 }
103
104 d->view = view;
105
106 if (d->view)
107 {
108 connect (d->view, SIGNAL (destroyed ()),
109 this, SLOT (slotViewDestroyed ()));
110 connect (d->view, SIGNAL (zoomLevelChanged (int, int)),
111 this, SLOT (updateCaption ()));
112
113 Q_ASSERT (d->view->parent () == this);
114 d->lay->addWidget (d->view, Qt::AlignCenter);
115
116 d->view->show ();
117 }
118
119 updateCaption ();
120}
121
122
123// public slot
124void kpThumbnail::updateCaption ()
125{
126 setWindowTitle (view () ? view ()->caption () : i18nc ("@title:window", "Thumbnail"));
127}
128
129
130// protected slot
131void kpThumbnail::slotViewDestroyed ()
132{
133#if DEBUG_KP_THUMBNAIL
134 kDebug () << "kpThumbnail::slotViewDestroyed()";
135#endif
136
137 d->view = 0;
138 updateCaption ();
139}
140
141
142// protected virtual [base QWidget]
143void kpThumbnail::resizeEvent (QResizeEvent *e)
144{
145#if DEBUG_KP_THUMBNAIL
146 kDebug () << "kpThumbnail::resizeEvent(" << width ()
147 << "," << height () << ")" << endl;
148#endif
149
150 QWidget::resizeEvent (e);
151
152 // updateVariableZoom (); TODO: is below a good idea since this commented out?
153
154 if (d->mainWindow)
155 {
156 d->mainWindow->notifyThumbnailGeometryChanged ();
157
158 if (d->mainWindow->tool ())
159 d->mainWindow->tool ()->somethingBelowTheCursorChanged ();
160 }
161}
162
163// protected virtual [base QWidget]
164void kpThumbnail::moveEvent (QMoveEvent * /*e*/)
165{
166 if (d->mainWindow)
167 d->mainWindow->notifyThumbnailGeometryChanged ();
168}
169
170// protected virtual [base QWidget]
171void kpThumbnail::closeEvent (QCloseEvent *e)
172{
173 QWidget::closeEvent (e);
174
175 emit windowClosed ();
176}
177
178
179#include <kpThumbnail.moc>
180