1 /*************************************************************************** 2 rkxmlguipreviewarea - description 3 ------------------- 4 begin : Wed Feb 03 2016 5 copyright : (C) 2016-2018 by Thomas Friedrichsmeier 6 email : thomas.friedrichsmeier@kdemail.net 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef RKXMLGUIPREVIEWAREA_H 19 #define RKXMLGUIPREVIEWAREA_H 20 21 #include <kxmlguiwindow.h> 22 #include <kparts/part.h> 23 24 #include <QPointer> 25 26 class QMenu; 27 class QToolButton; 28 class QLabel; 29 30 class RKXMLGUIPreviewArea : public KXmlGuiWindow { 31 Q_OBJECT 32 public: 33 RKXMLGUIPreviewArea (const QString &label, QWidget* parent); 34 ~RKXMLGUIPreviewArea (); 35 /** Returns a wrapper widget (created on first call of this function) that contains this widget along with a caption (see setLabel()), menu button, and close button. */ 36 QWidget *wrapperWidget (); label()37 QString label () const { return _label; }; 38 void setLabel (const QString &label); 39 protected: 40 /** build / destroy menu, when child is added removed. Note that we are in the fortunate situation that RKMDIWindow-children only ever get to the 41 * preview area via reparenting, i.e. contrary to usual QEvent::ChildAdded semnatics, they are always fully constructed, when added. */ 42 void childEvent (QChildEvent *event) override; 43 protected slots: 44 void prepareMenu (); 45 signals: 46 void previewClosed (RKXMLGUIPreviewArea *preview); 47 private: 48 QWidget *wrapper_widget; 49 QString _label; 50 QLabel *lab; 51 QMenu *menu; 52 QPointer<KParts::Part> current; 53 }; 54 55 class RCommand; 56 /** Simple manager (state machine) for previews. Keeps track of whether a preview is currently updating / up-to-date, and provides 57 * status information to any preview window. */ 58 class RKPreviewManager : public QObject { 59 Q_OBJECT 60 public: 61 explicit RKPreviewManager (QObject *parent); 62 ~RKPreviewManager (); 63 64 void setUpdatePending (); 65 void setPreviewDisabled (); 66 void setNoPreviewAvailable (); 67 /** Start the next preview update, as given by command. You must call needsCommand() first, to check whether the next command is 68 * ready to go. */ 69 void setCommand (RCommand *command); needsCommand()70 bool needsCommand () const { return !updating && (update_pending == UpdatePending); }; previewId()71 QString previewId () const { return id; }; 72 QString shortStatusLabel () const; 73 signals: 74 void statusChanged (); 75 private slots: 76 void previewCommandDone (RCommand *command); 77 private: 78 void setStatusMessage (const QString &); 79 enum { 80 NoUpdatePending, 81 NoUpdatePossible, 82 PreviewDisabled, 83 UpdatePending 84 } update_pending; 85 bool updating; 86 QString id; 87 }; 88 89 #endif 90