summaryrefslogtreecommitdiff
path: root/libopie2/opieui/otabwidget.cpp
authordrw <drw>2005-04-05 22:38:32 (UTC)
committer drw <drw>2005-04-05 22:38:32 (UTC)
commit0f7b159f0a4972b6ffdc292f5eb4d2169c7fa75d (patch) (unidiff)
tree27fb276e59b1eab586d029feaf21f45ddf1cb96a /libopie2/opieui/otabwidget.cpp
parent327e938f58125a52482b9a6543dd1aa4243bb5d3 (diff)
downloadopie-0f7b159f0a4972b6ffdc292f5eb4d2169c7fa75d.zip
opie-0f7b159f0a4972b6ffdc292f5eb4d2169c7fa75d.tar.gz
opie-0f7b159f0a4972b6ffdc292f5eb4d2169c7fa75d.tar.bz2
Use OResource for loading images
Diffstat (limited to 'libopie2/opieui/otabwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/otabwidget.cpp66
1 files changed, 30 insertions, 36 deletions
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp
index 8d7806c..7333f5e 100644
--- a/libopie2/opieui/otabwidget.cpp
+++ b/libopie2/opieui/otabwidget.cpp
@@ -1,50 +1,50 @@
1/* 1/*
2 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 Copyright (c) 2002, 2005 Dan Williams <drw@handhelds.org> 4 Copyright (C) 2002, 2005 Dan Williams <drw@handhelds.org>
5 =. 5 =.
6 .=l. 6 .=l.
7 .>+-= 7           .>+-=
8_;:, .> :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_, > . <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12- . .-<_> .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13 ._= =} : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14 .%`+i> _;_. 14    .%`+i>       _;_.
15 .i_,=:_. -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17 : .. .:, . . . without even the implied warranty of 17 : ..    .:,     . . . without even the implied warranty of
18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.= = ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++= -. .` .: details. 21++=   -.     .`     .: details.
22: = ...= . :.=- 22 :     =  ...= . :.=-
23-. .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24 -_. . . )=. = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25 -- :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29
30*/ 29*/
31 30
32#include <opie2/otabwidget.h> 31#include <opie2/otabwidget.h>
33 32
34/* OPIE */ 33/* OPIE */
34#include <opie2/oresource.h>
35#include <opie2/otabbar.h>
36
35#include <qpe/applnk.h> 37#include <qpe/applnk.h>
36#include <qpe/config.h> 38#include <qpe/config.h>
37#include <qpe/resource.h>
38#include <opie2/otabbar.h>
39 39
40/* QT */ 40/* QT */
41#include <qcombobox.h> 41#include <qcombobox.h>
42#include <qwidgetstack.h> 42#include <qwidgetstack.h>
43 43
44using namespace Opie::Ui; 44using namespace Opie::Ui;
45 45
46OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) 46OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p )
47 : QWidget( parent, name ) 47 : QWidget( parent, name )
48 , m_currTab( 0l ) 48 , m_currTab( 0l )
49 , m_tabBarStyle( Global ) 49 , m_tabBarStyle( Global )
50 , m_tabBarPosition( Top ) 50 , m_tabBarPosition( Top )
@@ -88,36 +88,36 @@ void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &lab
88{ 88{
89 int tabid = -1; 89 int tabid = -1;
90 90
91 if ( m_usingTabs ) 91 if ( m_usingTabs )
92 { 92 {
93 // Create new tab in tab bar 93 // Create new tab in tab bar
94 QTab *tab = new QTab(); 94 QTab *tab = new QTab();
95 95
96 // Set label (and icon if necessary) 96 // Set label (and icon if necessary)
97 if ( m_tabBarStyle == IconTab ) 97 if ( m_tabBarStyle == IconTab )
98 { 98 {
99 tab->label = QString::null; 99 tab->label = QString::null;
100 tab->iconset = new QIconSet( loadSmooth( icon ) ); 100 tab->iconset = new QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) );
101 } 101 }
102 else 102 else
103 tab->label = label; 103 tab->label = label;
104 104
105 tabid = m_tabBar->addTab( tab ); 105 tabid = m_tabBar->addTab( tab );
106 } 106 }
107 else 107 else
108 { 108 {
109 // Insert entry (with icon if necessary) into drop down list 109 // Insert entry (with icon if necessary) into drop down list
110 if ( m_tabBarStyle == IconList ) 110 if ( m_tabBarStyle == IconList )
111 m_tabList->insertItem( loadSmooth( icon ), label, -1 ); 111 m_tabList->insertItem( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ), label, -1 );
112 else 112 else
113 m_tabList->insertItem( label ); 113 m_tabList->insertItem( label );
114 } 114 }
115 115
116 // Add widget to stack 116 // Add widget to stack
117 m_widgetStack->addWidget( child, tabid ); 117 m_widgetStack->addWidget( child, tabid );
118 m_widgetStack->raiseWidget( child ); 118 m_widgetStack->raiseWidget( child );
119 m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); 119 m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
120 120
121 // Keep track of tab information 121 // Keep track of tab information
122 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); 122 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
123 m_tabs.append( tabinfo ); 123 m_tabs.append( tabinfo );
@@ -171,25 +171,25 @@ void OTabWidget::removePage( QWidget *childwidget )
171 } 171 }
172} 172}
173 173
174void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) 174void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
175{ 175{
176 // Find tab information for desired widget 176 // Find tab information for desired widget
177 OTabInfo *currtab = m_tabs.first(); 177 OTabInfo *currtab = m_tabs.first();
178 while ( currtab && currtab->control() != widget ) 178 while ( currtab && currtab->control() != widget )
179 currtab = m_tabs.next(); 179 currtab = m_tabs.next();
180 180
181 if ( currtab && currtab->control() == widget ) 181 if ( currtab && currtab->control() == widget )
182 { 182 {
183 QPixmap icon( loadSmooth( iconset ) ); 183 QPixmap icon( Opie::Core::OResource::loadPixmap( iconset, Opie::Core::OResource::SmallIcon ) );
184 184
185 if ( m_usingTabs ) 185 if ( m_usingTabs )
186 { 186 {
187 // Update tab label and icon (if necessary) 187 // Update tab label and icon (if necessary)
188 QTab *tab = m_tabBar->tab( currtab->id() ); 188 QTab *tab = m_tabBar->tab( currtab->id() );
189 tab->setText( label ); 189 tab->setText( label );
190 if ( m_tabBarStyle == IconTab ) 190 if ( m_tabBarStyle == IconTab )
191 tab->setIconSet( icon ); 191 tab->setIconSet( icon );
192 } 192 }
193 else 193 else
194 { 194 {
195 // Update entry label and icon (if necessary) 195 // Update entry label and icon (if necessary)
@@ -289,45 +289,46 @@ void OTabWidget::setTabStyle( TabStyle s )
289 connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabBarSelected(int)) ); 289 connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabBarSelected(int)) );
290 290
291 // Add all current tabs to tab bar 291 // Add all current tabs to tab bar
292 for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) 292 for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() )
293 { 293 {
294 // Create new tab in tab bar 294 // Create new tab in tab bar
295 QTab *tab = new QTab(); 295 QTab *tab = new QTab();
296 296
297 // Set label (and icon if necessary) 297 // Set label (and icon if necessary)
298 if ( m_tabBarStyle == IconTab ) 298 if ( m_tabBarStyle == IconTab )
299 { 299 {
300 tab->label = QString::null; 300 tab->label = QString::null;
301 tab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); 301 tab->iconset = new QIconSet( Opie::Core::OResource::loadPixmap( tabinfo->icon(), Opie::Core::OResource::SmallIcon ) );
302 } 302 }
303 else 303 else
304 tab->label = tabinfo->label(); 304 tab->label = tabinfo->label();
305 305
306 // Add tab and save its Id 306 // Add tab and save its Id
307 int tabid = m_tabBar->addTab( tab ); 307 int tabid = m_tabBar->addTab( tab );
308 tabinfo->setId( tabid ); 308 tabinfo->setId( tabid );
309 } 309 }
310 } 310 }
311 else 311 else
312 { 312 {
313 // Create new drop down list selector 313 // Create new drop down list selector
314 m_tabList = new QComboBox( false, this ); 314 m_tabList = new QComboBox( false, this );
315 connect( m_tabList, SIGNAL(activated(int)), this, SLOT(slotTabListSelected(int)) ); 315 connect( m_tabList, SIGNAL(activated(int)), this, SLOT(slotTabListSelected(int)) );
316 316
317 // Add all current tabs to drop down list 317 // Add all current tabs to drop down list
318 for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) 318 for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() )
319 { 319 {
320 if ( m_tabBarStyle == IconList ) 320 if ( m_tabBarStyle == IconList )
321 m_tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); 321 m_tabList->insertItem( Opie::Core::OResource::loadPixmap( tabinfo->icon(), Opie::Core::OResource::SmallIcon ),
322 tabinfo->label() );
322 else 323 else
323 m_tabList->insertItem( tabinfo->label() ); 324 m_tabList->insertItem( tabinfo->label() );
324 } 325 }
325 } 326 }
326 327
327 // Redraw widget 328 // Redraw widget
328 setUpLayout(); 329 setUpLayout();
329} 330}
330 331
331OTabWidget::TabPosition OTabWidget::tabPosition() const 332OTabWidget::TabPosition OTabWidget::tabPosition() const
332{ 333{
333 return m_tabBarPosition; 334 return m_tabBarPosition;
@@ -356,31 +357,24 @@ void OTabWidget::slotTabBarSelected( int id )
356 357
357 if ( newtab && newtab->id() == id ) 358 if ( newtab && newtab->id() == id )
358 selectTab( newtab ); 359 selectTab( newtab );
359} 360}
360 361
361void OTabWidget::slotTabListSelected( int index ) 362void OTabWidget::slotTabListSelected( int index )
362{ 363{
363 OTabInfo *newtab = m_tabs.at( index ); 364 OTabInfo *newtab = m_tabs.at( index );
364 if ( newtab ) 365 if ( newtab )
365 selectTab( newtab ); 366 selectTab( newtab );
366} 367}
367 368
368QPixmap OTabWidget::loadSmooth( const QString &name )
369{
370 QPixmap p;
371 p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) );
372 return p;
373}
374
375void OTabWidget::selectTab( OTabInfo *tab ) 369void OTabWidget::selectTab( OTabInfo *tab )
376{ 370{
377 if ( m_tabBarStyle == IconTab ) 371 if ( m_tabBarStyle == IconTab )
378 { 372 {
379 // Remove text label from currently selected tab 373 // Remove text label from currently selected tab
380 if ( m_currTab ) 374 if ( m_currTab )
381 { 375 {
382 m_tabBar->tab( m_currTab->id() )->setText( QString::null ); 376 m_tabBar->tab( m_currTab->id() )->setText( QString::null );
383 //setUpLayout(); 377 //setUpLayout();
384 } 378 }
385 379
386 // Set text label for newly selected tab 380 // Set text label for newly selected tab