handle/discard LCHM entries with no urls
[kdegraphics.git] / kolourpaint / kpThumbnail.cpp
blob9c7f443df7fdd5096f17dab69d46d33bade67940
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
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.
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.
29 #define DEBUG_KP_THUMBNAIL 0
32 #include <kpThumbnail.h>
34 #include <QAction>
35 #include <QLayout>
37 #include <kdebug.h>
38 #include <klocale.h>
40 #include <kpDefs.h>
41 #include <kpDocument.h>
42 #include <kpMainWindow.h>
43 #include <kpThumbnailView.h>
44 #include <kpTool.h>
47 struct kpThumbnailPrivate
49 kpMainWindow *mainWindow;
50 kpThumbnailView *view;
51 QHBoxLayout *lay;
54 kpThumbnail::kpThumbnail (kpMainWindow *parent)
55 : kpSubWindow (parent),
56 d (new kpThumbnailPrivate ())
58 Q_ASSERT (parent);
60 d->mainWindow = parent;
61 d->view = 0;
62 d->lay = new QHBoxLayout (this);
65 setMinimumSize (64, 64);
68 updateCaption ();
71 kpThumbnail::~kpThumbnail ()
73 delete d;
77 // public
78 kpThumbnailView *kpThumbnail::view () const
80 return d->view;
83 // public
84 void kpThumbnail::setView (kpThumbnailView *view)
86 #if DEBUG_KP_THUMBNAIL
87 kDebug () << "kpThumbnail::setView(" << view << ")";
88 #endif
90 if (d->view == view)
91 return;
94 if (d->view)
96 disconnect (d->view, SIGNAL (destroyed ()),
97 this, SLOT (slotViewDestroyed ()));
98 disconnect (d->view, SIGNAL (zoomLevelChanged (int, int)),
99 this, SLOT (updateCaption ()));
101 d->lay->removeWidget (d->view);
104 d->view = view;
106 if (d->view)
108 connect (d->view, SIGNAL (destroyed ()),
109 this, SLOT (slotViewDestroyed ()));
110 connect (d->view, SIGNAL (zoomLevelChanged (int, int)),
111 this, SLOT (updateCaption ()));
113 Q_ASSERT (d->view->parent () == this);
114 d->lay->addWidget (d->view, Qt::AlignCenter);
116 d->view->show ();
119 updateCaption ();
123 // public slot
124 void kpThumbnail::updateCaption ()
126 setWindowTitle (view () ? view ()->caption () : i18n ("Thumbnail"));
130 // protected slot
131 void kpThumbnail::slotViewDestroyed ()
133 #if DEBUG_KP_THUMBNAIL
134 kDebug () << "kpThumbnail::slotViewDestroyed()";
135 #endif
137 d->view = 0;
138 updateCaption ();
142 // protected virtual [base QWidget]
143 void kpThumbnail::resizeEvent (QResizeEvent *e)
145 #if DEBUG_KP_THUMBNAIL
146 kDebug () << "kpThumbnail::resizeEvent(" << width ()
147 << "," << height () << ")" << endl;
148 #endif
150 QWidget::resizeEvent (e);
152 // updateVariableZoom (); TODO: is below a good idea since this commented out?
154 if (d->mainWindow)
156 d->mainWindow->notifyThumbnailGeometryChanged ();
158 if (d->mainWindow->tool ())
159 d->mainWindow->tool ()->somethingBelowTheCursorChanged ();
163 // protected virtual [base QWidget]
164 void kpThumbnail::moveEvent (QMoveEvent * /*e*/)
166 if (d->mainWindow)
167 d->mainWindow->notifyThumbnailGeometryChanged ();
170 // protected virtual [base QWidget]
171 void kpThumbnail::closeEvent (QCloseEvent *e)
173 QWidget::closeEvent (e);
175 emit windowClosed ();
179 #include <kpThumbnail.moc>