themewidget.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "themewidget.h"
00021 #include "themelocale.h"
00022 #include <kpushbutton.h>
00023 #include <kdebug.h>
00024 #include <klocale.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027
00028 ThemeWidget::ThemeWidget(QWidget *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 QPixmap pixmap = m_themeFile->icon();
00039 if(!pixmap.isNull())
00040 icon->setPixmap(pixmap);
00041 QString 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(QString text)
00084 {
00085 description->setText(text);
00086 }
00087
00088 void ThemeWidget::setHeaderText(QString 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"
|