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 storyeditor.h - description 9 ------------------- 10 begin : Tue Nov 11 2003 11 copyright : (C) 2003 by Franz Schmid 12 email : Franz.Schmid@altmuehlnet.de 13 ***************************************************************************/ 14 15 /*************************************************************************** 16 * * 17 * This program is free software; you can redistribute it and/or modify * 18 * it under the terms of the GNU General Public License as published by * 19 * the Free Software Foundation; either version 2 of the License, or * 20 * (at your option) any later version. * 21 * * 22 ***************************************************************************/ 23 24 #ifndef STORYEDITOR_H 25 #define STORYEDITOR_H 26 27 #include <tuple> 28 29 #include <QTextEdit> 30 #include <QAction> 31 #include <QCheckBox> 32 #include <QCloseEvent> 33 #include <QDialog> 34 #include <QEvent> 35 #include <QFocusEvent> 36 #include <QHideEvent> 37 #include <QKeyEvent> 38 #include <QLabel> 39 #include <QLayout> 40 #include <QList> 41 #include <QMainWindow> 42 #include <QMap> 43 #include <QMenu> 44 #include <QMenuBar> 45 #include <QMouseEvent> 46 #include <QPaintEvent> 47 #include <QPair> 48 #include <QPixmap> 49 #include <QPointer> 50 #include <QShowEvent> 51 #include <QSpinBox> 52 #include <QSplitter> 53 #include <QStack> 54 #include <QStatusBar> 55 #include <QStringList> 56 #include <QToolBar> 57 #include <QToolButton> 58 #include <QVariant> 59 #include <QWidgetAction> 60 61 class QEvent; 62 class QGridLayout; 63 class QHBoxLayout; 64 class QFrame; 65 66 #include "scribusapi.h" 67 #include "text/storytext.h" 68 69 class PageItem; 70 class MenuManager; 71 class ScrSpinBox; 72 class ParaStyleComboBox; 73 class StyleSelect; 74 class AlignSelect; 75 class DirectionSelect; 76 class FontCombo; 77 class ScrAction; 78 class ShadeButton; 79 class PrefsManager; 80 class PrefsContext; 81 class StoryEditor; 82 class ColorCombo; 83 class CharSelect; 84 85 class SCRIBUS_API SEditor : public QTextEdit 86 { 87 Q_OBJECT 88 89 friend class StoryEditor; 90 friend class SideBar; 91 92 public: 93 SEditor (QWidget* parent, ScribusDoc *docc, StoryEditor* parentSE); ~SEditor()94 ~SEditor() {} 95 96 void setCurrentDocument(ScribusDoc *docc); 97 void setAlign(int align); 98 void setDirection(int align); 99 void saveItemText(PageItem *currItem); 100 void loadItemText(PageItem *currItem); 101 void loadText(const QString& tx, PageItem *currItem); 102 void updateAll(); 103 void updateFromChars(int p); 104 void updateSel(const CharStyle& style); 105 void updateSel(const ParagraphStyle& style); 106 void deleteSel(); 107 void setEffects(int effects); 108 void setColor(bool marker); 109 110 void insertChars(const QString& text); 111 void insertChars(const QString& styledText, const QString& editText); 112 113 StoryText StyledText; 114 115 protected: 116 117 void insertCharsInternal(const QString& t); 118 void insertCharsInternal(const QString& t, int position); 119 120 void insertStyledText(const StoryText& styledText); 121 void insertStyledText(const StoryText& styledText, int position); 122 123 void insertUpdate(int position, int len); 124 125 void setAlign(QTextCursor& tCursor, int style); 126 void setDirection(QTextCursor& tCursor, int style); 127 void setEffects(QTextCursor& tCursor, int effects); 128 129 void keyPressEvent(QKeyEvent *k); 130 void inputMethodEvent(QInputMethodEvent *event); 131 void focusOutEvent(QFocusEvent *e); 132 void focusInEvent(QFocusEvent *e); 133 void scrollContentsBy(int dx, int dy); 134 virtual bool canInsertFromMimeData( const QMimeData * source ) const; 135 virtual QMimeData * createMimeDataFromSelection () const; 136 virtual void insertFromMimeData ( const QMimeData * source ); 137 138 QList<PageItem*> FrameItems; 139 ScribusDoc* doc { nullptr }; 140 StoryEditor* parentStoryEditor { nullptr }; 141 int blockContentsChangeHook { 0 }; 142 bool unicodeTextEditMode { false }; 143 bool wasMod { false }; 144 bool ready { false }; 145 int unicodeInputCount { 0 }; 146 StyleFlag CurrentEffects; 147 QString currentParaStyle; 148 int CurrAlign { 0 }; 149 int CurrDirection { 0 }; 150 double CurrFontSize { 0.0 }; 151 double CurrTextFillSh { 0.0 }; 152 double CurrTextStrokeSh { 0.0 }; 153 double CurrTextScaleH { 0.0 }; 154 double CurrTextScaleV { 0.0 }; 155 double CurrTextBase { 0.0 }; 156 double CurrTextShadowX { 0.0 }; 157 double CurrTextShadowY { 0.0 }; 158 double CurrTextOutline { 0.0 }; 159 double CurrTextUnderPos { 0.0 }; 160 double CurrTextUnderWidth { 0.0 }; 161 double CurrTextStrikePos { 0.0 }; 162 double CurrTextStrikeWidth { 0.0 }; 163 double CurrTextKern { 0.0 }; 164 QString CurrTextStroke; 165 QString CurrTextFill; 166 QString prevFont; 167 QString CurrFont; 168 QString unicodeInputString; 169 170 QStack< std::tuple<int, int, int> > SelStack; 171 172 int SelCharStart { 0 }; 173 int SelCharEnd { 0 }; 174 int SuspendContentsChange { 0 }; // input method 175 176 protected slots: 177 void handleContentsChange(int position, int charsRemoved, int charsAdded); 178 179 public slots: 180 void cut(); 181 void copy(); 182 void paste(); 183 void ClipChange(); 184 void SelClipChange(); 185 186 signals: 187 void setProps(int, int); 188 void SideBarUp(bool); 189 void SideBarUpdate(); 190 void PasteAvail(); 191 void contentsMoving(int, int); 192 }; 193 194 class SCRIBUS_API SideBar : public QLabel 195 { 196 Q_OBJECT 197 198 public: 199 SideBar(QWidget *pa); ~SideBar()200 ~SideBar() {}; 201 202 void setEditor(SEditor* editor); 203 204 int offs { 0 }; 205 int currentPar { 0 }; 206 QMenu *pmen { nullptr }; 207 QWidgetAction* paraStyleAct { nullptr }; 208 bool noUpdt { true }; 209 bool inRep { false }; 210 211 protected: 212 void paintEvent(QPaintEvent *e); 213 void mouseReleaseEvent(QMouseEvent *m); 214 215 private: 216 SEditor *m_editor { nullptr }; 217 218 signals: 219 void ChangeStyle(int, const QString&); 220 //! signal raised when user ask for style manager 221 //void sigEditStyles(); 222 223 public slots: 224 void setPStyle(const QString&); 225 void doMove(int x, int y); 226 void doRepaint(); 227 void setRepaint(bool r); 228 //! slot raising style manager 229 //void editStyles(); 230 }; 231 232 class SCRIBUS_API SToolBColorF : public QToolBar 233 { 234 Q_OBJECT 235 236 public: 237 SToolBColorF(QMainWindow* parent, ScribusDoc *doc); ~SToolBColorF()238 ~SToolBColorF() {}; 239 240 void setCurrentDocument(ScribusDoc *doc); 241 242 QLabel* FillIcon { nullptr }; 243 ColorCombo* TxFill { nullptr }; 244 ShadeButton *PM2 { nullptr }; 245 QAction* pm2Action { nullptr }; 246 QAction* txFillAction { nullptr }; 247 QAction* fillIconAction { nullptr }; 248 249 protected: 250 void changeEvent(QEvent *e) override; 251 252 public slots: 253 void SetColor(int c); 254 void SetShade(double s); 255 void newShadeHandler(); 256 void iconSetChange(); 257 void languageChange(); 258 259 signals: 260 void NewColor(int, int); 261 }; 262 263 class SCRIBUS_API SToolBColorS : public QToolBar 264 { 265 Q_OBJECT 266 267 public: 268 SToolBColorS(QMainWindow* parent, ScribusDoc *doc); ~SToolBColorS()269 ~SToolBColorS() {}; 270 271 void setCurrentDocument(ScribusDoc *doc); 272 273 QLabel* StrokeIcon { nullptr }; 274 ColorCombo* TxStroke { nullptr }; 275 ShadeButton *PM1 { nullptr }; 276 QAction* strokeIconAction { nullptr }; 277 QAction* txStrokeAction { nullptr }; 278 QAction* pm1Action { nullptr }; 279 280 protected: 281 void changeEvent(QEvent *e) override; 282 283 public slots: 284 void SetColor(int c); 285 void SetShade(double s); 286 void newShadeHandler(); 287 void iconSetChange(); 288 void languageChange(); 289 290 signals: 291 void NewColor(int, int); 292 }; 293 294 class SCRIBUS_API SToolBStyle : public QToolBar 295 { 296 Q_OBJECT 297 298 public: 299 SToolBStyle(QMainWindow* parent); ~SToolBStyle()300 ~SToolBStyle() {}; 301 302 StyleSelect* SeStyle { nullptr }; 303 QLabel* trackingLabel { nullptr }; 304 ScrSpinBox* Extra { nullptr }; 305 QAction* seStyleAction { nullptr }; 306 QAction* trackingLabelAction { nullptr }; 307 QAction* extraAction { nullptr }; 308 309 protected: 310 void changeEvent(QEvent *e) override; 311 312 public slots: 313 void newStrikeHandler(); 314 void newUnderlineHandler(); 315 void newOutlineHandler(); 316 void newShadowHandler(); 317 void newKernHandler(); 318 void SetShadow(double x, double y); 319 void setStrike(double p, double w); 320 void setUnderline(double p, double w); 321 void setOutline(double o); 322 void SetStyle(int s); 323 void SetKern(double k); 324 void iconSetChange(); 325 void languageChange(); 326 327 signals: 328 void NewKern(double); 329 void NewShadow(double, double); 330 void newOutline(double); 331 void newStrike(double, double); 332 void newUnderline(double, double); 333 void newStyle(int); 334 }; 335 336 class SCRIBUS_API SToolBAlign : public QToolBar 337 { 338 Q_OBJECT 339 340 public: 341 SToolBAlign(QMainWindow* parent); ~SToolBAlign()342 ~SToolBAlign() {}; 343 344 AlignSelect* GroupAlign { nullptr }; 345 DirectionSelect* GroupDirection { nullptr }; 346 ParaStyleComboBox *paraStyleCombo { nullptr }; 347 QAction* groupAlignAction { nullptr }; 348 QAction* groupDirectionAction { nullptr }; 349 QAction* paraStyleComboAction { nullptr }; 350 351 protected: 352 void changeEvent(QEvent *e) override; 353 354 public slots: 355 void SetAlign(int s); 356 void SetDirection(int s); 357 void SetParaStyle(const QString& s); 358 void languageChange(); 359 360 signals: 361 void newAlign(int); 362 void newDirection(int); 363 void newParaStyle(const QString&); 364 }; 365 366 class SCRIBUS_API SToolBFont : public QToolBar 367 { 368 Q_OBJECT 369 370 public: 371 SToolBFont(QMainWindow* parent); ~SToolBFont()372 ~SToolBFont() {}; 373 374 FontCombo* Fonts { nullptr }; 375 ScrSpinBox* charScaleH { nullptr }; 376 ScrSpinBox* charScaleV { nullptr }; 377 QAction* fontsAction { nullptr }; 378 QAction* chScaleHAction { nullptr }; 379 QAction* chScaleVAction { nullptr }; 380 381 protected: 382 void changeEvent(QEvent *e) override; 383 384 public slots: 385 void SetFont(const QString& f); 386 void SetSize(double s); 387 void SetScaleH(double s); 388 void SetScaleV(double s); 389 390 signals: 391 void newFont(const QString &); 392 void newSize(double); 393 void newScaleH(double); 394 void newScaleV(double); 395 396 private: 397 ScrSpinBox* Size { nullptr }; 398 QLabel* lblScaleTxtH { nullptr }; 399 QLabel* lblScaleTxtV { nullptr }; 400 QAction* sizeAction { nullptr }; 401 QAction* scaleTxtHAction { nullptr }; 402 QAction* scaleTxtVAction { nullptr }; 403 404 private slots: 405 void iconSetChange(); 406 void languageChange(); 407 }; 408 409 class SCRIBUS_API StoryEditor : public QMainWindow 410 { 411 Q_OBJECT 412 friend class SEditor; 413 414 public: 415 StoryEditor( QWidget* parent ); 416 // StoryEditor( QWidget* parent, ScribusDoc *docc, PageItem* ite ); 417 ~StoryEditor(); 418 419 void setCurrentDocumentAndItem(ScribusDoc *doc=nullptr, PageItem *item=nullptr); 420 void setSpellActive(bool ssa); 421 422 ScribusDoc* currentDocument() const; 423 PageItem* currentItem() const; 424 425 SEditor* Editor { nullptr }; 426 bool activFromApp { true }; 427 MenuManager* seMenuMgr { nullptr }; 428 QMap<QString, QPointer<ScrAction> > seActions; 429 430 public slots: 431 void newStyle(const QString&); 432 void newAlign(int st); 433 void newDirection(int dir); 434 void newTxFill(int c, int s); 435 void newTxStroke(int c, int s); 436 void newTxFont(const QString &f); 437 void newTxSize(double s); 438 void newTxStyle(int s); 439 440 signals: 441 void DocChanged(); 442 443 private: 444 //int exec(); 445 void changeAlign(int align); 446 void changeDirection(int align); 447 bool textDataChanged() const; 448 449 /*! \brief Enables/disables the "smart" selection (#1203) - 10/16/2004 pv */ 450 bool m_smartSelection { false }; 451 452 ScribusDoc* m_doc { nullptr }; 453 PageItem* m_item { nullptr }; 454 455 bool m_textChanged { false }; 456 bool m_firstSet { false }; 457 bool m_blockUpdate { false }; 458 459 int m_result { QDialog::Rejected }; 460 461 protected slots: 462 void setFontPref(); 463 void newTxScale(); 464 void newTxScaleV(); 465 void newTxKern(double s); 466 void newShadowOffs(double x, double y); 467 void newTxtOutline(double o); 468 void newTxtUnderline(double p, double w); 469 void newTxtStrike(double p, double w); 470 void updateProps(); 471 void updateProps(QTextCursor &cur); 472 void updateProps(int p, int ch); 473 474 void changeStyleSB(int pa, const QString&); 475 void changeStyle(); 476 void updateStatus(); 477 void Do_leave(); 478 void Do_leave2(); 479 //! \brief Saves the document with editation continued. Signal called from menu. 480 void Do_saveDocument(); 481 bool Do_new(); 482 void slotFileRevert(); 483 484 void Do_selectAll(); 485 void Do_copy(); 486 void Do_paste(); 487 void Do_cut(); 488 void Do_del(); 489 void Do_insSp(); 490 /*! \brief Insert a Lorem Ipsum (from dialog) into 491 current position inthe SE. 492 */ 493 void insertSampleText(); 494 void Do_fontPrev(); 495 void CopyAvail(bool u); 496 void PasteAvail(); 497 void updateTextFrame(); 498 void SearchText(); 499 //void slotEditStyles(); 500 void modifiedText(); 501 void LoadTextFile(); 502 void SaveTextFile(); 503 void setSmart(bool); 504 505 void iconSetChange(); 506 void languageChange(); 507 508 void specialActionKeyEvent(int unicodevalue); 509 /*! \brief Slot to insert special characters from charSelect widget. */ 510 void slot_insertSpecialChar(); 511 void slot_insertUserSpecialChar(QChar, const QString&); 512 // 10/12/2004 - pv - #1203: wrong selection on double click 513 void doubleClick(int para, int pos); 514 515 protected: 516 void initActions(); 517 void updateUnicodeActions(); 518 void buildMenus(); 519 void buildGUI(); 520 void setupEditorGUI(); 521 void connectSignals(); 522 void disconnectSignals(); 523 /*! \brief Loading the preferences (position). 524 It's in separate method due the 2 constructors. */ 525 void loadPrefs(); 526 /*! \brief Saving the preferences (position). */ 527 void savePrefs(); 528 529 /*! \brief Special Characters dialog. 530 It uses a little bit ugly method to operate with. 531 It's a duplication of the main window's charPalette due 532 the lack of setParent() in qt3 and a ugly behaviour of 533 the reparent(). 534 charSelect is created as a copy of the charPalette. 535 \author Petr Vanek <petr@scribus.info> 536 */ 537 CharSelect *charSelect { nullptr }; 538 //! True when there were some glyphs inserted via charSelect 539 bool charSelectUsed { false }; 540 541 void changeEvent(QEvent *e) override; 542 543 void showEvent(QShowEvent *) override; 544 void hideEvent(QHideEvent *) override; 545 546 void closeEvent(QCloseEvent *) override; 547 void keyPressEvent(QKeyEvent *e) override; 548 bool eventFilter(QObject *ob, QEvent* ev) override; 549 550 QHBoxLayout* StoryEd2Layout { nullptr }; 551 QGridLayout* ButtonGroup1Layout { nullptr }; 552 QGridLayout* ButtonGroup2Layout { nullptr }; 553 554 PrefsManager& prefsManager; 555 PrefsContext* prefs { nullptr }; 556 557 QStringList unicodeCharActionNames; 558 QPixmap noIcon; 559 560 QToolBar* FileTools { nullptr }; 561 SToolBFont* FontTools { nullptr }; 562 SToolBAlign* AlignTools { nullptr }; 563 SToolBColorF* FillTools { nullptr }; 564 SToolBColorS* StrokeTools { nullptr }; 565 SToolBStyle* StyleTools { nullptr }; 566 QSplitter* EdSplit { nullptr }; 567 SideBar* EditorBar { nullptr }; 568 QFrame* ButtonGroup1 { nullptr }; 569 QFrame* ButtonGroup2 { nullptr }; 570 QLabel* WordCT1 { nullptr }; 571 QLabel* WordCT3 { nullptr }; 572 QLabel* ParCT { nullptr }; 573 QLabel* ParC { nullptr }; 574 QLabel* WordCT { nullptr }; 575 QLabel* WordC { nullptr }; 576 QLabel* CharCT { nullptr }; 577 QLabel* CharC { nullptr }; 578 QLabel* WordCT2 { nullptr }; 579 QLabel* WordC2 { nullptr }; 580 QLabel* CharCT2 { nullptr }; 581 QLabel* CharC2 { nullptr }; 582 583 bool m_spellActive { false }; 584 }; 585 586 #endif 587 588 589