themewidget.cpp
00001 /* 00002 * Copyright (C) 2005 Petri Damstén <petri.damsten@iki.fi> 00003 * 00004 * This file is part of SuperKaramba. 00005 * 00006 * SuperKaramba is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * SuperKaramba is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with SuperKaramba; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 ****************************************************************************/ 00020 #include "themewidget.h" 00021 #include "themelocale.h" 00022 #include <kpushbutton.h> 00023 #include <kdebug.h> 00024 #include <klocale.h> 00025 #include <tqlabel.h> 00026 #include <tqlayout.h> 00027 00028 ThemeWidget::ThemeWidget(TQWidget *parent, const char *name) 00029 : ThemeWidgetLayout(parent, name), m_themeFile(0) 00030 { 00031 running->setText(""); 00032 setDescriptionMaxHeight(); 00033 } 00034 00035 ThemeWidget::ThemeWidget(ThemeFile* tf) 00036 : m_themeFile(tf) 00037 { 00038 TQPixmap pixmap = m_themeFile->icon(); 00039 if(!pixmap.isNull()) 00040 icon->setPixmap(pixmap); 00041 TQString version; 00042 if(!m_themeFile->version().isEmpty()) 00043 version = " - " + m_themeFile->version(); 00044 themeName->setText( 00045 m_themeFile->locale()->translate(m_themeFile->name().ascii()) + version); 00046 description->setText( 00047 m_themeFile->locale()->translate(m_themeFile->description().ascii())); 00048 running->setText(""); 00049 buttonGo->hide(); 00050 setDescriptionMaxHeight(); 00051 } 00052 00053 ThemeWidget::~ThemeWidget() 00054 { 00055 delete m_themeFile; 00056 } 00057 00058 int ThemeWidget::addInstance() 00059 { 00060 int i = 1; 00061 while(m_instancePool.find(i) != m_instancePool.end()) 00062 ++i; 00063 m_instancePool.append(i); 00064 updateRunning(); 00065 return i; 00066 } 00067 00068 void ThemeWidget::removeInstance(int instance) 00069 { 00070 m_instancePool.remove(instance); 00071 updateRunning(); 00072 } 00073 00074 void ThemeWidget::updateRunning() 00075 { 00076 int i = instances(); 00077 if(i > 0) 00078 running->setText(i18n("<p align=\"center\">%1 running</p>").arg(i)); 00079 else 00080 running->setText(""); 00081 } 00082 00083 void ThemeWidget::setDescriptionText(TQString text) 00084 { 00085 description->setText(text); 00086 } 00087 00088 void ThemeWidget::setHeaderText(TQString text) 00089 { 00090 themeName->setText(text); 00091 } 00092 00093 void ThemeWidget::showButton(bool show) 00094 { 00095 if(show) 00096 buttonGo->show(); 00097 else 00098 buttonGo->hide(); 00099 setDescriptionMaxHeight(); 00100 } 00101 00102 void ThemeWidget::setDescriptionMaxHeight() 00103 { 00104 if(layoutText->geometry().height() <= 0) 00105 return; 00106 int height = layoutText->geometry().height() - themeName->height() - 00107 layoutText->spacing(); 00108 if(buttonGo->isVisible()) 00109 height -= layoutButton->geometry().height() + layoutText->spacing(); 00110 description->setMaximumHeight(height); 00111 } 00112 00113 #include "themewidget.moc"