File indexing completed on 2024-12-08 08:10:48
0001 /*************************************************************************** 0002 * Copyright (C) 2005 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #ifndef VIEW_H 0012 #define VIEW_H 0013 0014 #include "viewcontainer.h" 0015 0016 #include <KXMLGUIClient> 0017 0018 #include <QEvent> 0019 #include <QPainter> 0020 #include <QPixmap> 0021 #include <QPointer> 0022 #include <QStatusBar> 0023 #include <QUrl> 0024 0025 class DCOPObject; 0026 class Document; 0027 class KSqueezedTextLabel; 0028 class KTechlab; 0029 class View; 0030 class ViewContainer; 0031 class ViewIface; 0032 0033 class QVBoxLayout; 0034 class QLabel; 0035 0036 class ViewStatusBar : public QStatusBar 0037 { 0038 Q_OBJECT 0039 public: 0040 ViewStatusBar(View *view); 0041 0042 public: 0043 void setStatusText(const QString &statusText); 0044 0045 public slots: 0046 void slotModifiedStateChanged(); 0047 void slotFileNameChanged(const QUrl &url); 0048 void slotViewFocused(View *); 0049 void slotViewUnfocused(); 0050 0051 protected: 0052 View *p_view; 0053 QLabel *m_statusLabel; 0054 QLabel *m_modifiedLabel; 0055 KSqueezedTextLabel *m_fileNameLabel; 0056 QPixmap m_modifiedPixmap; 0057 QPixmap m_unmodifiedPixmap; 0058 }; 0059 0060 /** 0061 @author David Saxton 0062 */ 0063 class View : public QWidget, public KXMLGUIClient 0064 { 0065 Q_OBJECT 0066 public: 0067 View(Document *document, ViewContainer *viewContainer, uint viewAreaId); 0068 ~View() override; 0069 0070 QAction *actionByName(const QString &name) const; 0071 /** 0072 * Pointer to the parent document 0073 * Out of line to avoid needing to include document.h, leading to recursive includes. 0074 */ 0075 Document *document() const; 0076 /** 0077 * Returns the DCOP object from this view 0078 */ 0079 DCOPObject *dcopObject() const; 0080 /** 0081 * Returns the dcop suffix for this view - a unique ID for the current the 0082 * view within all views associated with the parent document. DCOP name 0083 * will become "View#docID#viewID". 0084 */ 0085 unsigned dcopID() const 0086 { 0087 return m_dcopID; 0088 } 0089 /** 0090 * Sets the dcop suffix. The DCOP object for this view will be renamed. 0091 * @see dcopID 0092 */ 0093 void setDCOPID(unsigned id); 0094 /** 0095 * Pointer to the ViewContainer that we're in 0096 */ 0097 ViewContainer *viewContainer() const 0098 { 0099 return p_viewContainer; 0100 } 0101 /** 0102 * Tells the view container which contains this view to close this view, 0103 * returning true if successful (i.e. not both last view and unsaved, etc) 0104 */ 0105 virtual bool closeView(); 0106 /** 0107 * Returns the unique (for the view container) view area id associated with this view 0108 */ 0109 uint viewAreaId() const 0110 { 0111 return m_viewAreaId; 0112 } 0113 /** 0114 * Zoom in 0115 */ 0116 virtual void viewZoomIn() {}; 0117 /** 0118 * Zoom out 0119 */ 0120 virtual void viewZoomOut() {}; 0121 virtual bool canZoomIn() const 0122 { 0123 return true; 0124 } 0125 virtual bool canZoomOut() const 0126 { 0127 return true; 0128 } 0129 /** 0130 * Restore view to actual size 0131 */ 0132 virtual void actualSize() {}; 0133 0134 virtual void toggleBreakpoint() {}; 0135 bool eventFilter(QObject *watched, QEvent *e) override; 0136 0137 protected slots: 0138 /** 0139 * Called when the user changes the configuration. 0140 */ 0141 virtual void slotUpdateConfiguration() {}; 0142 0143 signals: 0144 /** 0145 * Emitted when the view receives focus. @p view is a pointer to this class. 0146 */ 0147 void focused(View *view); 0148 /** 0149 * Emitted when the view looses focus. 0150 */ 0151 void unfocused(); 0152 0153 protected: 0154 /** 0155 * This function should be called in the constructor of the child class 0156 * (e.g. in ItemView or TextView) to set the widget which receives focus 0157 * events. 0158 */ 0159 void setFocusWidget(QWidget *focusWidget); 0160 0161 QPointer<Document> m_pDocument; 0162 QPointer<ViewContainer> p_viewContainer; 0163 uint m_viewAreaId; 0164 ViewStatusBar *m_statusBar; 0165 QVBoxLayout *m_layout; 0166 ViewIface *m_pViewIface; 0167 unsigned m_dcopID; 0168 QWidget *m_pFocusWidget; 0169 }; 0170 0171 /* 0172 "KateViewSpaceStatusBarSeparator" 0173 A 2 px line to separate the statusbar from the view. 0174 It is here to compensate for the lack of a frame in the view, 0175 I think Kate looks very nice this way, as QScrollView with frame 0176 looks slightly clumsy... 0177 Slight 3D effect. I looked for suitable QStyle props or methods, 0178 but found none, though maybe it should use QStyle::PM_DefaultFrameWidth 0179 for height (TRY!). 0180 It does look a bit funny with flat styles (Light, .Net) as is, 0181 but there are on methods to paint panel lines separately. And, 0182 those styles tends to look funny on their own, as a light line 0183 in a 3D frame next to a light contents widget is not functional. 0184 Also, QStatusBar is up to now completely ignorant to style. 0185 -anders 0186 */ 0187 class KVSSBSep : public QWidget 0188 { 0189 public: 0190 KVSSBSep(View *parent = nullptr) 0191 : QWidget(parent) 0192 { 0193 setFixedHeight(2); 0194 } 0195 0196 protected: 0197 void paintEvent(QPaintEvent *e) override; 0198 // { 0199 // QPainter p( this ); 0200 // //p.setPen( colorGroup().shadow() ); 0201 // QColorGroup colorGroup(palette()); 0202 // p.setPen( colorGroup.shadow() ); 0203 // p.drawLine( e->rect().left(), 0, e->rect().right(), 0 ); 0204 // p.setPen( ((View*)parentWidget())->hasFocus() ? colorGroup.light() : colorGroup.midlight() ); 0205 // p.drawLine( e->rect().left(), 1, e->rect().right(), 1 ); 0206 // } 0207 }; 0208 0209 #endif