1 /* 2 For general Scribus (>=1.3.2) copyright and licensing information please refer 3 to the COPYING file provided with the program. Following this notice may exist 4 a copyright and/or license notice that predates the release of Scribus 1.3.2 5 for which a new license (GPL+exception) is in place. 6 */ 7 8 #ifndef GUIDEMANAGERCORE_H 9 #define GUIDEMANAGERCORE_H 10 11 #include <QPair> 12 13 #include "undoobject.h" 14 #include "scribusapi.h" 15 16 class QColor; 17 class ScPage; 18 class ScPainter; 19 class UndoManager; 20 class ScribusDoc; 21 typedef QList<double> Guides; 22 23 /*! \brief Core manipulation with the guides. 24 Basic idea: 25 - guides are handled "on the fly", no by modal dialog. 26 - 2 types of guides: Standard = created one by one. 27 Auto = created by automatic division algorithms. 28 Automatic guides are kept by 2 ways: 1st its parameters (m_horizontalAutoCount etc.) 29 to setup the GUI and compute guides itself. 2nd the horizontalAutoG etc. set 30 with precomputed values from GUI actions for drawing. 31 - user can move only Stnadard ones 32 - Auto guides can be deleted only in manipulation dialog 33 - Auto guides are painted in different color / (probably) with diff. line. 34 \author Petr vanek <petr@scribus.info> 35 */ 36 class SCRIBUS_API GuideManagerCore 37 { 38 public: 39 GuideManagerCore(); 40 GuideManagerCore(ScPage* parentPage); 41 ~GuideManagerCore() = default; 42 43 typedef enum {Standard, Auto} GuideType; 44 45 void addHorizontal(double value, GuideType type); 46 void addHorizontals(Guides values, GuideType type); 47 void addVertical(double value, GuideType type); 48 void addVerticals(Guides values, GuideType type); 49 void deleteHorizontal(double value, GuideType type); 50 void deleteVertical(double value, GuideType type); 51 void moveHorizontal(double from, double to, GuideType type); 52 void moveVertical(double from, double to, GuideType type); 53 54 Guides horizontals(GuideType type); 55 Guides verticals(GuideType type); 56 double horizontal(uint ix, GuideType type); 57 double vertical(uint ix, GuideType type); 58 59 Guides getAutoHorizontals(ScPage* page = nullptr); 60 Guides getAutoVerticals(ScPage* page = nullptr); 61 62 void clearHorizontals(GuideType type); 63 void clearVerticals(GuideType type); 64 65 void copy(GuideManagerCore *target); 66 void copy(GuideManagerCore *target, GuideType type); 67 68 void drawPage(ScPainter *p, ScribusDoc *doc, double lineWidth); 69 70 int isMouseOnHorizontal(double low, double high, GuideType type); 71 int isMouseOnVertical(double low, double high, GuideType type); 72 73 void setPage(ScPage *p); 74 75 QPair<double, double> topLeft(double x, double y);// const; 76 QPair<double, double> topRight(double x, double y);// const; 77 QPair<double, double> bottomLeft(double x, double y);// const; 78 QPair<double, double> bottomRight(double x, double y);// const; 79 80 //! \brief Properties for Auto guides remembrance. See GuideManager. horizontalAutoCount()81 int horizontalAutoCount() { return m_horizontalAutoCount; } 82 //! \brief Properties for Auto guides remembrance. See GuideManager. setHorizontalAutoCount(int val)83 void setHorizontalAutoCount(int val) { m_horizontalAutoCount = val; } 84 //! \brief Properties for Auto guides remembrance. See GuideManager. verticalAutoCount()85 int verticalAutoCount() { return m_verticalAutoCount; } 86 //! \brief Properties for Auto guides remembrance. See GuideManager. setVerticalAutoCount(int val)87 void setVerticalAutoCount(int val) { m_verticalAutoCount = val; } 88 //! \brief Properties for Auto guides remembrance. See GuideManager. horizontalAutoGap()89 double horizontalAutoGap(){ return m_horizontalAutoGap; } 90 //! \brief Properties for Auto guides remembrance. See GuideManager. verticalAutoGap()91 double verticalAutoGap(){return m_verticalAutoGap; } 92 //! \brief Properties for Auto guides remembrance. See GuideManager. setHorizontalAutoGap(double gap)93 void setHorizontalAutoGap(double gap){ m_horizontalAutoGap = gap; } 94 //! \brief Properties for Auto guides remembrance. See GuideManager. setVerticalAutoGap(double gap)95 void setVerticalAutoGap(double gap){ m_verticalAutoGap = gap; } 96 //! \brief Properties for Auto guides remembrance. See GuideManager. horizontalAutoRefer()97 int horizontalAutoRefer() { return m_horizontalAutoRefer; } 98 //! \brief Properties for Auto guides remembrance. See GuideManager. setHorizontalAutoRefer(int val)99 void setHorizontalAutoRefer(int val) { m_horizontalAutoRefer = val; } 100 //! \brief Properties for Auto guides remembrance. See GuideManager. verticalAutoRefer()101 int verticalAutoRefer() { return m_verticalAutoRefer; } 102 //! \brief Properties for Auto guides remembrance. See GuideManager. setVerticalAutoRefer(int val)103 void setVerticalAutoRefer(int val) { m_verticalAutoRefer = val; } 104 105 /*! \brief Selection/group coordinates 106 It's used to simulate the original selection "freezed in time" 107 for parent page */ 108 double gx {0.0}; 109 double gy {0.0}; 110 double gw {0.0}; 111 double gh {0.0}; 112 113 114 private: 115 UndoManager * const m_undoManager; 116 ScPage* m_page {nullptr}; 117 Guides m_horizontalStdG; 118 Guides m_verticalStdG; 119 Guides m_horizontalAutoG; 120 Guides m_verticalAutoG; 121 122 double m_horizontalAutoGap {0.0}; 123 double m_verticalAutoGap {0.0}; 124 int m_horizontalAutoCount {0}; 125 int m_verticalAutoCount {0}; 126 int m_horizontalAutoRefer {0}; 127 int m_verticalAutoRefer {0}; 128 129 double closestHorAbove(double y);// const; 130 double closestHorBelow(double y);// const; 131 double closestVertLeft(double x);// const; 132 double closestVertRight(double x);// const; 133 }; 134 135 136 /*! \brief A separate class for Guides IO operations in reading or closing 137 the documents. 138 \author Petr Vanek <petr@scribus.info> 139 */ 140 class SCRIBUS_API GuideManagerIO 141 { 142 public: 143 GuideManagerIO() = default; 144 ~GuideManagerIO() = default; 145 146 /*! \brief Read the guides from XML attribute (file opening). 147 It's statis method sou you can call it without instance initialized: 148 GuideManagerIO::readHorizontalGuides(foo blah); 149 \param guideString a string with all values separated by space (' '). E.g. "1.0 23.17 6" 150 \param page a reference to the Page object to append the separated guideString values 151 \param type Guide type to load 152 \param useOldGuides A little bit hacking here. The guides were stored in a little mess 153 in the ancient times. So when is the obsolete XML attribute found in reading document 154 the old reading method is used. All guides are saved in new format then. */ 155 static void readHorizontalGuides(const QString& guideString, 156 ScPage *page, 157 GuideManagerCore::GuideType type, 158 bool useOldGuides=false); 159 160 /*! \brief Read the guides from XML attribute (file opening). 161 It's statis method sou you can call it without instance initialized: 162 GuideManagerIO::readVerticalGuides(foo blah); 163 \param guideString a string with all values separated by space (' '). E.g. "1.0 23.17 6" 164 \param page a reference to the Page object to append the separated guideString values 165 \param type Guide type to load 166 \param useOldGuides A little bit hacking here. The guides were stored in a little mess 167 in the ancient times. So when is the obsolete XML attribute found in reading document 168 the old reading method is used. All guides are saved in new format then. */ 169 static void readVerticalGuides(const QString& guideString, 170 ScPage *page, 171 GuideManagerCore::GuideType type, 172 bool useOldGuides=false); 173 174 static QString writeHorizontalGuides(ScPage *page, GuideManagerCore::GuideType type); 175 static QString writeVerticalGuides(ScPage *page, GuideManagerCore::GuideType type); 176 177 static void readSelection(const QString& guideString, ScPage *page); 178 static QString writeSelection(ScPage *page); 179 }; 180 181 #endif 182