File indexing completed on 2024-04-28 04:20:21
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 <KActionCollection> 0034 #include <KSharedConfig> 0035 #include <KConfigGroup> 0036 #include <KShortcutsDialog> 0037 #include <KStandardAction> 0038 #include <KToggleFullScreenAction> 0039 #include <KLocalizedString> 0040 0041 #include "kpDefs.h" 0042 #include "document/kpDocument.h" 0043 #include "widgets/toolbars/kpToolToolBar.h" 0044 #include "environments/tools/kpToolEnvironment.h" 0045 0046 //--------------------------------------------------------------------- 0047 0048 // private 0049 void kpMainWindow::setupSettingsMenuActions () 0050 { 0051 KActionCollection *ac = actionCollection (); 0052 0053 0054 // Settings/Toolbars |> %s 0055 setStandardToolBarMenuEnabled (true); 0056 0057 // Settings/Show Statusbar 0058 createStandardStatusBarAction (); 0059 0060 0061 d->actionFullScreen = KStandardAction::fullScreen (this, SLOT (slotFullScreen()), 0062 this/*window*/, ac); 0063 0064 0065 d->actionShowPath = ac->add<KToggleAction> (QStringLiteral("settings_show_path")); 0066 d->actionShowPath->setText (i18n ("Show &Path")); 0067 connect (d->actionShowPath, &QAction::triggered, this, &kpMainWindow::slotShowPathToggled); 0068 slotEnableSettingsShowPath (); 0069 0070 auto *action = ac->add<KToggleAction>(QStringLiteral("settings_draw_antialiased")); 0071 action->setText(i18n("Draw Anti-Aliased")); 0072 action->setChecked(kpToolEnvironment::drawAntiAliased); 0073 connect (action, &KToggleAction::triggered, this, &kpMainWindow::slotDrawAntiAliasedToggled); 0074 0075 d->actionKeyBindings = KStandardAction::keyBindings (this, SLOT (slotKeyBindings()), ac); 0076 0077 KStandardAction::configureToolbars(this, SLOT(configureToolbars()), actionCollection()); 0078 0079 enableSettingsMenuDocumentActions (false); 0080 } 0081 0082 //--------------------------------------------------------------------- 0083 0084 // private 0085 void kpMainWindow::enableSettingsMenuDocumentActions (bool /*enable*/) 0086 { 0087 } 0088 0089 //--------------------------------------------------------------------- 0090 0091 // private slot 0092 void kpMainWindow::slotFullScreen () 0093 { 0094 KToggleFullScreenAction::setFullScreen( this, d->actionFullScreen->isChecked ()); 0095 } 0096 0097 //--------------------------------------------------------------------- 0098 0099 // private slot 0100 void kpMainWindow::slotEnableSettingsShowPath () 0101 { 0102 #if DEBUG_KP_MAIN_WINDOW 0103 qCDebug(kpLogMainWindow) << "kpMainWindow::slotEnableSettingsShowPath()"; 0104 #endif 0105 0106 const bool enable = (d->document && !d->document->url ().isEmpty ()); 0107 0108 d->actionShowPath->setEnabled (enable); 0109 d->actionShowPath->setChecked (enable && d->configShowPath); 0110 } 0111 0112 //--------------------------------------------------------------------- 0113 0114 // private slot 0115 void kpMainWindow::slotShowPathToggled () 0116 { 0117 #if DEBUG_KP_MAIN_WINDOW 0118 qCDebug(kpLogMainWindow) << "kpMainWindow::slotShowPathToggled()"; 0119 #endif 0120 0121 d->configShowPath = d->actionShowPath->isChecked (); 0122 0123 slotUpdateCaption (); 0124 0125 0126 KConfigGroup cfg (KSharedConfig::openConfig (), QStringLiteral(kpSettingsGroupGeneral)); 0127 0128 cfg.writeEntry (kpSettingShowPath, d->configShowPath); 0129 cfg.sync (); 0130 } 0131 0132 //--------------------------------------------------------------------- 0133 0134 void kpMainWindow::slotDrawAntiAliasedToggled(bool on) 0135 { 0136 kpToolEnvironment::drawAntiAliased = on; 0137 0138 KConfigGroup cfg(KSharedConfig::openConfig(), QStringLiteral(kpSettingsGroupGeneral)); 0139 0140 cfg.writeEntry(kpSettingDrawAntiAliased, kpToolEnvironment::drawAntiAliased); 0141 cfg.sync(); 0142 } 0143 0144 //--------------------------------------------------------------------- 0145 0146 // private slot 0147 void kpMainWindow::slotKeyBindings () 0148 { 0149 toolEndShape (); 0150 0151 auto *dlg = new KShortcutsDialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this); 0152 dlg->setAttribute(Qt::WA_DeleteOnClose); 0153 dlg->addCollection(actionCollection()); 0154 0155 // TODO: PROPAGATE: through mainWindow's and interprocess, by connecting to 0156 // KShortcutsDialog::saved() signal 0157 dlg->configure(true /* save settings */); 0158 } 0159 0160 //---------------------------------------------------------------------