KLcdDimmer – applet to adjust LCD brightness
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

klcddimmer.cpp 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /***************************************************************************
  2. * Copyright (C) 2005 by Lorenzo Bettini *
  3. * http://www.lorenzobettini.it *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include <ntqlcdnumber.h>
  21. #include <tdeglobal.h>
  22. #include <tdelocale.h>
  23. #include <tdeconfigdialog.h>
  24. #include <tdeapplication.h>
  25. #include <tdemessagebox.h>
  26. #include <tdepopupmenu.h>
  27. #include <kdatetbl.h> // for TDEPopupFrame
  28. #include <kiconloader.h>
  29. #include <tdeaboutapplication.h>
  30. #include <ntqlabel.h>
  31. #include <ntqframe.h>
  32. #include <kdebug.h>
  33. #ifdef HAVE_CONFIG_H
  34. #include "config.h"
  35. #endif
  36. #include "klcddimmer.h"
  37. #include "brightnesschooserimpl.h"
  38. #include "progpreferences.h"
  39. #include "preferences.h"
  40. #include "klcddimmerapplet.h"
  41. klcddimmer::klcddimmer(const TQString& configFile, Type type, int actions, TQWidget *parent, const char *name)
  42. : KPanelApplet(configFile, type, actions, parent, name),
  43. mBrightnessChooserFrame(0)
  44. {
  45. // Get the current application configuration handle
  46. ksConfig = config();
  47. /*
  48. TQLCDNumber *w = new TQLCDNumber(this);
  49. w->display(42);
  50. */
  51. // this is the popup windows that is shown when the left button is pressed
  52. mBrightnessChooserFrame = new TDEPopupFrame(this);
  53. //mBrightnessChooserFrame = new TQWidget
  54. // (this, "klcddimmer popup", WStyle_Customize | WType_Popup | TQt::WStyle_DialogBorder);
  55. chooser = new BrightnessChooserImpl(mBrightnessChooserFrame);
  56. mBrightnessChooserFrame->setMainWidget(chooser);
  57. mBrightnessChooserFrame->resize(chooser->size());
  58. connect(chooser, SIGNAL(valueUpdated()), this, SLOT(valueUpdate()));
  59. initContextMenu();
  60. /*
  61. TQFrame *w = new TQFrame(this);
  62. valueLabel = new TQLabel(w);
  63. valueLabel->setText(chooser->getValue());
  64. */
  65. klcddimmerView = new KlcdDimmerApplet(this);
  66. mainView = klcddimmerView;
  67. // klcddimmerView->brightnessIcon->setPixmap(SmallIcon("klcddimmer"));
  68. klcddimmerView->setBrightnessLevel(chooser->getValue());
  69. //klcddimmerView->resize( TQSize(122, 48).expandedTo(minimumSizeHint()) );
  70. mainView->show();
  71. /* get the current value */
  72. chooser->getBrightness();
  73. }
  74. klcddimmer::~klcddimmer()
  75. {
  76. }
  77. void klcddimmer::about()
  78. {
  79. //KMessageBox::information(0, i18n("This is an about box"));
  80. TDEAboutData aboutData("KLcdDimmer", "KLcdDimmer", VERSION,
  81. I18N_NOOP("Applet for LCD brightness adjustment"), TDEAboutData::License_GPL_V2);
  82. aboutData.addAuthor("Lorenzo Bettini", "main author", "",
  83. "http://www.lorenzobettini.it");
  84. aboutData.setHomepage("http://klcddimmer.sourceforge.net");
  85. aboutData.setCustomAuthorText("please use http://sourceforge.net/projects/klcddimmer to report bugs",
  86. "please use <a href=http://sourceforge.net/projects/klcddimmer>http://sourceforge.net/projects/klcddimmer</a> to report bugs");
  87. TDEAboutApplication about(&aboutData, this, 0);
  88. about.setProgramLogo( TDEGlobal::instance()->iconLoader()->iconPath( "klcddimmer", -TDEIcon::SizeLarge ) );
  89. about.exec();
  90. }
  91. void klcddimmer::help()
  92. {
  93. KMessageBox::information(0, i18n("This is a help box"));
  94. }
  95. void klcddimmer::preferences()
  96. {
  97. TDEConfigDialog dialog( this, "settings", Preferences::self() );
  98. ProgPreferences *preferences = new ProgPreferences(0, "Program");
  99. dialog.addPage(preferences, i18n("Program"), "wizard");
  100. if (dialog.exec())
  101. {
  102. chooser->updateSlider();
  103. }
  104. }
  105. /*
  106. int klcddimmer::widthForHeight(int height) const
  107. {
  108. return klcddimmerView->width();
  109. }
  110. int klcddimmer::heightForWidth(int width) const
  111. {
  112. return klcddimmerView->height();
  113. }
  114. */
  115. int klcddimmer::widthForHeight( int height ) const
  116. {
  117. // kdDebug() << "icon sizeHint: " << klcddimmerView->brightnessIcon->sizeHint() << endl;
  118. // kdDebug() << "text sizeHint: " << klcddimmerView->brightnessLevel->sizeHint() << endl;
  119. return height;
  120. }
  121. int klcddimmer::heightForWidth( int width ) const
  122. {
  123. // kdDebug() << "icon sizeHint: " << klcddimmerView->brightnessIcon->sizeHint() << endl;
  124. // kdDebug() << "text sizeHint: " << klcddimmerView->brightnessLevel->sizeHint() << endl;
  125. return width;
  126. }
  127. void klcddimmer::resizeEvent(TQResizeEvent *e)
  128. {
  129. klcddimmerView->resize(this->width(),this->height());
  130. }
  131. void klcddimmer::initContextMenu()
  132. {
  133. mContextMenu = new TDEPopupMenu(this);
  134. //mContextMenu->insertItem(SmallIcon("reload"), i18n("&Update Now"),
  135. // this, SLOT(slotUpdateNow()), 0, -1, 2);
  136. mContextMenu->insertSeparator();
  137. mContextMenu->insertItem(SmallIcon("klcddimmer"), i18n("&About KLcdDimmer"), this, SLOT(about()));
  138. mContextMenu->insertItem(SmallIcon("configure"),
  139. i18n("&Configure KLcdDimmer..."), this, SLOT(preferences()));
  140. setCustomMenu(mContextMenu);
  141. }
  142. void klcddimmer::mousePressEvent(TQMouseEvent *e)
  143. {
  144. if ( e->button() == LeftButton )
  145. {
  146. if (!mBrightnessChooserFrame->isShown()) {
  147. mBrightnessChooserFrame->popup(e->globalPos());
  148. }
  149. }
  150. else if ( e->button() != RightButton )
  151. {
  152. KPanelApplet::mousePressEvent( e );
  153. return;
  154. }
  155. else // must be right button
  156. {
  157. mContextMenu->exec(e->globalPos());
  158. }
  159. }
  160. void klcddimmer::valueUpdate()
  161. {
  162. kdDebug() << "updated value: " << chooser->getValue() << endl;
  163. klcddimmerView->setBrightnessLevel(chooser->getValue());
  164. }
  165. extern "C"
  166. {
  167. KPanelApplet* init( TQWidget *parent, const TQString& configFile)
  168. {
  169. TDEGlobal::locale()->insertCatalogue("klcddimmer");
  170. return new klcddimmer(configFile, KPanelApplet::Normal,
  171. KPanelApplet::About | KPanelApplet::Help | KPanelApplet::Preferences,
  172. parent, "klcddimmer");
  173. }
  174. }
  175. #include "klcddimmer.moc"