-
Notifications
You must be signed in to change notification settings - Fork 0
/
zhscmw.cpp
245 lines (185 loc) · 8.61 KB
/
zhscmw.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
ZHSC
zhscmw.cpp
v 0.0.1
2003/06/23
Copyright (C) 2003 Cavendish
cavendish@qiliang.net
http://www.qiliang.net/software/zhsc.html
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.
*/
#include <qapplication.h>
#include <qpopupmenu.h>
#include <qmenubar.h>
#include <qstatusbar.h>
#include <qtoolbar.h>
#include <qmessagebox.h>
#include <qpixmap.h>
#include <qiconset.h>
#include "zhscmw.h"
#include "codec.h"
ZhscMainWindow::ZhscMainWindow( QWidget* parent, const char* name )
: QMainWindow( parent, name )
{
pmBookmark = NULL;
setIcon( QPixmap( "img/poems.xpm" ) );
setCaption( Unicode( "中华诗词 Qt版" ) );
zw = new ZhscWidget( this, "Zhsc Widget" );
QToolBar *tb = new QToolBar( this, "Tool Bar" );
tb->setLabel( Unicode( "工具条" ) );
QPopupMenu *pmSystem = new QPopupMenu( this );
menuBar()->insertItem( Unicode( "系统(&S)" ), pmSystem );
actExport = new QAction( Unicode( "导出到文件" ), Unicode( "导出(&E)" ), 0, this, 0 );
connect( actExport, SIGNAL( activated() ), zw, SLOT( educe() ) );
actExport->addTo( pmSystem );
pmSystem->insertSeparator();
pmSystem->insertItem( Unicode( "退出(&Q)" ), qApp, SLOT( closeAllWindows() ), CTRL+Key_Q );
QPopupMenu *pmRecord = new QPopupMenu( this );
menuBar()->insertItem( Unicode( "记录(&R)" ), pmRecord );
actRecordFirst = new QAction( Unicode( "第一首记录" ), Unicode( "第一首(&F)" ), 0, this, 0 );
connect( actRecordFirst, SIGNAL( activated() ), zw, SLOT( recordFirst() ) );
connect( zw, SIGNAL( recordFirstEnabled( bool ) ), actRecordFirst, SLOT( setEnabled( bool ) ) );
actRecordFirst->setIconSet( QPixmap( "img/first.xpm") );
actRecordFirst->addTo( pmRecord );
actRecordFirst->addTo( tb );
actRecordPrev = new QAction( Unicode( "上一首记录" ), Unicode( "上一首(&P)" ), 0, this, 0 );
connect( actRecordPrev, SIGNAL( activated() ), zw, SLOT( recordPrev() ) );
connect( zw, SIGNAL( recordPrevEnabled( bool ) ), actRecordPrev, SLOT( setEnabled( bool ) ) );
actRecordPrev->setIconSet( QPixmap( "img/prev.xpm") );
actRecordPrev->addTo( pmRecord );
actRecordPrev->addTo( tb );
actRecordNext = new QAction( Unicode( "下一首记录" ), Unicode( "下一首(&N)" ), 0, this, 0 );
connect( actRecordNext, SIGNAL( activated() ), zw, SLOT( recordNext() ) );
connect( zw, SIGNAL( recordNextEnabled( bool ) ), actRecordNext, SLOT( setEnabled( bool ) ) );
actRecordNext->setIconSet( QPixmap( "img/next.xpm") );
actRecordNext->addTo( pmRecord );
actRecordNext->addTo( tb );
actRecordLast = new QAction( Unicode( "最后一首记录" ), Unicode( "最后一首条(&L)" ), 0, this, 0 );
connect( actRecordLast, SIGNAL( activated() ), zw, SLOT( recordLast() ) );
connect( zw, SIGNAL( recordLastEnabled( bool ) ), actRecordLast, SLOT( setEnabled( bool ) ) );
actRecordLast->setIconSet( QPixmap( "img/last.xpm") );
actRecordLast->addTo( pmRecord );
actRecordLast->addTo( tb );
pmRecord->insertSeparator();
tb->addSeparator();
actRecordRandom = new QAction( Unicode( "乱翻书" ), Unicode( "乱翻书" ), 0, this, 0 );
connect( actRecordRandom, SIGNAL( activated() ), zw, SLOT( recordRandom() ) );
actRecordRandom->addTo( pmRecord );
actRecordNumber = new QAction( Unicode( "第...首" ), Unicode( "第...首" ), 0, this, 0 );
connect( actRecordNumber, SIGNAL( activated() ), zw, SLOT( recordNumber() ) );
actRecordNumber->addTo( pmRecord );
QPopupMenu *pmHistory = new QPopupMenu( this );
menuBar()->insertItem( Unicode( "历史(&I)" ), pmHistory );
actHistoryPrev = new QAction( Unicode( "上一首历史记录" ), Unicode( "上一首(&P)" ), 0, this, 0 );
connect( actHistoryPrev, SIGNAL( activated() ), zw, SLOT( historyPrev() ) );
connect( zw, SIGNAL( historyPrevEnabled( bool ) ), actHistoryPrev, SLOT( setEnabled( bool ) ) );
actHistoryPrev->setIconSet( QPixmap( "img/hprev.xpm") );
actHistoryPrev->addTo( pmHistory );
actHistoryPrev->addTo( tb );
actHistoryNext = new QAction( Unicode( "下一首历史记录" ), Unicode( "下一首(&N)" ), 0, this, 0 );
connect( actHistoryNext, SIGNAL( activated() ), zw, SLOT( historyNext() ) );
connect( zw, SIGNAL( historyNextEnabled( bool ) ), actHistoryNext, SLOT( setEnabled( bool ) ) );
actHistoryNext->setIconSet( QPixmap( "img/hnext.xpm") );
actHistoryNext->addTo( pmHistory );
actHistoryNext->addTo( tb );
pmHistory->insertSeparator();
actClearHistory = new QAction( Unicode( "清空历史记录" ), Unicode( "清空历史记录(&C)" ), 0, this, 0 );
connect( actClearHistory, SIGNAL( activated() ), zw, SLOT( clearHistory() ) );
actClearHistory->addTo( pmHistory );
pmBookmark = new QPopupMenu( this );
menuBar()->insertItem( Unicode( "书签(&B)" ), pmBookmark );
actAddBookmark = new QAction( Unicode( "添加书签" ), Unicode( "添加书签(&A)" ), 0, this, 0 );
connect( actAddBookmark, SIGNAL( activated() ), zw, SLOT( addBookmark() ) );
actAddBookmark->addTo( pmBookmark );
actModifyBookmark = new QAction( Unicode( "修改书签" ), Unicode( "修改书签(&M)" ), 0, this, 0 );
connect( actModifyBookmark, SIGNAL( activated() ), zw, SLOT( modifyBookmark() ) );
actModifyBookmark->addTo( pmBookmark );
actClearBookmark = new QAction( Unicode( "清空书签" ), Unicode( "清空书签(&C)" ), 0, this, 0 );
connect( actClearBookmark, SIGNAL( activated() ), zw, SLOT( clearBookmark() ) );
actClearBookmark->addTo( pmBookmark );
pmBookmark->insertSeparator();
connect( pmBookmark, SIGNAL( activated(int) ), this, SLOT( bookmark(int) ) );
connect( this, SIGNAL( selectBookmark( QString ) ), zw, SLOT( selectBookmark( QString ) ) );
QPopupMenu *pmHelp = new QPopupMenu( this );
menuBar()->insertItem( Unicode ( "帮助(&H)" ), pmHelp );
pmHelp->insertItem( Unicode( "关于(&A)" ), this, SLOT( about() ), Key_F1 );
pmHelp->insertItem( Unicode( "关于Qt(&Q)" ), this, SLOT( aboutQt() ) );
lPoemCount = new QLabel( this );
statusBar()->addWidget( lPoemCount, 0, TRUE );
lPoemIndex = new QLabel( this );
statusBar()->addWidget( lPoemIndex, 0, TRUE );
lPoetCount = new QLabel( this );
statusBar()->addWidget( lPoetCount, 0, TRUE );
connect( zw, SIGNAL( poemCount( int ) ), this, SLOT( poemCount( int ) ) );
connect( zw, SIGNAL( poetCount( QString, int ) ), this, SLOT( poetCount( QString, int ) ) );
connect( zw, SIGNAL( poemIndex( int ) ), this, SLOT( poemIndex( int ) ) );
connect( zw, SIGNAL( bookmarkChanged( BookmarkList ) ), this, SLOT( bookmarkChanged( BookmarkList ) ) );
zw->init();
setFocusProxy( zw );
setCentralWidget( zw );
showMaximized();
}
ZhscMainWindow::~ZhscMainWindow()
{
}
void ZhscMainWindow::bookmark( int index )
{
QString bm;
bm = pmBookmark->text( index );
emit selectBookmark( bm );
}
void ZhscMainWindow::bookmarkChanged( BookmarkList bml )
{
if ( pmBookmark != NULL )
{
pmBookmark->clear();
actAddBookmark = new QAction( Unicode( "添加书签" ), Unicode( "添加书签(&A)" ), 0, this, 0 );
connect( actAddBookmark, SIGNAL( activated() ), zw, SLOT( addBookmark() ) );
actAddBookmark->addTo( pmBookmark );
actModifyBookmark = new QAction( Unicode( "修改书签" ), Unicode( "修改书签(&M)" ), 0, this, 0 );
connect( actModifyBookmark, SIGNAL( activated() ), zw, SLOT( modifyBookmark() ) );
actModifyBookmark->addTo( pmBookmark );
actClearBookmark = new QAction( Unicode( "清空书签" ), Unicode( "清空书签(&C)" ), 0, this, 0 );
connect( actClearBookmark, SIGNAL( activated() ), zw, SLOT( clearBookmark() ) );
actClearBookmark->addTo( pmBookmark );
pmBookmark->insertSeparator();
BookmarkList::Iterator it;
for ( it = bml.begin(); it != bml.end(); ++it )
{
pmBookmark->insertItem( (*it).content );
}
}
}
void ZhscMainWindow::about()
{
QMessageBox::about( this, Unicode( "中华诗词 Qt版" ),
Unicode( "中华诗词 Qt版\n0.0.1版\n\n改编自 方旻的中华诗词6000\n中华诗词主页:http://www.zhsc.com\n方旻的Email:roadcom@zhsc.com\n\n作者:Cavendish\n个人主页:http://www.qiliang.net\nEmail:cavendish@qiliang.net\n2003年6月23日" ) );
}
void ZhscMainWindow::aboutQt()
{
QMessageBox::aboutQt( this, Unicode( "关于Qt" ) );
}
void ZhscMainWindow::poemCount( int count )
{
if ( lPoemCount != NULL )
{
lPoemCount->setText( Unicode( "共%1首作品" ).arg( count ) );
}
}
void ZhscMainWindow::poetCount( QString poet, int count )
{
if ( lPoetCount != NULL )
{
lPoetCount->setText( Unicode( "%1的作品共%2首" ).arg( poet ).arg( count ) );
}
}
void ZhscMainWindow::poemIndex( int index )
{
if ( lPoemIndex != NULL )
{
lPoemIndex->setText( Unicode( "当前为总第%1首" ).arg( index ) );
}
}