compile
[kdegraphics.git] / kolourpaint / mainWindow / kpMainWindow_View.cpp
blob45cbbb9e9f1f31adfb4bbfc27695ef818e3f1181
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 #include <kpMainWindow.h>
30 #include <kpMainWindowPrivate.h>
32 #include <qdatetime.h>
33 #include <qpainter.h>
34 #include <qtimer.h>
36 #include <kapplication.h>
37 #include <kconfig.h>
38 #include <kconfiggroup.h>
39 #include <kdebug.h>
40 #include <kglobal.h>
41 #include <klocale.h>
42 #include <kselectaction.h>
43 #include <kstandardaction.h>
44 #include <ktoggleaction.h>
45 #include <kactioncollection.h>
47 #include <kpDefs.h>
48 #include <kpDocument.h>
49 #include <kpThumbnail.h>
50 #include <kpTool.h>
51 #include <kpToolToolBar.h>
52 #include <kpUnzoomedThumbnailView.h>
53 #include <kpViewManager.h>
54 #include <kpViewScrollableContainer.h>
55 #include <kpWidgetMapper.h>
56 #include <kpZoomedView.h>
57 #include <kpZoomedThumbnailView.h>
60 // private
61 void kpMainWindow::setupViewMenuActions ()
63 d->viewMenuDocumentActionsEnabled = false;
66 KActionCollection *ac = actionCollection ();
68 /*d->actionFullScreen = KStandardAction::fullScreen (0, 0, ac);
69 d->actionFullScreen->setEnabled (false);*/
72 setupViewMenuZoomActions ();
75 d->actionShowGrid = ac->add <KToggleAction> ("view_show_grid");
76 d->actionShowGrid->setText (i18n ("Show &Grid"));
77 d->actionShowGrid->setShortcut (Qt::CTRL + Qt::Key_G);
78 //d->actionShowGrid->setCheckedState (KGuiItem(i18n ("Hide &Grid")));
79 connect (d->actionShowGrid, SIGNAL (triggered (bool)),
80 SLOT (slotShowGridToggled ()));
83 setupViewMenuThumbnailActions ();
86 enableViewMenuDocumentActions (false);
89 // private
90 bool kpMainWindow::viewMenuDocumentActionsEnabled () const
92 return d->viewMenuDocumentActionsEnabled;
95 // private
96 void kpMainWindow::enableViewMenuDocumentActions (bool enable)
98 d->viewMenuDocumentActionsEnabled = enable;
101 enableViewMenuZoomDocumentActions (enable);
103 actionShowGridUpdate ();
105 enableViewMenuThumbnailDocumentActions (enable);
109 // private
110 void kpMainWindow::actionShowGridUpdate ()
112 #if DEBUG_KP_MAIN_WINDOW
113 kDebug () << "kpMainWindow::actionShowGridUpdate()";
114 #endif
115 const bool enable = (viewMenuDocumentActionsEnabled () &&
116 d->mainView && d->mainView->canShowGrid ());
118 d->actionShowGrid->setEnabled (enable);
119 d->actionShowGrid->setChecked (enable && d->configShowGrid);
122 // private slot
123 void kpMainWindow::slotShowGridToggled ()
125 #if DEBUG_KP_MAIN_WINDOW
126 kDebug () << "kpMainWindow::slotActionShowGridToggled()";
127 #endif
129 updateMainViewGrid ();
132 KConfigGroup cfg (KGlobal::config (), kpSettingsGroupGeneral);
134 cfg.writeEntry (kpSettingShowGrid, d->configShowGrid = d->actionShowGrid->isChecked ());
135 cfg.sync ();
138 // private
139 void kpMainWindow::updateMainViewGrid ()
141 #if DEBUG_KP_MAIN_WINDOW
142 kDebug () << "kpMainWindow::updateMainViewGrid ()";
143 #endif
145 if (d->mainView)
146 d->mainView->showGrid (d->actionShowGrid->isChecked ());
150 // private
151 QRect kpMainWindow::mapToGlobal (const QRect &rect) const
153 return kpWidgetMapper::toGlobal (this, rect);
156 // private
157 QRect kpMainWindow::mapFromGlobal (const QRect &rect) const
159 return kpWidgetMapper::fromGlobal (this, rect);