Back to index

fet  5.18.0
centerwidgetonscreen.cpp
Go to the documentation of this file.
00001 /*
00002 File centerwidgetonscreen.cpp
00003 */
00004 
00005 /***************************************************************************
00006                           centerwidgetonscreen.cpp  -  description
00007                              -------------------
00008     begin                : 13 July 2008
00009     copyright            : (C) 2008 by Lalescu Liviu
00010     email                : Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
00011  ***************************************************************************/
00012 
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This program is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU General Public License as published by  *
00017  *   the Free Software Foundation; either version 2 of the License, or     *
00018  *   (at your option) any later version.                                   *
00019  *                                                                         *
00020  ***************************************************************************/
00021 
00022 #include "centerwidgetonscreen.h"
00023 
00024 #include "fetmainform.h"
00025 
00026 #include "rules.h"
00027 #include "timetable.h"
00028 
00029 #include <QWidget>
00030 #include <QApplication>
00031 #include <QDesktopWidget>
00032 #include <QRect>
00033 #include <QSize>
00034 #include <QPoint>
00035 
00036 #include <QSettings>
00037 
00038 #include <QObject>
00039 #include <QMetaObject>
00040 
00041 #include <QString>
00042 
00043 #include <QHeaderView>
00044 #include <QTableWidget>
00045 #include <QTableWidgetItem>
00046 #include <QAbstractItemView>
00047 
00048 extern const QString COMPANY;
00049 extern const QString PROGRAM;
00050 
00051 extern FetMainForm* pFetMainForm;
00052 
00053 extern Timetable gt;
00054 
00055 void centerWidgetOnScreen(QWidget* widget)
00056 {
00057        Q_UNUSED(widget);
00058 
00059        //widget->setWindowFlags(widget->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowMinMaxButtonsHint);
00060        
00061 /*     QRect frect=widget->frameGeometry();
00062        frect.moveCenter(QApplication::desktop()->availableGeometry(widget).center());
00063        widget->move(frect.topLeft());*/
00064 }
00065 
00066 void forceCenterWidgetOnScreen(QWidget* widget)
00067 {
00068        //widget->setWindowFlags(widget->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowMinMaxButtonsHint);
00069        
00070        QRect frect=widget->frameGeometry();
00071        frect.moveCenter(QApplication::desktop()->availableGeometry(widget).center());
00072        widget->move(frect.topLeft());
00073 }
00074 
00075 /*void centerWidgetOnParent(QWidget* widget, QWidget* parent)
00076 {
00077        //widget->setWindowFlags(widget->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowMinMaxButtonsHint);
00078        
00079        assert(parent!=NULL);
00080        
00081        QRect frect=widget->geometry();
00082        frect.moveCenter(parent->geometry().center());
00083        widget->move(frect.topLeft());
00084 }*/
00085 
00086 int maxScreenWidth(QWidget* widget)
00087 {
00088        QRect rect = QApplication::desktop()->availableGeometry(widget);
00089 
00090        return rect.width();
00091 }
00092 
00093 int maxRecommendedWidth(QWidget* widget)
00094 {
00095        int d=maxScreenWidth(widget);
00096        
00097        if(d<800)
00098               d=800;
00099               
00100        //if(d>1000)
00101        //     d=1000;
00102        
00103        return d;
00104 }
00105 
00106 void saveFETDialogGeometry(QWidget* widget, const QString& alternativeName)
00107 {
00108        QSettings settings(COMPANY, PROGRAM);
00109        QString name=QString(widget->metaObject()->className());
00110        if(!alternativeName.isEmpty())
00111               name=alternativeName;
00112        
00113        QRect rect=widget->geometry();
00114        settings.setValue(name+QString("/geometry"), rect);
00115 }
00116 
00117 void restoreFETDialogGeometry(QWidget* widget, const QString& alternativeName)
00118 {
00119        QSettings settings(COMPANY, PROGRAM);
00120        QString name=QString(widget->metaObject()->className());
00121        if(!alternativeName.isEmpty())
00122               name=alternativeName;
00123        if(settings.contains(name+QString("/geometry"))){
00124               QRect rect=settings.value(name+QString("/geometry")).toRect();
00125               if(rect.isValid())
00126                      widget->setGeometry(rect);
00127        }
00128 }
00129 
00130 void setParentAndOtherThings(QWidget* widget, QWidget* parent)
00131 {
00132        Q_UNUSED(widget);
00133        Q_UNUSED(parent);
00134 
00135 /*     if(!widget->parentWidget()){
00136               widget->setParent(parent, Qt::Dialog);
00137        
00138               QRect rect=widget->geometry();
00139               rect.translate(widget->geometry().x() - widget->frameGeometry().x(), widget->geometry().y() - widget->frameGeometry().y());
00140               widget->setGeometry(rect);
00141        }*/
00142 }
00143 
00144 void setStretchAvailabilityTableNicely(QTableWidget* notAllowedTimesTable)
00145 {
00146        notAllowedTimesTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
00147        int q=notAllowedTimesTable->horizontalHeader()->defaultSectionSize();
00148        notAllowedTimesTable->horizontalHeader()->setMinimumSectionSize(q);
00149 
00150        notAllowedTimesTable->verticalHeader()->setResizeMode(QHeaderView::Stretch);
00151        q=-1;
00152        for(int i=0; i<notAllowedTimesTable->verticalHeader()->count(); i++)
00153               if(q<notAllowedTimesTable->verticalHeader()->sectionSizeHint(i))
00154                      q=notAllowedTimesTable->verticalHeader()->sectionSizeHint(i);
00155        notAllowedTimesTable->verticalHeader()->setMinimumSectionSize(q);
00156        
00157        //2011-09-23
00158        for(int i=0; i<notAllowedTimesTable->rowCount(); i++){
00159               for(int j=0; j<notAllowedTimesTable->columnCount(); j++){
00160                      QFont font=notAllowedTimesTable->item(i,j)->font();
00161                      font.setBold(true);
00162                      notAllowedTimesTable->item(i,j)->setFont(font);
00163               }
00164        }
00165        notAllowedTimesTable->setCornerButtonEnabled(false);
00166 }
00167 
00168 void setRulesModifiedAndOtherThings(Rules* rules)
00169 {
00170        if(!rules->modified){
00171               rules->modified=true;
00172        
00173               if(rules==&gt.rules && pFetMainForm!=NULL)
00174                      if(!pFetMainForm->isWindowModified())
00175                             pFetMainForm->setWindowModified(true);
00176        }
00177 }
00178 
00179 void setRulesUnmodifiedAndOtherThings(Rules* rules)
00180 {
00181        if(rules->modified){
00182               rules->modified=false;
00183        
00184               if(rules==&gt.rules && pFetMainForm!=NULL)
00185                      if(pFetMainForm->isWindowModified())
00186                             pFetMainForm->setWindowModified(false);
00187        }
00188 }