• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

panel_decorator.cpp

Go to the documentation of this file.
00001 /*
00002   Copyright 2008 Google Inc.
00003 
00004   Licensed under the Apache License, Version 2.0 (the "License");
00005   you may not use this file except in compliance with the License.
00006   You may obtain a copy of the License at
00007 
00008        http://www.apache.org/licenses/LICENSE-2.0
00009 
00010   Unless required by applicable law or agreed to in writing, software
00011   distributed under the License is distributed on an "AS IS" BASIS,
00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013   See the License for the specific language governing permissions and
00014   limitations under the License.
00015 */
00016 
00017 #include <QtGui/QMessageBox>
00018 
00019 #include <ggadget/gadget_consts.h>
00020 #include <ggadget/gadget.h>
00021 #include <ggadget/messages.h>
00022 #include <ggadget/menu_interface.h>
00023 #include <ggadget/decorated_view_host.h>
00024 #include <ggadget/qt/qt_view_widget.h>
00025 
00026 #include <Plasma/Applet>
00027 #include "panel_decorator.h"
00028 
00029 namespace ggadget {
00030 
00031 class PanelDecorator::Private {
00032  public:
00033   Private(GadgetInfo *info)
00034       : owner_(NULL), info_(info), minimized_width_(0), vertical_(true) {}
00035 
00036   void onAddDecoratorMenuItems(MenuInterface *menu) {
00037     int priority = MenuInterface::MENU_ITEM_PRI_DECORATOR;
00038     owner_->AddCollapseExpandMenuItem(menu);
00039     if (owner_->IsMinimized()) {
00040       menu->AddItem(i18n("Show Icon").toUtf8().data(),
00041                     owner_->IsMinimizedIconVisible() ?
00042                     MenuInterface::MENU_ITEM_FLAG_CHECKED:0,
00043                     0,
00044                     NewSlot(this, &Private::showIcon), priority);
00045       menu->AddItem(i18n("Show Caption").toUtf8().data(),
00046                     owner_->IsMinimizedCaptionVisible() ?
00047                     MenuInterface::MENU_ITEM_FLAG_CHECKED:0,
00048                     0,
00049                     NewSlot(this, &Private::showCaption), priority);
00050     }
00051 
00052 #ifndef NDEBUG
00053     menu->AddItem(
00054         "Debug", 0, 0,
00055         NewSlot(this, &Private::showDebugInfo), priority);
00056 #endif
00057   }
00058 
00059 #ifndef NDEBUG
00060   void showDebugInfo(const char*) {
00061     QString msg = "Applet size:(%1, %2)\n"
00062                   "Widget size:(%3, %4)\n"
00063                   "View size:(%5, %6)\n"
00064                   "Aspect:(%7)";
00065     qt::QtViewWidget *widget = static_cast<qt::QtViewWidget*>(
00066         info_->main_view_host->GetNativeWidget());
00067     ViewInterface *view = info_->main_view_host->GetViewDecorator();
00068     QMessageBox::information(NULL,
00069                              "Debug",
00070                              msg.arg(info_->applet->size().width())
00071                              .arg(info_->applet->size().height())
00072                              .arg(widget->size().width())
00073                              .arg(widget->size().height())
00074                              .arg(view->GetWidth())
00075                              .arg(view->GetHeight())
00076                              .arg(info_->applet->aspectRatioMode()));
00077   }
00078 #endif
00079 
00080   void showIcon(const char*) {
00081     bool caption = owner_->IsMinimizedCaptionVisible();
00082     owner_->SetMinimizedIconVisible(!owner_->IsMinimizedIconVisible());
00083     if (caption != owner_->IsMinimizedCaptionVisible())
00084       updateIconizeStatus();
00085   }
00086 
00087   void showCaption(const char*) {
00088     owner_->SetMinimizedCaptionVisible(!owner_->IsMinimizedCaptionVisible());
00089     updateIconizeStatus();
00090   }
00091 
00092   void updateIconizeStatus() {
00093     if (vertical_ || !owner_->IsMinimized()) return;
00094     if (!owner_->IsMinimizedCaptionVisible()) {
00095       minimized_width_ = owner_->GetWidth();
00096       owner_->SetWidth(38);
00097       owner_->SetResizeBorderVisible(0);
00098     } else {
00099       owner_->SetWidth(minimized_width_);
00100       owner_->SetResizeBorderVisible(BORDER_RIGHT);
00101     }
00102   }
00103 
00104   void loadMinimizedWidth() {
00105     DLOG("LoadMinimizedWidth:");
00106     Variant width = owner_->GetOption("minimized_width");
00107     if (width.type() == Variant::TYPE_DOUBLE) {
00108       minimized_width_ = VariantValue<double>()(width);
00109       DLOG("\t%f", VariantValue<double>()(width));
00110     }
00111     updateIconizeStatus();
00112   }
00113   PanelDecorator *owner_;
00114   GadgetInfo *info_;
00115   double minimized_width_;
00116   bool vertical_;
00117 };
00118 
00119 PanelDecorator::PanelDecorator(PlasmaViewHost *host)
00120     : DockedMainViewDecorator(host), d(new Private(host->getInfo())) {
00121   SetButtonVisible(MainViewDecoratorBase::POP_IN_OUT_BUTTON, false);
00122   SetButtonVisible(MainViewDecoratorBase::MENU_BUTTON, false);
00123   SetButtonVisible(MainViewDecoratorBase::CLOSE_BUTTON, false);
00124   SetOptionPrefix("plasma_panel");
00125   d->owner_ = this;
00126 }
00127 
00128 PanelDecorator::~PanelDecorator() {
00129   delete d;
00130 }
00131 
00132 void PanelDecorator::OnAddDecoratorMenuItems(MenuInterface *menu) {
00133   d->onAddDecoratorMenuItems(menu);
00134 }
00135 
00136 void PanelDecorator::SetSize(double width, double height) {
00137   DockedMainViewDecorator::SetSize(width, height);
00138   if (IsMinimized() && IsMinimizedCaptionVisible()) {
00139     SetOption("minimized_width", Variant(GetWidth()));
00140     DLOG("SaveMinimizedWidth:%f", GetWidth());
00141   }
00142 }
00143 
00144 void PanelDecorator::SetResizable(ViewInterface::ResizableMode resizable) {
00145   View::SetResizable(RESIZABLE_FALSE);
00146 }
00147 
00148 /*void PanelDecorator::GetClientExtents(double *width, double *height) const {
00149   MainViewDecoratorBase::GetClientExtents(width, height);
00150   if (IsMinimized()) {
00151     if (!IsMinimizedCaptionVisible())
00152       *width = 38;
00153     else
00154       *width = d->minimized_width_;
00155   }
00156 }*/
00157 
00158 void PanelDecorator::OnChildViewChanged() {
00159   DockedMainViewDecorator::OnChildViewChanged();
00160   // this methods is called not only when a main view assigned to this
00161   // decorator for the first time, but also when a main view popped in/out.
00162   // We only want to init minimized_width_ the first time
00163   if (d->minimized_width_ == 0)
00164     d->loadMinimizedWidth();
00165 }
00166 
00167 bool PanelDecorator::ShowDecoratedView(bool modal, int flags,
00168                        Slot1<bool, int> *feedback_handler) {
00169   d->info_->applet->setMaximumSize(QSizeF());
00170   if (d->vertical_)
00171     d->info_->applet->setMaximumHeight(GetHeight());
00172   else
00173     d->info_->applet->setMaximumWidth(GetWidth());
00174   return DockedMainViewDecorator::ShowDecoratedView(
00175       modal, flags, feedback_handler);
00176 }
00177 
00178 void PanelDecorator::setVertical() {
00179   SetAllowYMargin(false);
00180   SetAllowXMargin(true);
00181 
00182   // Gadget on vertical panel is not minimized by default
00183   Variant vertical_minimized = GetOption("vertical_minimized");
00184   if (vertical_minimized.type() != Variant::TYPE_BOOL ||
00185       !VariantValue<bool>()(vertical_minimized)) {
00186     SetMinimized(false);
00187   } else {
00188     SetMinimized(true);
00189   }
00190 
00191   SetResizeBorderVisible(IsMinimized() ? 0 : BORDER_BOTTOM);
00192   d->vertical_ = true;
00193 }
00194 
00195 void PanelDecorator::setHorizontal() {
00196   SetAllowYMargin(true);
00197   SetAllowXMargin(false);
00198 
00199   // Gadget on horizontal panel is minimized by default
00200   Variant horizontal_minimized = GetOption("horizontal_minimized");
00201   if (horizontal_minimized.type() != Variant::TYPE_BOOL ||
00202       VariantValue<bool>()(horizontal_minimized)) {
00203     SetMinimized(true);
00204   } else {
00205     SetMinimized(false);
00206   }
00207 
00208   SetResizeBorderVisible((!IsMinimized() || IsMinimizedCaptionVisible()) ?
00209                          0 : BORDER_RIGHT);
00210   d->vertical_ = false;
00211 }
00212 
00213 } // namespace ggadget

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal