forked from CSReviser/CaptureStream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messagewindow.cpp
137 lines (116 loc) · 3.51 KB
/
messagewindow.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
133
134
135
136
137
/*
Copyright (C) 2009-2013 jakago
This file is part of CaptureStream, the flv downloader for NHK radio
language courses.
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, see <http://www.gnu.org/licenses/>.
*/
#include "messagewindow.h"
#include "ui_messagewindow.h"
#include "mainwindow.h"
#include "utility.h"
#include "qt4qt5.h"
#include <QtGui>
#include <QTextCursor>
#include <QSettings>
#include <QVariant>
namespace {
const QString SETTING_GROUP( "MessageWindow" );
const QString SETTING_GEOMETRY( "geometry" );
const int DEFAULT_WIDTH = 540;
const int DEFAULT_HEIGHT = 300;
#ifdef QT4_QT5_WIN
const int FONT_SIZE = 13;
#else
#ifdef QT4_QT5_MAC
const int FONT_SIZE = 11;
#else
const int FONT_SIZE = 14;
#endif
#endif
}
MessageWindow::MessageWindow(QWidget *parent) :
QWidget(parent, Qt::CustomizeWindowHint|Qt::WindowTitleHint|Qt::WindowCloseButtonHint)/*, ui(new Ui::MessageWindow)*/ {
//ui->setupUi(this);
setupGui();
settings( false );
}
MessageWindow::~MessageWindow() {
settings( true );
//delete ui;
}
void MessageWindow::changeEvent( QEvent *e ) {
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
//ui->retranslateUi(this);
break;
default:
break;
}
}
void MessageWindow::setupGui() {
textEdit = new QPlainTextEdit;
textEdit->setReadOnly( true );
textEdit->setWordWrapMode( QTextOption::WrapAnywhere );
QFont* font = new QFont();
font->setPixelSize( FONT_SIZE );
textEdit->setFont( *font );
clearTextButton = new QPushButton( QString::fromUtf8( "クリア" ) );
connect( clearTextButton, SIGNAL(clicked()), this, SLOT(clearText()) );
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(textEdit);
mainLayout->addWidget(clearTextButton);
setLayout(mainLayout);
}
QString MessageWindow::text() {
return textEdit->toPlainText();
}
// 改行あり
void MessageWindow::appendParagraph( const QString& text ) {
if ( !Utility::nogui() ) {
show();
textEdit->appendPlainText( text );
}
}
// 改行なし
void MessageWindow::append( const QString& text ) {
if ( !Utility::nogui() ) {
show();
//textEdit->setPlainText( textEdit->toPlainText().append( text ) ); // これはとても遅い
QTextCursor cursor = textEdit->textCursor();
cursor.movePosition( QTextCursor::End );
textEdit->setTextCursor( cursor );
textEdit->insertPlainText( text );
}
}
void MessageWindow::clearText() {
textEdit->clear();
}
void MessageWindow::settings( bool write ) {
#if defined( QT4_QT5_MAC ) || defined( QT4_QT5_WIN )
QSettings settings( Utility::applicationBundlePath() + INI_FILE, QSettings::IniFormat );
settings.beginGroup( SETTING_GROUP );
if ( !write ) {
QVariant saved = settings.value( SETTING_GEOMETRY );
if ( saved.type() != QVariant::Invalid )
restoreGeometry( saved.toByteArray() );
else
resize( DEFAULT_WIDTH, DEFAULT_HEIGHT );
} else {
settings.setValue( SETTING_GEOMETRY, saveGeometry() );
}
settings.endGroup();
#else
Q_UNUSED( write )
resize( DEFAULT_WIDTH, DEFAULT_HEIGHT );
#endif
}