|  | Home · All Namespaces · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# dialog.cpp Example File
dialogs/sipdialog/dialog.cpp

     /****************************************************************************
     **
     ** Copyright (C) 2004-$THISYEAR$ $TROLLTECH$. All rights reserved.
     **
     ** This file is part of the $MODULE$ of the Qt Toolkit.
     **
     ** $TROLLTECH_DUAL_LICENSE$
     **
     ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
     ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     **
     ****************************************************************************/

     #include <QtGui>

     #include "dialog.h"

     Dialog::Dialog()
     {
         desktopGeometry = QApplication::desktop()->availableGeometry(0);

         setWindowTitle(tr("SIP Dialog Example"));
         QScrollArea *scrollArea = new QScrollArea(this);
         QGroupBox *groupBox = new QGroupBox(scrollArea);
         groupBox->setTitle(tr("SIP Dialog Example"));
         QGridLayout *gridLayout = new QGridLayout(groupBox);
         groupBox->setLayout(gridLayout);

         QLineEdit* lineEdit = new QLineEdit(groupBox);
         lineEdit->setText(tr("Open and close the SIP"));
         lineEdit->setMinimumWidth(220);

         QLabel* label = new QLabel(groupBox);
         label->setText(tr("This dialog resizes if the SIP is opened"));
         label->setMinimumWidth(220);

         QPushButton* button = new QPushButton(groupBox);
         button->setText(tr("Close Dialog"));
         button->setMinimumWidth(220);

         if (desktopGeometry.height() < 400)
             gridLayout->setVerticalSpacing(80);
         else
             gridLayout->setVerticalSpacing(150);

         gridLayout->addWidget(label);
         gridLayout->addWidget(lineEdit);
         gridLayout->addWidget(button);

         scrollArea->setWidget(groupBox);
         QHBoxLayout* layout = new QHBoxLayout();
         layout->addWidget(scrollArea);
         setLayout(layout);
         scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

         connect(button, SIGNAL(pressed()),
             qApp, SLOT(closeAllWindows()));
         connect(QApplication::desktop(), SIGNAL(workAreaResized(int)),
             this, SLOT(desktopResized(int)));
     }

     void Dialog::desktopResized(int screen)
     {
         if (screen != 0)
             return;
         reactToSIP();
     }

     void Dialog::reactToSIP()
     {
         QRect availableGeometry = QApplication::desktop()->availableGeometry(0);

         if (desktopGeometry.width() == availableGeometry.width()) {
             if (desktopGeometry.height() > availableGeometry.height()) {
                 setWindowState(windowState() & ~Qt::WindowMaximized);
                 setGeometry(availableGeometry);
             } else {
                 setWindowState(windowState() | Qt::WindowMaximized);
             }
         }
         desktopGeometry = availableGeometry;
     }