Warning, file /office/skrooge/skgbasegui/skgwidget.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 "skgwidget.h"
0012 
0013 #include <qwidget.h>
0014 
0015 #include "skgtraces.h"
0016 #include "skgtreeview.h"
0017 
0018 SKGWidget::SKGWidget(QWidget* iParent, SKGDocument* iDocument)
0019     : QWidget(iParent), m_document(iDocument)
0020 {
0021     SKGTRACEINFUNC(5)
0022 }
0023 
0024 SKGWidget::~SKGWidget()
0025 {
0026     SKGTRACEINFUNC(5)
0027     m_document = nullptr;
0028 }
0029 
0030 SKGDocument* SKGWidget::getDocument() const
0031 {
0032     return m_document;
0033 }
0034 
0035 QString SKGWidget::getState()
0036 {
0037     return QLatin1String("");
0038 }
0039 
0040 QString SKGWidget::getDefaultStateAttribute()
0041 {
0042     return QLatin1String("");
0043 }
0044 
0045 void SKGWidget::setState(const QString& /*iState*/)
0046 {
0047 }
0048 
0049 SKGObjectBase::SKGListSKGObjectBase SKGWidget::getSelectedObjects()
0050 {
0051     SKGObjectBase::SKGListSKGObjectBase selection;
0052     auto* treeView = qobject_cast<SKGTreeView*>(mainWidget());
0053     if (treeView != nullptr) {
0054         selection = treeView->getSelectedObjects();
0055     }
0056 
0057     return selection;
0058 }
0059 
0060 SKGObjectBase SKGWidget::getFirstSelectedObject()
0061 {
0062     SKGObjectBase first;
0063     auto* treeView = qobject_cast<SKGTreeView*>(mainWidget());
0064     if (treeView != nullptr) {
0065         first = treeView->getFirstSelectedObject();
0066     }
0067 
0068     return first;
0069 }
0070 
0071 int SKGWidget::getNbSelectedObjects()
0072 {
0073     int output = 0;
0074     auto* treeView = qobject_cast<SKGTreeView*>(mainWidget());
0075     if (treeView != nullptr) {
0076         output = treeView->getNbSelectedObjects();
0077     } else {
0078         output = getSelectedObjects().count();
0079     }
0080 
0081     return output;
0082 }
0083 
0084 bool SKGWidget::hasSelectionWithFocus()
0085 {
0086     return (mainWidget()->hasFocus());
0087 }
0088 
0089 bool SKGWidget::eventFilter(QObject* iObject, QEvent* iEvent)
0090 {
0091     if (iObject == mainWidget() && (iEvent != nullptr) && (iEvent->type() == QEvent::FocusIn || iEvent->type() == QEvent::FocusOut)) {
0092         emit selectionFocusChanged();
0093     }
0094     return QObject::eventFilter(iObject, iEvent);
0095 }
0096 
0097 QWidget* SKGWidget::mainWidget()
0098 {
0099     return this;
0100 }
0101 
0102