source: trunk/tools/assistant/tabbedbrowser.ui.h@ 191

Last change on this file since 191 was 191, checked in by rudi, 14 years ago

Qt Assistant added

File size: 9.9 KB
Line 
1/****************************************************************************
2** ui.h extension file, included from the uic-generated form implementation.
3**
4** If you wish to add, delete or rename functions or slots use
5** Qt Designer which will update this file, preserving your code. Create an
6** init() function in place of a constructor, and a destroy() function in
7** place of a destructor.
8*****************************************************************************/
9
10#include <qfileinfo.h>
11#include <qtoolbutton.h>
12#include <qpixmap.h>
13#include <qiconset.h>
14#include <qstyle.h>
15#include <qtimer.h>
16
17#include "config.h"
18
19static QString reduceLabelLength( const QString &s )
20{
21 uint maxLength = 16;
22 QString str = s;
23 if ( str.length() < maxLength )
24 return str;
25 str = str.left( maxLength - 3 );
26 str += "...";
27 return str;
28}
29
30void TabbedBrowser::forward()
31{
32 currentBrowser()->forward();
33}
34
35void TabbedBrowser::backward()
36{
37 currentBrowser()->backward();
38}
39
40void TabbedBrowser::setSource( const QString &ref )
41{
42 HelpWindow * win = currentBrowser();
43 win->setSource(ref);
44}
45
46void TabbedBrowser::reload()
47{
48 currentBrowser()->reload();
49}
50
51void TabbedBrowser::home()
52{
53 currentBrowser()->home();
54}
55
56HelpWindow * TabbedBrowser::currentBrowser()
57{
58 return (HelpWindow*) tab->currentPage();
59}
60
61void TabbedBrowser::nextTab()
62{
63 if( tab->currentPageIndex()<=tab->count()-1 )
64 tab->setCurrentPage( tab->currentPageIndex()+1 );
65}
66
67void TabbedBrowser::previousTab()
68{
69 int idx = tab->currentPageIndex()-1;
70 if( idx>=0 )
71 tab->setCurrentPage( idx );
72}
73
74HelpWindow *TabbedBrowser::createHelpWindow(const QString &title)
75{
76 MainWindow *mainWin = mainWindow();
77 HelpWindow *win = new HelpWindow( mainWin, this, "qt_assistant_helpwin" );
78 win->setFont( browserFont() );
79 win->setPalette( palette() );
80 win->setLinkUnderline( tabLinkUnderline );
81 win->setStyleSheet( tabStyleSheet );
82 win->setMimeSourceFactory( mimeSourceFactory );
83 tab->addTab(win, reduceLabelLength(title));
84 connect( win, SIGNAL( highlighted( const QString & ) ),
85 (const QObject*) (mainWin->statusBar()), SLOT( message( const QString & ) ) );
86 connect( win, SIGNAL( chooseWebBrowser() ), mainWin, SLOT( showWebBrowserSettings() ) );
87 connect( win, SIGNAL( backwardAvailable(bool) ),
88 mainWin, SLOT( backwardAvailable(bool) ) );
89 connect( win, SIGNAL( forwardAvailable(bool) ),
90 mainWin, SLOT( forwardAvailable(bool) ) );
91 connect( win, SIGNAL( sourceChanged(const QString &) ), this, SLOT( sourceChanged() ));
92
93 tab->cornerWidget( Qt::TopRight )->setEnabled( tab->count() > 1 );
94 return win;
95}
96
97HelpWindow *TabbedBrowser::newBackgroundTab( const QString &url )
98{
99 HelpWindow *win = createHelpWindow(url);
100 return win;
101}
102
103void TabbedBrowser::newTab( const QString &lnk )
104{
105 QString link( lnk );
106 if( link.isNull() ) {
107 HelpWindow *w = currentBrowser();
108 if( w )
109 link = w->source();
110 }
111 HelpWindow *win = createHelpWindow(link);
112 tab->showPage( win );
113 if( !link.isNull() ) {
114 win->setSource( link );
115 }
116}
117
118void TabbedBrowser::zoomIn()
119{
120 currentBrowser()->zoomIn();
121}
122
123void TabbedBrowser::zoomOut()
124{
125 currentBrowser()->zoomOut();
126}
127
128void TabbedBrowser::init()
129{
130 tabLinkUnderline = FALSE;
131 tabStyleSheet = new QStyleSheet( QStyleSheet::defaultSheet() );
132 lastCurrentTab = 0;
133 while( tab->count() )
134 tab->removePage( tab->page(0) );
135
136 mimeSourceFactory = new QMimeSourceFactory();
137 mimeSourceFactory->setExtensionType("html","text/html;charset=UTF-8");
138 mimeSourceFactory->setExtensionType("htm","text/html;charset=UTF-8");
139 mimeSourceFactory->setExtensionType("png", "image/png" );
140 mimeSourceFactory->setExtensionType("jpg", "image/jpeg" );
141 mimeSourceFactory->setExtensionType("jpeg", "image/jpeg" );
142 setMimePath( Config::configuration()->mimePaths() );
143
144 connect( tab, SIGNAL( currentChanged( QWidget* ) ),
145 this, SLOT( transferFocus() ) );
146 connect( tab, SIGNAL( currentChanged( QWidget* ) ),
147 mainWindow(), SLOT( browserTabChanged() ) );
148
149 QTabBar *tabBar = (QTabBar*)tab->child( 0, "QTabBar", FALSE );
150 int m = ( tabBar ? style().pixelMetric( QStyle::PM_TabBarTabVSpace, (QWidget*)tabBar )
151 + style().pixelMetric( QStyle::PM_TabBarBaseHeight, (QWidget*)tabBar ) : 0 );
152 int s = tab->height() - m;
153
154 // workaround for sgi style
155 QPalette pal = palette();
156 pal.setColor(QPalette::Active, QColorGroup::Button, pal.active().background());
157 pal.setColor(QPalette::Disabled, QColorGroup::Button, pal.disabled().background());
158 pal.setColor(QPalette::Inactive, QColorGroup::Button, pal.inactive().background());
159
160 QToolButton *newTabButton = new QToolButton( this );
161 newTabButton->setPalette(pal);
162 tab->setCornerWidget( newTabButton, Qt::TopLeft );
163 newTabButton->setCursor( arrowCursor );
164 newTabButton->setAutoRaise( TRUE );
165 newTabButton->setPixmap( QPixmap::fromMimeSource( "addtab.png" ) );
166 newTabButton->setFixedSize( s, s );
167 QObject::connect( newTabButton, SIGNAL( clicked() ), this, SLOT( newTab() ) );
168 QToolTip::add( newTabButton, tr( "Add page" ) );
169
170 QToolButton *closeTabButton = new QToolButton( this );
171 closeTabButton->setPalette(pal);
172 tab->setCornerWidget( closeTabButton, Qt::TopRight );
173 closeTabButton->setCursor( arrowCursor );
174 closeTabButton->setAutoRaise( TRUE );
175 QIconSet is( QPixmap::fromMimeSource( "closetab.png") );
176 QPixmap disabledPix = QPixmap::fromMimeSource( "d_closetab.png" );
177 is.setPixmap( disabledPix, QIconSet::Small, QIconSet::Disabled );
178 closeTabButton->setIconSet( is );
179 closeTabButton->setFixedSize( s, s );
180 QObject::connect( closeTabButton, SIGNAL( clicked() ), this, SLOT( closeTab() ) );
181 QToolTip::add( closeTabButton, tr( "Close page" ) );
182 closeTabButton->setEnabled( FALSE );
183}
184
185void TabbedBrowser::setMimePath( QStringList lst )
186{
187 mimeSourceFactory->setFilePath( lst );
188}
189
190void TabbedBrowser::setMimeExtension( const QString &ext )
191{
192 mimeSourceFactory->setExtensionType( "html", ext );
193 mimeSourceFactory->setExtensionType( "htm", ext );
194}
195
196void TabbedBrowser::updateTitle( const QString &title )
197{
198 tab->changeTab( currentBrowser(), title );
199}
200
201MainWindow* TabbedBrowser::mainWindow()
202{
203 return (MainWindow*) parent();
204}
205
206void TabbedBrowser::newTab()
207{
208 newTab( QString::null );
209}
210
211void TabbedBrowser::transferFocus()
212{
213 if( currentBrowser() ) {
214 currentBrowser()->setFocus();
215 }
216 mainWindow()->setCaption(Config::configuration()->title()
217 + " - " + currentBrowser()->documentTitle());
218}
219
220void TabbedBrowser::initHelpWindow( HelpWindow * /*win*/ )
221{
222}
223
224void TabbedBrowser::setup()
225{
226 Config *config = Config::configuration();
227
228 QFont fnt( font() );
229 QFontInfo fntInfo( fnt );
230 fnt.setFamily( config->fontFamily() );
231 fnt.setPointSize( config->fontSize() );
232 setBrowserFont( fnt );
233
234 QPalette pal = palette();
235 QColor lc( config->linkColor() );
236 pal.setColor( QPalette::Active, QColorGroup::Link, lc );
237 pal.setColor( QPalette::Inactive, QColorGroup::Link, lc );
238 pal.setColor( QPalette::Disabled, QColorGroup::Link, lc );
239 setPalette( pal );
240
241 tabLinkUnderline = config->isLinkUnderline();
242
243 QString family = config->fontFixedFamily();
244 tabStyleSheet->item( "pre" )->setFontFamily( family );
245 tabStyleSheet->item( "code" )->setFontFamily( family );
246 tabStyleSheet->item( "tt" )->setFontFamily( family );
247
248 newTab( QString::null );
249}
250
251void TabbedBrowser::setLinkUnderline( bool uline )
252{
253 if( uline==tabLinkUnderline )
254 return;
255 tabLinkUnderline = uline;
256 int cnt = tab->count();
257 for( int i=0; i<cnt; i++ )
258 ( (QTextBrowser*) tab->page( i ) )->setLinkUnderline( tabLinkUnderline );
259}
260
261QFont TabbedBrowser::browserFont()
262{
263 return tabFont;
264}
265
266void TabbedBrowser::setBrowserFont( const QFont &fnt )
267{
268 if( tabFont == fnt )
269 return;
270 tabFont = fnt;
271 int cnt = tab->count();
272 for( int i=0; i<cnt; i++ )
273 ( (QTextBrowser*) tab->page( i ) )->setFont( fnt );
274}
275
276void TabbedBrowser::setPalette( const QPalette &pal )
277{
278 if( palette()==pal )
279 return;
280 QWidget::setPalette( pal );
281 int cnt = tab->count();
282 for( int i=0; i<cnt; i++ )
283 ( (QTextBrowser*) tab->page( i ) )->setPalette( pal );
284}
285
286QStyleSheet* TabbedBrowser::styleSheet()
287{
288 return tabStyleSheet;
289}
290
291bool TabbedBrowser::linkUnderline()
292{
293 return tabLinkUnderline;
294}
295
296void TabbedBrowser::copy()
297{
298 currentBrowser()->copy();
299}
300
301void TabbedBrowser::closeTab()
302{
303 if( tab->count()==1 )
304 return;
305 HelpWindow *win = currentBrowser();
306 tab->removePage( win );
307 QTimer::singleShot(0, win, SLOT(deleteLater()));
308 tab->cornerWidget( Qt::TopRight )->setEnabled( tab->count() > 1 );
309}
310
311QStringList TabbedBrowser::sources()
312{
313 QStringList lst;
314 int cnt = tab->count();
315 for( int i=0; i<cnt; i++ ) {
316 lst.append( ( (QTextBrowser*) tab->page(i) )->source() );
317 }
318 return lst;
319}
320
321QPtrList<HelpWindow> TabbedBrowser::browsers() const
322{
323 QPtrList<HelpWindow> list;
324 for (int i=0; i<tab->count(); ++i) {
325 Q_ASSERT(::qt_cast<HelpWindow*>(tab->page(i)));
326 list.append(::qt_cast<HelpWindow*>(tab->page(i)));
327 }
328 return list;
329}
330
331void TabbedBrowser::sourceChanged()
332{
333 HelpWindow *win = ::qt_cast<HelpWindow *>( QObject::sender() );
334 Q_ASSERT( win );
335 QString docTitle(win->documentTitle());
336 if (docTitle.isEmpty())
337 docTitle = "...";
338 setTitle(win, docTitle);
339}
340
341void TabbedBrowser::setTitle(HelpWindow *win, const QString &title)
342{
343 tab->setTabLabel(win, reduceLabelLength(title));
344 if (win == currentBrowser())
345 mainWindow()->setCaption(Config::configuration()->title() + " - " + title);
346}
347
Note: See TracBrowser for help on using the repository browser.