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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
#include <qfileinfo.h>
#include <qtoolbutton.h>
#include <qpixmap.h>
#include <qiconset.h>
#include <qstyle.h>
#include <qtimer.h>
#include "config.h"
static QString reduceLabelLength( const QString &s )
{
uint maxLength = 16;
QString str = s;
if ( str.length() < maxLength )
return str;
str = str.left( maxLength - 3 );
str += "...";
return str;
}
void TabbedBrowser::forward()
{
currentBrowser()->forward();
}
void TabbedBrowser::backward()
{
currentBrowser()->backward();
}
void TabbedBrowser::setSource( const QString &ref )
{
HelpWindow * win = currentBrowser();
win->setSource(ref);
}
void TabbedBrowser::reload()
{
currentBrowser()->reload();
}
void TabbedBrowser::home()
{
currentBrowser()->home();
}
HelpWindow * TabbedBrowser::currentBrowser()
{
return (HelpWindow*) tab->currentPage();
}
void TabbedBrowser::nextTab()
{
if( tab->currentPageIndex()<=tab->count()-1 )
tab->setCurrentPage( tab->currentPageIndex()+1 );
}
void TabbedBrowser::previousTab()
{
int idx = tab->currentPageIndex()-1;
if( idx>=0 )
tab->setCurrentPage( idx );
}
HelpWindow *TabbedBrowser::createHelpWindow(const QString &title)
{
MainWindow *mainWin = mainWindow();
HelpWindow *win = new HelpWindow( mainWin, this, "qt_assistant_helpwin" );
win->setFont( browserFont() );
win->setPalette( palette() );
win->setLinkUnderline( tabLinkUnderline );
win->setStyleSheet( tabStyleSheet );
win->setMimeSourceFactory( mimeSourceFactory );
tab->addTab(win, reduceLabelLength(title));
connect( win, SIGNAL( highlighted( const QString & ) ),
(const QObject*) (mainWin->statusBar()), SLOT( message( const QString & ) ) );
connect( win, SIGNAL( chooseWebBrowser() ), mainWin, SLOT( showWebBrowserSettings() ) );
connect( win, SIGNAL( backwardAvailable(bool) ),
mainWin, SLOT( backwardAvailable(bool) ) );
connect( win, SIGNAL( forwardAvailable(bool) ),
mainWin, SLOT( forwardAvailable(bool) ) );
connect( win, SIGNAL( sourceChanged(const QString &) ), this, SLOT( sourceChanged() ));
tab->cornerWidget( Qt::TopRight )->setEnabled( tab->count() > 1 );
return win;
}
HelpWindow *TabbedBrowser::newBackgroundTab( const QString &url )
{
HelpWindow *win = createHelpWindow(url);
return win;
}
void TabbedBrowser::newTab( const QString &lnk )
{
QString link( lnk );
if( link.isNull() ) {
HelpWindow *w = currentBrowser();
if( w )
link = w->source();
}
HelpWindow *win = createHelpWindow(link);
tab->showPage( win );
if( !link.isNull() ) {
win->setSource( link );
}
}
void TabbedBrowser::zoomIn()
{
currentBrowser()->zoomIn();
}
void TabbedBrowser::zoomOut()
{
currentBrowser()->zoomOut();
}
void TabbedBrowser::init()
{
tabLinkUnderline = FALSE;
tabStyleSheet = new QStyleSheet( QStyleSheet::defaultSheet() );
lastCurrentTab = 0;
while( tab->count() )
tab->removePage( tab->page(0) );
mimeSourceFactory = new QMimeSourceFactory();
mimeSourceFactory->setExtensionType("html","text/html;charset=UTF-8");
mimeSourceFactory->setExtensionType("htm","text/html;charset=UTF-8");
mimeSourceFactory->setExtensionType("png", "image/png" );
mimeSourceFactory->setExtensionType("jpg", "image/jpeg" );
mimeSourceFactory->setExtensionType("jpeg", "image/jpeg" );
setMimePath( Config::configuration()->mimePaths() );
connect( tab, SIGNAL( currentChanged( QWidget* ) ),
this, SLOT( transferFocus() ) );
connect( tab, SIGNAL( currentChanged( QWidget* ) ),
mainWindow(), SLOT( browserTabChanged() ) );
QTabBar *tabBar = (QTabBar*)tab->child( 0, "QTabBar", FALSE );
int m = ( tabBar ? style().pixelMetric( QStyle::PM_TabBarTabVSpace, (QWidget*)tabBar )
+ style().pixelMetric( QStyle::PM_TabBarBaseHeight, (QWidget*)tabBar ) : 0 );
int s = tab->height() - m;
// workaround for sgi style
QPalette pal = palette();
pal.setColor(QPalette::Active, QColorGroup::Button, pal.active().background());
pal.setColor(QPalette::Disabled, QColorGroup::Button, pal.disabled().background());
pal.setColor(QPalette::Inactive, QColorGroup::Button, pal.inactive().background());
QToolButton *newTabButton = new QToolButton( this );
newTabButton->setPalette(pal);
tab->setCornerWidget( newTabButton, Qt::TopLeft );
newTabButton->setCursor( arrowCursor );
newTabButton->setAutoRaise( TRUE );
newTabButton->setPixmap( QPixmap::fromMimeSource( "addtab.png" ) );
newTabButton->setFixedSize( s, s );
QObject::connect( newTabButton, SIGNAL( clicked() ), this, SLOT( newTab() ) );
QToolTip::add( newTabButton, tr( "Add page" ) );
QToolButton *closeTabButton = new QToolButton( this );
closeTabButton->setPalette(pal);
tab->setCornerWidget( closeTabButton, Qt::TopRight );
closeTabButton->setCursor( arrowCursor );
closeTabButton->setAutoRaise( TRUE );
QIconSet is( QPixmap::fromMimeSource( "closetab.png") );
QPixmap disabledPix = QPixmap::fromMimeSource( "d_closetab.png" );
is.setPixmap( disabledPix, QIconSet::Small, QIconSet::Disabled );
closeTabButton->setIconSet( is );
closeTabButton->setFixedSize( s, s );
QObject::connect( closeTabButton, SIGNAL( clicked() ), this, SLOT( closeTab() ) );
QToolTip::add( closeTabButton, tr( "Close page" ) );
closeTabButton->setEnabled( FALSE );
}
void TabbedBrowser::setMimePath( QStringList lst )
{
mimeSourceFactory->setFilePath( lst );
}
void TabbedBrowser::setMimeExtension( const QString &ext )
{
mimeSourceFactory->setExtensionType( "html", ext );
mimeSourceFactory->setExtensionType( "htm", ext );
}
void TabbedBrowser::updateTitle( const QString &title )
{
tab->changeTab( currentBrowser(), title );
}
MainWindow* TabbedBrowser::mainWindow()
{
return (MainWindow*) parent();
}
void TabbedBrowser::newTab()
{
newTab( QString::null );
}
void TabbedBrowser::transferFocus()
{
if( currentBrowser() ) {
currentBrowser()->setFocus();
}
mainWindow()->setCaption(Config::configuration()->title()
+ " - " + currentBrowser()->documentTitle());
}
void TabbedBrowser::initHelpWindow( HelpWindow * /*win*/ )
{
}
void TabbedBrowser::setup()
{
Config *config = Config::configuration();
QFont fnt( font() );
QFontInfo fntInfo( fnt );
fnt.setFamily( config->fontFamily() );
fnt.setPointSize( config->fontSize() );
setBrowserFont( fnt );
QPalette pal = palette();
QColor lc( config->linkColor() );
pal.setColor( QPalette::Active, QColorGroup::Link, lc );
pal.setColor( QPalette::Inactive, QColorGroup::Link, lc );
pal.setColor( QPalette::Disabled, QColorGroup::Link, lc );
setPalette( pal );
tabLinkUnderline = config->isLinkUnderline();
QString family = config->fontFixedFamily();
tabStyleSheet->item( "pre" )->setFontFamily( family );
tabStyleSheet->item( "code" )->setFontFamily( family );
tabStyleSheet->item( "tt" )->setFontFamily( family );
newTab( QString::null );
}
void TabbedBrowser::setLinkUnderline( bool uline )
{
if( uline==tabLinkUnderline )
return;
tabLinkUnderline = uline;
int cnt = tab->count();
for( int i=0; i<cnt; i++ )
( (QTextBrowser*) tab->page( i ) )->setLinkUnderline( tabLinkUnderline );
}
QFont TabbedBrowser::browserFont()
{
return tabFont;
}
void TabbedBrowser::setBrowserFont( const QFont &fnt )
{
if( tabFont == fnt )
return;
tabFont = fnt;
int cnt = tab->count();
for( int i=0; i<cnt; i++ )
( (QTextBrowser*) tab->page( i ) )->setFont( fnt );
}
void TabbedBrowser::setPalette( const QPalette &pal )
{
if( palette()==pal )
return;
QWidget::setPalette( pal );
int cnt = tab->count();
for( int i=0; i<cnt; i++ )
( (QTextBrowser*) tab->page( i ) )->setPalette( pal );
}
QStyleSheet* TabbedBrowser::styleSheet()
{
return tabStyleSheet;
}
bool TabbedBrowser::linkUnderline()
{
return tabLinkUnderline;
}
void TabbedBrowser::copy()
{
currentBrowser()->copy();
}
void TabbedBrowser::closeTab()
{
if( tab->count()==1 )
return;
HelpWindow *win = currentBrowser();
tab->removePage( win );
QTimer::singleShot(0, win, SLOT(deleteLater()));
tab->cornerWidget( Qt::TopRight )->setEnabled( tab->count() > 1 );
}
QStringList TabbedBrowser::sources()
{
QStringList lst;
int cnt = tab->count();
for( int i=0; i<cnt; i++ ) {
lst.append( ( (QTextBrowser*) tab->page(i) )->source() );
}
return lst;
}
QPtrList<HelpWindow> TabbedBrowser::browsers() const
{
QPtrList<HelpWindow> list;
for (int i=0; i<tab->count(); ++i) {
Q_ASSERT(::qt_cast<HelpWindow*>(tab->page(i)));
list.append(::qt_cast<HelpWindow*>(tab->page(i)));
}
return list;
}
void TabbedBrowser::sourceChanged()
{
HelpWindow *win = ::qt_cast<HelpWindow *>( QObject::sender() );
Q_ASSERT( win );
QString docTitle(win->documentTitle());
if (docTitle.isEmpty())
docTitle = "...";
setTitle(win, docTitle);
}
void TabbedBrowser::setTitle(HelpWindow *win, const QString &title)
{
tab->setTabLabel(win, reduceLabelLength(title));
if (win == currentBrowser())
mainWindow()->setCaption(Config::configuration()->title() + " - " + title);
}
|