Warning, file /office/skrooge/skgbasegui/skgtabpage.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr 0003 * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 ***************************************************************************/ 0006 /** @file 0007 * This file is a class managing widget. 0008 * 0009 * @author Stephane MANKOWSKI / Guillaume DE BURE 0010 */ 0011 #include "skgtabpage.h" 0012 0013 #include <klocalizedstring.h> 0014 #include <kmessagebox.h> 0015 0016 #include <qwidget.h> 0017 #ifdef SKG_WEBENGINE 0018 #include <qwebengineview.h> 0019 #endif 0020 #ifdef SKG_WEBKIT 0021 #include <qwebview.h> 0022 #endif 0023 #if !defined(SKG_WEBENGINE) && !defined(SKG_WEBKIT) 0024 #include <qlabel.h> 0025 #endif 0026 #include <qmath.h> 0027 0028 #include <cmath> 0029 0030 #include "skgdocument.h" 0031 #include "skghtmlboardwidget.h" 0032 #include "skgmainpanel.h" 0033 #include "skgnodeobject.h" 0034 #include "skgservices.h" 0035 #include "skgtraces.h" 0036 #include "skgtransactionmng.h" 0037 #include "skgtreeview.h" 0038 0039 SKGTabPage::SKGTabPage(QWidget* iParent, SKGDocument* iDocument) 0040 : SKGWidget(iParent, iDocument), m_pin(false) 0041 { 0042 SKGTRACEINFUNC(5) 0043 0044 // Save original size 0045 m_fontOriginalPointSize = this->font().pointSize(); // Use this instead of zoomableWidget() 0046 } 0047 0048 SKGTabPage::~SKGTabPage() 0049 { 0050 SKGTRACEINFUNC(5) 0051 } 0052 0053 bool SKGTabPage::close(bool iForce) 0054 { 0055 SKGTRACEINFUNC(5) 0056 #ifdef SKG_KF_5102 0057 int conf = KMessageBox::PrimaryAction; 0058 #else 0059 int conf = KMessageBox::Yes; 0060 #endif 0061 0062 if (!iForce && isPin()) { 0063 QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); 0064 #ifdef SKG_KF_5102 0065 conf = KMessageBox::questionTwoActions(this, 0066 i18nc("Question", "Do you really want to close this pinned page?"), 0067 i18nc("Question", "Pinned page"), 0068 KStandardGuiItem::apply(), 0069 KStandardGuiItem::cancel(), 0070 QStringLiteral("closepinnedpage")); 0071 #else 0072 conf = KMessageBox::questionYesNo(this, 0073 i18nc("Question", "Do you really want to close this pinned page?"), 0074 i18nc("Question", "Pinned page"), 0075 KStandardGuiItem::yes(), 0076 KStandardGuiItem::no(), 0077 QStringLiteral("closepinnedpage")); 0078 #endif 0079 QApplication::restoreOverrideCursor(); 0080 } 0081 overwrite(); 0082 #ifdef SKG_KF_5102 0083 if (conf == KMessageBox::SecondaryAction) { 0084 #else 0085 if (conf == KMessageBox::No) { 0086 #endif 0087 return false; 0088 } 0089 return QWidget::close(); 0090 } 0091 0092 void SKGTabPage::setBookmarkID(const QString& iId) 0093 { 0094 m_bookmarkID = iId; 0095 } 0096 0097 QString SKGTabPage::getBookmarkID() 0098 { 0099 return m_bookmarkID; 0100 } 0101 SKGTabPage::SKGPageHistoryItemList SKGTabPage::getPreviousPages() 0102 { 0103 return m_previousPages; 0104 } 0105 0106 void SKGTabPage::setPreviousPages(const SKGTabPage::SKGPageHistoryItemList& iPages) 0107 { 0108 m_previousPages = iPages; 0109 } 0110 0111 SKGTabPage::SKGPageHistoryItemList SKGTabPage::getNextPages() 0112 { 0113 return m_nextPages; 0114 } 0115 0116 void SKGTabPage::setNextPages(const SKGTabPage::SKGPageHistoryItemList& iPages) 0117 { 0118 m_nextPages = iPages; 0119 } 0120 0121 bool SKGTabPage::isOverwriteNeeded() 0122 { 0123 // Is this widget linked to a bookmark ? 0124 if (!m_bookmarkID.isEmpty()) { 0125 // Yes. Is state modified ? 0126 SKGNodeObject node(getDocument(), SKGServices::stringToInt(m_bookmarkID)); 0127 if (node.exist()) { 0128 QStringList d = SKGServices::splitCSVLine(node.getData()); 0129 if (d.count() > 2) { 0130 QString currentState = getState().trimmed(); 0131 QString oldState = d[2].trimmed(); 0132 currentState.remove('\n'); 0133 oldState.remove('\n'); 0134 SKGTRACEL(20) << "oldState =[" << oldState << ']' << SKGENDL; 0135 SKGTRACEL(20) << "currentState =[" << currentState << ']' << SKGENDL; 0136 SKGTRACEL(20) << "Bookmark diff =" << (currentState != oldState ? "TRUE" : "FALSE") << SKGENDL; 0137 return (currentState != oldState); 0138 } 0139 } 0140 } else { 0141 // No. It is a page opened from context or from another page 0142 QString name = getDefaultStateAttribute(); 0143 if (!name.isEmpty()) { 0144 QString currentState = getState().trimmed(); 0145 QString oldState = getDocument()->getParameter(name); 0146 currentState.remove('\n'); 0147 oldState.remove('\n'); 0148 SKGTRACEL(20) << "oldState =[" << oldState << ']' << SKGENDL; 0149 SKGTRACEL(20) << "currentState =[" << currentState << ']' << SKGENDL; 0150 SKGTRACEL(20) << "Page diff =" << (currentState != oldState ? "TRUE" : "FALSE") << SKGENDL; 0151 return (currentState != oldState); 0152 } 0153 } 0154 return false; 0155 } 0156 0157 void SKGTabPage::overwrite(bool iUserConfirmation) 0158 { 0159 SKGTRACEINFUNC(10) 0160 // Is this widget linked to a bookmark ? 0161 if (!m_bookmarkID.isEmpty()) { 0162 // Yes. Is state modified ? 0163 SKGNodeObject node(getDocument(), SKGServices::stringToInt(m_bookmarkID)); 0164 if (node.exist()) { 0165 QStringList d = SKGServices::splitCSVLine(node.getData()); 0166 QString fullname = node.getFullName(); 0167 if (d.count() > 2) { 0168 QString currentState = getState().trimmed(); 0169 QString oldState = d[2].trimmed(); 0170 currentState.remove('\n'); 0171 oldState.remove('\n'); 0172 SKGTRACEL(20) << "oldState =[" << oldState << ']' << SKGENDL; 0173 SKGTRACEL(20) << "currentState =[" << currentState << ']' << SKGENDL; 0174 if (currentState != oldState) { 0175 QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); 0176 #ifdef SKG_KF_5102 0177 int conf = KMessageBox::PrimaryAction; 0178 #else 0179 int conf = KMessageBox::Yes; 0180 #endif 0181 if (iUserConfirmation && !oldState.isEmpty()) { 0182 #ifdef SKG_KF_5102 0183 conf = KMessageBox::questionTwoActions(this, 0184 i18nc("Question", "Bookmark '%1' has been modified. Do you want to update it with the current state?", fullname), 0185 i18nc("Question", "Bookmark has been modified"), 0186 KStandardGuiItem::apply(), 0187 KStandardGuiItem::cancel(), 0188 QStringLiteral("updateBookmarkOnClose")); 0189 #else 0190 conf = KMessageBox::questionYesNo(this, 0191 i18nc("Question", "Bookmark '%1' has been modified. Do you want to update it with the current state?", fullname), 0192 i18nc("Question", "Bookmark has been modified"), 0193 KStandardGuiItem::yes(), 0194 KStandardGuiItem::no(), 0195 QStringLiteral("updateBookmarkOnClose")); 0196 #endif 0197 } 0198 QApplication::restoreOverrideCursor(); 0199 #ifdef SKG_KF_5102 0200 if (conf == KMessageBox::PrimaryAction) { 0201 #else 0202 if (conf == KMessageBox::Yes) { 0203 #endif 0204 SKGError err; 0205 { 0206 SKGBEGINLIGHTTRANSACTION(*getDocument(), i18nc("Noun, name of the user action", "Bookmark update '%1'", fullname), err) 0207 d[2] = currentState; 0208 IFOKDO(err, node.setData(SKGServices::stringsToCsv(d))) 0209 IFOKDO(err, node.save()) 0210 } 0211 IFOKDO(err, SKGError(0, i18nc("Successful message after an user action", "Bookmark updated"))) 0212 SKGMainPanel::displayErrorMessage(err); 0213 } 0214 } 0215 } 0216 } 0217 } else { 0218 // No. It is a page opened from context or from another page 0219 QString name = getDefaultStateAttribute(); 0220 if (!name.isEmpty()) { 0221 QString currentState = getState().trimmed(); 0222 QString oldState = getDocument()->getParameter(name); 0223 SKGTRACEL(20) << "oldState =[" << oldState << ']' << SKGENDL; 0224 SKGTRACEL(20) << "currentState =[" << currentState << ']' << SKGENDL; 0225 currentState.remove('\n'); 0226 oldState.remove('\n'); 0227 if (currentState != oldState) { 0228 QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); 0229 #ifdef SKG_KF_5102 0230 int conf = KMessageBox::PrimaryAction; 0231 #else 0232 int conf = KMessageBox::Yes; 0233 #endif 0234 if (iUserConfirmation && !oldState.isEmpty()) { 0235 #ifdef SKG_KF_5102 0236 conf = KMessageBox::questionTwoActions(this, 0237 i18nc("Question", "Page has been modified. Do you want to update it with the current state?"), 0238 i18nc("Question", "Page has been modified"), 0239 KStandardGuiItem::apply(), 0240 KStandardGuiItem::cancel(), 0241 QStringLiteral("updateContextOnClose")); 0242 #else 0243 conf = KMessageBox::questionYesNo(this, 0244 i18nc("Question", "Page has been modified. Do you want to update it with the current state?"), 0245 i18nc("Question", "Page has been modified"), 0246 KStandardGuiItem::yes(), 0247 KStandardGuiItem::no(), 0248 QStringLiteral("updateContextOnClose")); 0249 #endif 0250 } 0251 QApplication::restoreOverrideCursor(); 0252 #ifdef SKG_KF_5102 0253 if (conf == KMessageBox::PrimaryAction) { 0254 #else 0255 if (conf == KMessageBox::Yes) { 0256 #endif 0257 SKGError err; 0258 { 0259 SKGBEGINLIGHTTRANSACTION(*getDocument(), i18nc("Noun, name of the user action", "Save default state"), err) 0260 err = getDocument()->setParameter(name, currentState); 0261 } 0262 IFOKDO(err, SKGError(0, i18nc("Successful message after an user action", "Default state saved"))) 0263 SKGMainPanel::displayErrorMessage(err); 0264 } 0265 } 0266 } 0267 } 0268 } 0269 0270 0271 bool SKGTabPage::isEditor() 0272 { 0273 return false; 0274 } 0275 0276 void SKGTabPage::activateEditor() {} 0277 0278 QWidget* SKGTabPage::zoomableWidget() 0279 { 0280 return mainWidget(); 0281 } 0282 0283 QList< QWidget* > SKGTabPage::printableWidgets() 0284 { 0285 QList< QWidget* > output; 0286 output.push_back(mainWidget()); 0287 return output; 0288 } 0289 0290 bool SKGTabPage::isZoomable() 0291 { 0292 return (zoomableWidget() != nullptr); 0293 } 0294 0295 void SKGTabPage::setZoomPosition(int iValue) 0296 { 0297 QWidget* widget = zoomableWidget(); 0298 auto* treeView = qobject_cast<SKGTreeView*>(widget); 0299 if (treeView != nullptr) { 0300 treeView->setZoomPosition(iValue); 0301 } else { 0302 #ifdef SKG_WEBENGINE 0303 auto webView = qobject_cast<QWebEngineView*>(widget); 0304 #endif 0305 #ifdef SKG_WEBKIT 0306 auto webView = qobject_cast<QWebView*>(widget); 0307 #endif 0308 #if defined(SKG_WEBENGINE) || defined(SKG_WEBKIT) 0309 if (webView != nullptr) { 0310 webView->setZoomFactor(qPow(10, static_cast<qreal>(iValue) / 30.0)); 0311 } else { 0312 int pointSize = qMax(1, m_fontOriginalPointSize + iValue); 0313 QFont f = widget->font(); 0314 f.setPointSize(pointSize); 0315 widget->setFont(f); 0316 0317 auto cs = widget->findChildren<SKGHtmlBoardWidget*>(); 0318 for (auto c : qAsConst(cs)) { 0319 c->setPointSize(pointSize); 0320 } 0321 } 0322 #endif 0323 } 0324 } 0325 0326 int SKGTabPage::zoomPosition() 0327 { 0328 int output = 0; 0329 QWidget* widget = zoomableWidget(); 0330 auto* treeView = qobject_cast<SKGTreeView*>(widget); 0331 if (treeView != nullptr) { 0332 output = treeView->zoomPosition(); 0333 } else { 0334 #ifdef SKG_WEBENGINE 0335 auto webView = qobject_cast<QWebEngineView*>(widget); 0336 #endif 0337 #ifdef SKG_WEBKIT 0338 auto webView = qobject_cast<QWebView*>(widget); 0339 #endif 0340 #if defined(SKG_WEBENGINE) || defined(SKG_WEBKIT) 0341 if (webView != nullptr) { 0342 output = qRound(30.0 * log10(webView->zoomFactor())); 0343 } else if (widget != nullptr) { 0344 output = widget->font().pointSize() - m_fontOriginalPointSize; 0345 } 0346 #endif 0347 } 0348 return output; 0349 } 0350 0351 SKGTabPage* SKGTabPage::parentTabPage(QWidget* iWidget) 0352 { 0353 auto* output = qobject_cast< SKGTabPage* >(iWidget); 0354 if ((output == nullptr) && (iWidget != nullptr)) { 0355 QWidget* iParent = iWidget->parentWidget(); 0356 if (iParent != nullptr) { 0357 output = SKGTabPage::parentTabPage(iParent); 0358 } 0359 } 0360 return output; 0361 } 0362 0363 bool SKGTabPage::isPin() const 0364 { 0365 return m_pin; 0366 } 0367 0368 void SKGTabPage::setPin(bool iPin) 0369 { 0370 m_pin = iPin; 0371 } 0372 0373