From: Max Lapan Date: Sun, 14 Mar 2010 14:49:14 +0000 (+0300) Subject: Resize widget according to it's contents. X-Git-Tag: v0.1~39 X-Git-Url: http://vcs.maemo.org/git/?p=yandex-traffic;a=commitdiff_plain;h=238af37933e4590b629777c10f931ba6398be3f3 Resize widget according to it's contents. --- diff --git a/mainwidget.cpp b/mainwidget.cpp index 76fc3ed..1cbb934 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -10,13 +10,14 @@ MainWidget::MainWidget () : QWidget () { - setMinimumSize (300, 80); #ifdef Q_WS_MAEMO_5 setAttribute(Qt::WA_TranslucentBackground); #endif _light = new TrafficLight (this); _label = new QLabel (this); + _label->setAlignment (Qt::AlignHCenter | Qt::AlignVCenter); + _traffic = new Traffic; _regions = new RegionsTable; _settings = new Settings; @@ -28,6 +29,8 @@ MainWidget::MainWidget () _light->setVisible (_settings->check (Settings::C_Light)); + updateSize (); + connect (_traffic, SIGNAL (updated ()), SLOT (trafficUpdated ())); // every 5 minutes (TODO, make option) @@ -90,7 +93,8 @@ void MainWidget::trafficUpdated () } if (_settings->check (Settings::C_Hint)) { - data.append ("\n"); + if (!first) + data.append ("\n"); data.append (info.hint ()); } @@ -117,5 +121,25 @@ void MainWidget::settingsDialog () // Handle settings _light->setVisible (_settings->check (Settings::C_Light)); + updateSize (); trafficUpdated (); } + + +void MainWidget::updateSize () +{ + QSize minSize (0, 80); + + if (_settings->check (Settings::C_Light)) + minSize += QSize (80, 0); + if (_settings->check (Settings::C_Hint)) + minSize += QSize (270, 0); + else { + if (_settings->check (Settings::C_Time)) + minSize += QSize (75, 0); + if (_settings->check (Settings::C_Rank)) + minSize += QSize (75, 0); + } + + setFixedSize (minSize); +} diff --git a/mainwidget.hpp b/mainwidget.hpp index fe41022..ce894c6 100644 --- a/mainwidget.hpp +++ b/mainwidget.hpp @@ -33,6 +33,7 @@ protected: void timerEvent (QTimerEvent *event); void updateData (); + void updateSize (); protected slots: void trafficUpdated ();