1 /*
2 **********************************************************************************
3 **
4 ** This file is part of the LibreCAD project (librecad.org), a 2D CAD program.
5 **
6 ** Copyright (C) 2015 ravas (github.com/r-a-v-a-s)
7 **
8 ** This program is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License
10 ** as published by the Free Software Foundation; either version 2
11 ** of the License, or (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program; if not, write to the Free Software
20 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 **
22 **********************************************************************************
23 */
24
25 // -- https://github.com/LibreCAD/LibreCAD --
26
27 #include "qg_commandhistory.h"
28 #include <QAction>
29 #include <QMouseEvent>
30
31 // -- commandline history (output) widget --
32
QG_CommandHistory(QWidget * parent)33 QG_CommandHistory::QG_CommandHistory(QWidget* parent) :
34 QTextEdit(parent)
35 {
36 setContextMenuPolicy(Qt::ActionsContextMenu);
37
38 m_pCopy = new QAction(tr("&Copy"), this);
39 connect(m_pCopy, SIGNAL(triggered()), this, SLOT(copy()));
40 addAction(m_pCopy);
41 m_pCopy->setVisible(false);
42 //only show "copy" menu item when there's available selection to copy
43 connect(this, SIGNAL(copyAvailable(bool)), m_pCopy, SLOT(setVisible(bool)));
44
45 m_pSelectAll = new QAction(tr("Select &All"), this);
46 connect(m_pSelectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
47 addAction(m_pSelectAll);
48 connect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
49
50 QAction* clear = new QAction(tr("Clear"), this);
51 connect(clear, SIGNAL(triggered(bool)), this, SLOT(clear()));
52 addAction(clear);
53
54 setStyleSheet("selection-color: white; selection-background-color: green;");
55 }
56
mouseReleaseEvent(QMouseEvent * event)57 void QG_CommandHistory::mouseReleaseEvent(QMouseEvent* event)
58 {
59 QTextEdit::mouseReleaseEvent(event);
60 if (event->button() == Qt::LeftButton && m_pCopy->isVisible())
61 {
62 copy();
63 }
64 }
65
slotTextChanged()66 void QG_CommandHistory::slotTextChanged()
67 {
68 //only show the selectAll item when there is text
69 m_pSelectAll->setVisible(! toPlainText().isEmpty());
70 }
71
72