File size: 2,492 Bytes
a5ffdcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
**********************************************************************************
**
** This file is part of the LibreCAD project (librecad.org), a 2D CAD program.
**
** Copyright (C) 2015 ravas (github.com/r-a-v-a-s)
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**
**********************************************************************************
*/
#include "qg_commandhistory.h"

#include <QMouseEvent>
// -- commandline history (output) widget --
QG_CommandHistory::QG_CommandHistory(QWidget* parent) :
    QTextEdit(parent){
    setContextMenuPolicy(Qt::ActionsContextMenu);

    m_pCopy = new QAction(tr("&Copy"), this);
    connect(m_pCopy, &QAction::triggered, this, &QG_CommandHistory::copy);
    addAction(m_pCopy);
    m_pCopy->setVisible(false);
    //only show "copy" menu item when there's available selection to copy
    connect(this, &QG_CommandHistory::copyAvailable, m_pCopy, &QAction::setVisible);

    m_pSelectAll = new QAction(tr("Select &All"), this);
    connect(m_pSelectAll, &QAction::triggered, this, &QG_CommandHistory::selectAll);
    addAction(m_pSelectAll);
    connect(this, &QG_CommandHistory::textChanged, this, &QG_CommandHistory::slotTextChanged);

    QAction* clear = new QAction(tr("Clear"), this);
    connect(clear, &QAction::triggered, this, &QG_CommandHistory::clear);
    addAction(clear);

#ifndef DONT_FORCE_WIDGETS_CSS
    setStyleSheet("selection-color: white; selection-background-color: green;");
#endif
}

void QG_CommandHistory::mouseReleaseEvent(QMouseEvent* event){
    QTextEdit::mouseReleaseEvent(event);
    if (event->button() == Qt::LeftButton && m_pCopy->isVisible())    {
        copy();
    }
}

void QG_CommandHistory::slotTextChanged(){
//only show the selectAll item when there is text
    m_pSelectAll->setVisible(! toPlainText().isEmpty());
}