File indexing completed on 2024-05-12 16:39:55
0001 /* This file is part of the KDE project 0002 Copyright (C) 2011-2012 Jarosław Staniek <staniek@kde.org> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this program; see the file COPYING. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KEXICONTEXTMESSAGE_H 0021 #define KEXICONTEXTMESSAGE_H 0022 0023 #include "kmessagewidget.h" 0024 0025 //! Information about context message. 0026 class KEXIUTILS_EXPORT KexiContextMessage 0027 { 0028 public: 0029 explicit KexiContextMessage(const QString& text = QString()); 0030 0031 explicit KexiContextMessage(QWidget *contentsWidget); 0032 0033 explicit KexiContextMessage(const KexiContextMessage& other); 0034 0035 ~KexiContextMessage(); 0036 0037 QString text() const; 0038 0039 void setText(const QString text); 0040 0041 //! Alignment of button corresponding to action added in addAction() 0042 enum ButtonAlignment { 0043 AlignLeft, 0044 AlignRight 0045 }; 0046 0047 //! Adds action. Does not take ownership. 0048 void addAction(QAction* action, ButtonAlignment alignment = AlignRight); 0049 0050 QList<QAction*> actions() const; 0051 0052 //! @return alignment of button for action @a action. 0053 ButtonAlignment buttonAlignment(QAction* action) const; 0054 0055 //! Sets default action, i.e. button created with this action 0056 //! will be the default button of the message. 0057 //! Does not take ownership. 0058 void setDefaultAction(QAction* action); 0059 0060 QAction* defaultAction() const; 0061 0062 QWidget* contentsWidget() const; 0063 0064 private: 0065 class Private; 0066 Private * const d; 0067 }; 0068 0069 class QFormLayout; 0070 0071 //! Context message widget constructed out of context message argument. 0072 class KEXIUTILS_EXPORT KexiContextMessageWidget : public KMessageWidget 0073 { 0074 Q_OBJECT 0075 public: 0076 //! Creates message widget constructed out of context message @a message. 0077 /*! Inserts itself into layout @a layout on top of the widget @a context. 0078 If @page is not 0 and @a message has any actions added, 0079 all children of @a page widget will be visually disabled to indicate 0080 modality of the message. 0081 The message widget will be automatically destroyed after triggering 0082 of any associated action. 0083 If @a layout is provided, direction of callout pointer is set by default 0084 to KMessageWidget::Down. This can be changed using setCalloutPointerDirection(). */ 0085 KexiContextMessageWidget(QWidget *page, 0086 QFormLayout* layout, QWidget *context, 0087 const KexiContextMessage& message); 0088 0089 //! @overload KexiContextMessageWidget(QWidget*, QFormLayout*, QWidget*, const KexiContextMessage&); 0090 //! Does not enter into modal state and does not accept actions. 0091 KexiContextMessageWidget(QFormLayout* layout, QWidget *context, 0092 const KexiContextMessage& message); 0093 0094 //! @overload KexiContextMessageWidget(QFormLayout*, QWidget*, const KexiContextMessage&); 0095 //! Does not enter into modal state and does not accept actions. 0096 KexiContextMessageWidget(QFormLayout* layout, QWidget *context, 0097 const QString& message); 0098 0099 virtual ~KexiContextMessageWidget(); 0100 0101 //! Sets widget @a widget to be foused after this message closes. 0102 //! By default context widget passed to constructor will be focused. 0103 //! Useful in modal mode. 0104 void setNextFocusWidget(QWidget *widget); 0105 0106 //! Sets global position for callout pointer 0107 //! @overload KMessageWidget::setCalloutPointerPosition(const QPoint&) 0108 //! Also sets tracked widget @a trackedWidget. 0109 //! If the widget changes its local position, the pointer position 0110 //! is moved by the same delta. 0111 void setCalloutPointerPosition(const QPoint& globalPos, 0112 QWidget *trackedWidget = 0); 0113 0114 //! Sets tracking policy for resize of the parent widget. 0115 //! When parent is resized in any way, size of the message box 0116 //! can be changed in one or two orientations. It is disabled by default 0117 //! and does not affect position of the callout pointer. 0118 //! Works only when tracked widget is set in setCalloutPointerPosition(). 0119 void setResizeTrackingPolicy(Qt::Orientations orientations); 0120 0121 //! @return tracking policy for resize of the parent widget. 0122 Qt::Orientations resizeTrackingPolicy() const; 0123 0124 //! Sets palette of the contents widget inheriting the message palette (background). 0125 //! Calling it is needed after delayed insering of the child contents widgets. 0126 void setPaletteInherited(); 0127 0128 protected: 0129 virtual bool eventFilter(QObject* watched, QEvent* event) override; 0130 0131 private Q_SLOTS: 0132 void actionTriggered(); 0133 void slotAnimatedShowFinished(); 0134 void slotAnimatedHideFinished(); 0135 0136 private: 0137 void init(QWidget *page, QFormLayout* layout, 0138 QWidget *context, const KexiContextMessage& message); 0139 0140 //! Made private to disable addAction(). 0141 void addAction(QAction* action) { Q_UNUSED(action); } 0142 0143 class Private; 0144 Private * const d; 0145 }; 0146 0147 #endif