Debian Codegraph @

ruqtextedit.cpp

raw symbols SCIP
1 /****************************************************************************
2 ** SASM - simple IDE for assembler development
3 ** Copyright (C) 2013 Dmitriy Manushin
4 ** Contact: site: http://dman95.github.io/SASM/
5 ** e-mail: [email protected]
6 **
7 ** This file is part of SASM.
8 **
9 ** SASM is free software: you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation, either version 3 of the License, or
12 ** (at your option) any later version.
13 **
14 ** SASM is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with SASM. If not, see <http://www.gnu.org/licenses/>.
21 **
22 ** Этот файл — часть SASM.
23 **
24 ** SASM - свободная программа: вы можете перераспространять ее и/или
25 ** изменять ее на условиях Стандартной общественной лицензии GNU в том виде,
26 ** в каком она была опубликована Фондом свободного программного обеспечения;
27 ** либо версии 3 лицензии, либо (по вашему выбору) любой более поздней
28 ** версии.
29 **
30 ** SASM распространяется в надежде, что она будет полезной,
31 ** но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
32 ** или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной
33 ** общественной лицензии GNU.
34 **
35 ** Вы должны были получить копию Стандартной общественной лицензии GNU
36 ** вместе с этой программой. Если это не так, см.
37 ** <http://www.gnu.org/licenses/>.)
38 **
39 ****************************************************************************/
40
41 #include "ruqtextedit.h"
42
43 /**
44 * @file ruqtextedit.cpp
45 * Implemets text editor
46 */
47
48 RuQTextEdit::RuQTextEdit(QWidget *parent) :
49 QTextEdit(parent)
50 {
51 setAcceptRichText(false);
52 QSettings settings("SASM Project", "SASM");
53 QPalette palette = this->palette();
54 palette.setColor(QPalette::Base, settings.value("backgroundcolor", QColor(255, 255, 255)).value<QColor>());
55 palette.setColor(QPalette::Text, settings.value("fontcolor", QColor(30, 30, 30)).value<QColor>());
56 setPalette(palette);
57
58 undoAction = new QAction(tr("Undo"), this);
59 undoAction->setShortcut(QKeySequence::Undo);
60 connect(undoAction, SIGNAL(triggered()), this, SLOT(undo()));
61
62 redoAction = new QAction(tr("Redo"), this);
63 redoAction->setShortcut(QKeySequence::Redo);
64 connect(redoAction, SIGNAL(triggered()), this, SLOT(redo()));
65
66 cutAction = new QAction(tr("Cut"), this);
67 cutAction->setShortcut(QKeySequence::Cut);
68 connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
69
70 copyAction = new QAction(tr("Copy"), this);
71 copyAction->setShortcut(QKeySequence::Copy);
72 connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
73
74 pasteAction = new QAction(tr("Paste"), this);
75 pasteAction->setShortcut(QKeySequence::Paste);
76 connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
77
78 deleteAction = new QAction(tr("Delete"), this);
79 deleteAction->setShortcut(QKeySequence::Delete);
80 connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteSelected()));
81
82 selectAllAction = new QAction(tr("Select all"), this);
83 selectAllAction->setShortcut(QKeySequence::SelectAll);
84 connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));
85
86 clearAction = new QAction(tr("Clear"), this);
87 connect(clearAction, SIGNAL(triggered()), this, SLOT(clear()));
88
89 undoAction->setEnabled(false);
90 redoAction->setEnabled(false);
91 connect(this, SIGNAL(undoAvailable(bool)), undoAction, SLOT(setEnabled(bool)));
92 connect(this, SIGNAL(redoAvailable(bool)), redoAction, SLOT(setEnabled(bool)));
93 }
94
95 void RuQTextEdit::contextMenuEvent(QContextMenuEvent *e)
96 {
97 contextMenu = new QMenu;
98 QTextCursor textCursor = this->textCursor();
99
100 //!if nothing selected
101 if (textCursor.selectionEnd() - textCursor.selectionStart() <= 0) {
102 cutAction->setEnabled(false);
103 copyAction->setEnabled(false);
104 deleteAction->setEnabled(false);
105 } else {
106 cutAction->setEnabled(true);
107 copyAction->setEnabled(true);
108 deleteAction->setEnabled(true);
109 }
110
111 if (isReadOnly()) {
112 undoAction->setVisible(false);
113 redoAction->setVisible(false);
114 cutAction->setVisible(false);
115 pasteAction->setVisible(false);
116 deleteAction->setVisible(false);
117 clearAction->setVisible(true);
118 } else {
119 undoAction->setVisible(true);
120 redoAction->setVisible(true);
121 cutAction->setVisible(true);
122 pasteAction->setVisible(true);
123 deleteAction->setVisible(true);
124 clearAction->setVisible(false);
125 }
126
127 contextMenu->addAction(undoAction);
128 contextMenu->addAction(redoAction);
129 contextMenu->addSeparator();
130 contextMenu->addAction(cutAction);
131 contextMenu->addAction(copyAction);
132 contextMenu->addAction(pasteAction);
133 contextMenu->addAction(deleteAction);
134 contextMenu->addSeparator();
135 contextMenu->addAction(selectAllAction);
136 contextMenu->addAction(clearAction);
137
138 contextMenu->exec(e->globalPos());
139 if (!contextMenu.isNull())
140 delete contextMenu;
141 }
142
143 void RuQTextEdit::deleteSelected()
144 {
145 QTextCursor textCursor = this->textCursor();
146 textCursor.removeSelectedText();
147 }
148
149 RuQTextEdit::~RuQTextEdit()
150 {
151 delete undoAction;
152 delete redoAction;
153 delete cutAction;
154 delete copyAction;
155 delete pasteAction;
156 delete deleteAction;
157 delete selectAllAction;
158 delete clearAction;
159 }