-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
136 lines (113 loc) · 3.78 KB
/
mainwindow.cpp
File metadata and controls
136 lines (113 loc) · 3.78 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <iostream>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Action "Undo"
QString qsUndo = "Undo";
QString qsUndoMsg = "Undo; Ctrl+Z";
m_pqaUndo = 0;
m_pqaUndo = new QAction( qsUndo, 0 );
if( m_pqaUndo )
{
m_pqaUndo->setText( qsUndo );
m_pqaUndo->setShortcut( QKeySequence("Ctrl+U"));
m_pqaUndo->setToolTip( qsUndo );
m_pqaUndo->setStatusTip( qsUndoMsg );
m_pqaUndo->setWhatsThis( qsUndoMsg );
m_pqaUndo->setIcon( QIcon("://images/undo.png") );
m_pqaUndo->setEnabled( true );
connect( m_pqaUndo, SIGNAL(triggered()), this, SLOT( onUndo() ) );
ui->toolBar->addAction( m_pqaUndo );
}
m_pqtbUndo = 0;
m_pqtbUndo = new QToolButton( this );
if( m_pqtbUndo )
{
m_pqtbUndo->setArrowType( Qt::DownArrow );
m_pqtbUndo->setMaximumWidth( 16 );
ui->toolBar->addWidget( m_pqtbUndo );
connect( m_pqtbUndo, SIGNAL( pressed() ), this, SLOT( onUndoMenu() ) );
}
m_pWgtUndoList = 0;
m_pFixedAdvert = 0;
m_pFixedAdvert = new CFixedAdvert();
if( m_pFixedAdvert )
{
m_pFixedAdvert->setWindowFlags( Qt::Drawer | Qt::Popup );
connect( m_pFixedAdvert, SIGNAL( sigOpCancel(int) ), this, SLOT( onOpCancel(int) ) );
}
}
MainWindow::~MainWindow()
{
if( m_pFixedAdvert ) delete m_pFixedAdvert;
if( m_pqaUndo ) delete m_pqaUndo;
if( m_pWgtUndoList ) delete m_pWgtUndoList;
delete ui;
}
void MainWindow::onOpCancel( int nOpCode )
{
qDebug() << "MainWindow::onOpCancel code:" << nOpCode;
}
void MainWindow::onUndo()
{
std::cout << "MainWindow::onUndo()" << std::endl;
if( m_pFixedAdvert )
{
if( m_pFixedAdvert->isVisible() )
m_pFixedAdvert->hide();
else
{
QString qsTemp;
qsTemp = QString::asprintf("Operation in progress: %d", m_nOpCode);
m_nOpCode++;
m_pFixedAdvert->ShowAdvert( m_nOpCode, qsTemp );
}
}
}
void MainWindow::onUndoMenu()
{
if( !m_pqtbUndo ) return;
QRect tmpFrameRect = m_pqtbUndo->frameGeometry();
QPoint qpGlbTopLeft = mapToGlobal( tmpFrameRect.topLeft() );
QPoint qpGlbBotRight = mapToGlobal( tmpFrameRect.bottomRight() );
if( !m_pWgtUndoList )
{
m_pWgtUndoList = new QUndoList;
if( m_pWgtUndoList )
{
connect( m_pWgtUndoList, SIGNAL( sigFocusOut( int ) ), this, SLOT( onUndoWgtFocusOut( int ) ) );
m_pWgtUndoList->setWindowFlags( Qt::Window | Qt::FramelessWindowHint );
m_pWgtUndoList->move( qpGlbTopLeft.x(), qpGlbBotRight.y() );
m_pWgtUndoList->show();
m_pWgtUndoList->addItem("Central frequency: 1213214214");
m_pWgtUndoList->addItem("Filter: LowPass Intel");
m_pWgtUndoList->addItem("Demodulator: GFSK2");
m_pWgtUndoList->setSelectionMode( QAbstractItemView::ContiguousSelection );
m_pWgtUndoList->setFocus(Qt::ActiveWindowFocusReason);
}
}
}
void MainWindow::onUndoWgtFocusOut( int nCurRow )
{
if( !m_pWgtUndoList ) return;
disconnect( m_pWgtUndoList, SIGNAL( sigFocusOut() ), this, SLOT( onUndoWgtFocusOut() ) );
if( nCurRow != -1 && nCurRow >= 0 && nCurRow < m_pWgtUndoList->count() )
{ // Undo the selected actions
int nRow = 0;
for( nRow = 0; nRow <= nCurRow; nRow++ )
{
QListWidgetItem *pItem = m_pWgtUndoList->item( nRow );
if( pItem )
{
std::cout << "Undo: " << pItem->text().toStdString() << std::endl;
}
}
}
if( m_pWgtUndoList ) delete m_pWgtUndoList;
m_pWgtUndoList = 0;
}