File indexing completed on 2024-04-28 04:20:22

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 #include "mainWindow/kpMainWindow.h"
0030 #include "kpMainWindowPrivate.h"
0031 #include "kpLogCategories.h"
0032 
0033 #include <KSharedConfig>
0034 #include <KConfigGroup>
0035 #include <KLocalizedString>
0036 #include <KToggleAction>
0037 #include <KActionCollection>
0038 
0039 #include "kpDefs.h"
0040 #include "document/kpDocument.h"
0041 #include "kpThumbnail.h"
0042 #include "tools/kpTool.h"
0043 #include "widgets/toolbars/kpToolToolBar.h"
0044 #include "views/kpUnzoomedThumbnailView.h"
0045 #include "views/manager/kpViewManager.h"
0046 #include "kpViewScrollableContainer.h"
0047 #include "generic/kpWidgetMapper.h"
0048 #include "views/kpZoomedView.h"
0049 #include "views/kpZoomedThumbnailView.h"
0050 
0051 
0052 // private
0053 void kpMainWindow::setupViewMenuActions ()
0054 {
0055     KActionCollection *ac = actionCollection ();
0056 
0057     /*d->actionFullScreen = KStandardAction::fullScreen (0, 0, ac);
0058     d->actionFullScreen->setEnabled (false);*/
0059 
0060 
0061     setupViewMenuZoomActions ();
0062 
0063 
0064     d->actionShowGrid = ac->add <KToggleAction> (QStringLiteral("view_show_grid"));
0065     d->actionShowGrid->setText (i18n ("Show &Grid"));
0066     ac->setDefaultShortcut (d->actionShowGrid, Qt::CTRL | Qt::Key_G);
0067     //d->actionShowGrid->setCheckedState (KGuiItem(i18n ("Hide &Grid")));
0068     connect (d->actionShowGrid, &KToggleAction::triggered,
0069              this, &kpMainWindow::slotShowGridToggled);
0070 
0071 
0072     setupViewMenuThumbnailActions ();
0073 
0074 
0075     enableViewMenuDocumentActions (false);
0076 }
0077 
0078 //---------------------------------------------------------------------
0079 
0080 // private
0081 bool kpMainWindow::viewMenuDocumentActionsEnabled () const
0082 {
0083     return d->viewMenuDocumentActionsEnabled;
0084 }
0085 
0086 //---------------------------------------------------------------------
0087 
0088 // private
0089 void kpMainWindow::enableViewMenuDocumentActions (bool enable)
0090 {
0091     d->viewMenuDocumentActionsEnabled = enable;
0092 
0093 
0094     enableViewMenuZoomDocumentActions (enable);
0095 
0096     actionShowGridUpdate ();
0097 
0098     enableViewMenuThumbnailDocumentActions (enable);
0099 }
0100 
0101 //---------------------------------------------------------------------
0102 
0103 // private
0104 void kpMainWindow::actionShowGridUpdate ()
0105 {
0106 #if DEBUG_KP_MAIN_WINDOW
0107     qCDebug(kpLogMainWindow) << "kpMainWindow::actionShowGridUpdate()";
0108 #endif
0109     const bool enable = (viewMenuDocumentActionsEnabled () &&
0110                          d->mainView && d->mainView->canShowGrid ());
0111 
0112     d->actionShowGrid->setEnabled (enable);
0113     d->actionShowGrid->setChecked (enable && d->configShowGrid);
0114 }
0115 
0116 //---------------------------------------------------------------------
0117 
0118 // private slot
0119 void kpMainWindow::slotShowGridToggled ()
0120 {
0121 #if DEBUG_KP_MAIN_WINDOW
0122     qCDebug(kpLogMainWindow) << "kpMainWindow::slotActionShowGridToggled()";
0123 #endif
0124 
0125     updateMainViewGrid ();
0126 
0127     KConfigGroup cfg (KSharedConfig::openConfig (), QStringLiteral(kpSettingsGroupGeneral));
0128 
0129     cfg.writeEntry (kpSettingShowGrid, d->configShowGrid = d->actionShowGrid->isChecked ());
0130     cfg.sync ();
0131 }
0132 
0133 //---------------------------------------------------------------------
0134 
0135 // private
0136 void kpMainWindow::updateMainViewGrid ()
0137 {
0138 #if DEBUG_KP_MAIN_WINDOW
0139     qCDebug(kpLogMainWindow) << "kpMainWindow::updateMainViewGrid ()";
0140 #endif
0141 
0142     if (d->mainView) {
0143         d->mainView->showGrid (d->actionShowGrid->isChecked ());
0144     }
0145 }
0146 
0147 //---------------------------------------------------------------------
0148 
0149 // private
0150 QRect kpMainWindow::mapToGlobal (const QRect &rect) const
0151 {
0152     return kpWidgetMapper::toGlobal (this, rect);
0153 }
0154 
0155 //---------------------------------------------------------------------
0156 
0157 // private
0158 QRect kpMainWindow::mapFromGlobal (const QRect &rect) const
0159 {
0160     return kpWidgetMapper::fromGlobal (this, rect);
0161 }
0162 
0163 //---------------------------------------------------------------------