-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddmInfoWindowWidget.cpp
132 lines (106 loc) · 3.93 KB
/
ddmInfoWindowWidget.cpp
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
#include <QDir>
#include <QImageReader>
#include <QMenu>
#include <QTextDocumentFragment>
#include <QTime>
#include "ddmInfoWindowWidget.h"
#include "ui_ddminfowindowwidget.h"
ddmInfoWindowWidget::ddmInfoWindowWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ddmInfoWindowWidget)
{
ui->setupUi(this);
ui->m_ptInfoWindow->setReadOnly( true );
ui->m_ptInfoWindow->setFont ( QFont( "Time New Roman", 10 ) );
ui->m_ptInfoWindow->setContextMenuPolicy( Qt::CustomContextMenu );
connect( ui->m_ptInfoWindow , SIGNAL(customContextMenuRequested( const QPoint & )),
this, SLOT(ShowContextMenu( const QPoint &) ) );
}
ddmInfoWindowWidget::~ddmInfoWindowWidget()
{
delete ui;
}
void ddmInfoWindowWidget::writeDebug( const QString &text )
{
QString imageFilePath = QObject::tr( "%1/bug.png" ).arg( getCurrentPathToIcon() );
insertImage( imageFilePath );
QString time = getCurrentTime();
QString message;
if( text.endsWith( "\n" ) || text.endsWith( "\n\r" ) )
message = QObject::tr( "%1:%2" ).arg( time ).arg( text );
else
message = QObject::tr( "%1:%2\n" ).arg( time ).arg( text );
ui->m_ptInfoWindow->insertPlainText( message );
}
void ddmInfoWindowWidget::writeInfo( const QString &text )
{
QString imageFilePath = QObject::tr( "%1/info.png" ).arg( getCurrentPathToIcon() );
insertImage( imageFilePath );
QString time = getCurrentTime();
QString message;
if( text.endsWith( "\n" ) || text.endsWith( "\n\r" ) )
message = QObject::tr( "%1:%2" ).arg( time ).arg( text );
else
message = QObject::tr( "%1:%2\n" ).arg( time ).arg( text );
ui->m_ptInfoWindow->insertPlainText( message );
}
void ddmInfoWindowWidget::writeWarning( const QString &text )
{
QString imageFilePath = QObject::tr( "%1/warning.png" ).arg( getCurrentPathToIcon() );
insertImage( imageFilePath );
QString time = getCurrentTime();
QString message;
if( text.endsWith( "\n" ) || text.endsWith( "\n\r" ) )
message = QObject::tr( "%1:%2" ).arg( time ).arg( text );
else
message = QObject::tr( "%1:%2\n" ).arg( time ).arg( text );
ui->m_ptInfoWindow->insertPlainText( message );
}
void ddmInfoWindowWidget::writeError( const QString &text )
{
QString imageFilePath = QObject::tr( "%1/error.png" ).arg( getCurrentPathToIcon() );
insertImage( imageFilePath );
QString time = getCurrentTime();
QString message;
if( text.endsWith( "\n" ) || text.endsWith( "\n\r" ) )
message = QObject::tr( "%1:%2" ).arg( time ).arg( text );
else
message = QObject::tr( "%1:%2\n" ).arg( time ).arg( text );
ui->m_ptInfoWindow->insertPlainText( message );
}
void ddmInfoWindowWidget::slotClearText()
{
ui->m_ptInfoWindow->clear();
}
void ddmInfoWindowWidget::ShowContextMenu( const QPoint& point )
{
QMenu contextMenu(tr( "Context menu" ), this );
ui->m_clearTextAction->setParent( this );
connect( ui->m_clearTextAction, SIGNAL( triggered() ), this,
SLOT( slotClearText() ), Qt::UniqueConnection );
contextMenu.addAction( ui->m_clearTextAction );
contextMenu.exec( this->mapToGlobal( point ) );
}
QString ddmInfoWindowWidget::getCurrentTime()
{
QTime time = QTime::currentTime();
return time.toString();
}
QString ddmInfoWindowWidget::getCurrentPathToIcon()
{
QString appPath = QApplication::applicationDirPath();
QString iconDirPath = QObject::tr( "%1/icons" ).arg( appPath );
QDir iconDir( iconDirPath );
if( iconDir.exists() )
return iconDirPath;
iconDirPath = QObject::tr( "%1/../../icons" ).arg( appPath );
iconDir.setPath( appPath );
if( iconDir.exists() )
return iconDirPath;
return "";
}
void ddmInfoWindowWidget::insertImage( const QString& fullFileName )
{
QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml( QObject::tr( "<img src='%1'>" ).arg( fullFileName ) );
ui->m_ptInfoWindow->textCursor().insertFragment( fragment );
}