File indexing completed on 2024-04-14 04:16:45

0001 
0002 /*
0003    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0004    All rights reserved.
0005 
0006    Redistribution and use in source and binary forms, with or without
0007    modification, are permitted provided that the following conditions
0008    are met:
0009 
0010    1. Redistributions of source code must retain the above copyright
0011       notice, this list of conditions and the following disclaimer.
0012    2. Redistributions in binary form must reproduce the above copyright
0013       notice, this list of conditions and the following disclaimer in the
0014       documentation and/or other materials provided with the distribution.
0015 
0016    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026 */
0027 
0028 
0029 #define DEBUG_KP_THUMBNAIL 0
0030 
0031 
0032 #include "kpThumbnail.h"
0033 
0034 #include "kpDefs.h"
0035 #include "document/kpDocument.h"
0036 #include "mainWindow/kpMainWindow.h"
0037 #include "views/kpThumbnailView.h"
0038 #include "tools/kpTool.h"
0039 
0040 #include "kpLogCategories.h"
0041 #include <KLocalizedString>
0042 
0043 #include <QAction>
0044 #include <QLayout>
0045 
0046 
0047 struct kpThumbnailPrivate
0048 {
0049     kpMainWindow *mainWindow;
0050     kpThumbnailView *view;
0051     QHBoxLayout *lay;
0052 };
0053 
0054 kpThumbnail::kpThumbnail (kpMainWindow *parent)
0055     : kpSubWindow (parent),
0056       d (new kpThumbnailPrivate ())
0057 {
0058     Q_ASSERT (parent);
0059 
0060     d->mainWindow = parent;
0061     d->view = nullptr;
0062     d->lay = new QHBoxLayout (this);
0063 
0064 
0065     setMinimumSize (64, 64);
0066 
0067 
0068     updateCaption ();
0069 }
0070 
0071 kpThumbnail::~kpThumbnail ()
0072 {
0073     delete d;
0074 }
0075 
0076 
0077 // public
0078 kpThumbnailView *kpThumbnail::view () const
0079 {
0080     return d->view;
0081 }
0082 
0083 // public
0084 void kpThumbnail::setView (kpThumbnailView *view)
0085 {
0086 #if DEBUG_KP_THUMBNAIL
0087     qCDebug(kpLogMisc) << "kpThumbnail::setView(" << view << ")";
0088 #endif
0089 
0090     if (d->view == view) {
0091         return;
0092     }
0093 
0094 
0095     if (d->view)
0096     {
0097         disconnect (d->view, &kpThumbnailView::destroyed,
0098                     this, &kpThumbnail::slotViewDestroyed);
0099 
0100         disconnect (d->view, &kpThumbnailView::zoomLevelChanged,
0101                     this, &kpThumbnail::updateCaption);
0102 
0103         d->lay->removeWidget (d->view);
0104     }
0105 
0106     d->view = view;
0107 
0108     if (d->view)
0109     {
0110         connect (d->view, &kpThumbnailView::destroyed,
0111                  this, &kpThumbnail::slotViewDestroyed);
0112 
0113         connect (d->view, &kpThumbnailView::zoomLevelChanged,
0114                  this, &kpThumbnail::updateCaption);
0115 
0116         Q_ASSERT (d->view->parent () == this);
0117         d->lay->addWidget (d->view, Qt::AlignCenter);
0118         
0119         d->view->show ();
0120     }
0121     
0122     updateCaption ();
0123 }
0124 
0125 
0126 // public slot
0127 void kpThumbnail::updateCaption ()
0128 {
0129     setWindowTitle (view () ? view ()->caption () : i18nc ("@title:window", "Thumbnail"));
0130 }
0131 
0132 
0133 // protected slot
0134 void kpThumbnail::slotViewDestroyed ()
0135 {
0136 #if DEBUG_KP_THUMBNAIL
0137     qCDebug(kpLogMisc) << "kpThumbnail::slotViewDestroyed()";
0138 #endif
0139 
0140     d->view = nullptr;
0141     updateCaption ();
0142 }
0143 
0144 
0145 // protected virtual [base QWidget]
0146 void kpThumbnail::resizeEvent (QResizeEvent *e)
0147 {
0148 #if DEBUG_KP_THUMBNAIL
0149     qCDebug(kpLogMisc) << "kpThumbnail::resizeEvent(" << width ()
0150                << "," << height () << ")";
0151 #endif
0152 
0153     QWidget::resizeEvent (e);
0154 
0155     // updateVariableZoom ();  TODO: is below a good idea since this commented out?
0156 
0157     if (d->mainWindow)
0158     {
0159         d->mainWindow->notifyThumbnailGeometryChanged ();
0160 
0161         if (d->mainWindow->tool ()) {
0162             d->mainWindow->tool ()->somethingBelowTheCursorChanged ();
0163         }
0164     }
0165 }
0166 
0167 // protected virtual [base QWidget]
0168 void kpThumbnail::moveEvent (QMoveEvent * /*e*/)
0169 {
0170     if (d->mainWindow) {
0171         d->mainWindow->notifyThumbnailGeometryChanged ();
0172     }
0173 }
0174 
0175 // protected virtual [base QWidget]
0176 void kpThumbnail::closeEvent (QCloseEvent *e)
0177 {
0178     QWidget::closeEvent (e);
0179 
0180     Q_EMIT windowClosed ();
0181 }
0182 
0183 #include "moc_kpThumbnail.cpp"