00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <QPoint>
00023 #include <QFont>
00024 #include <QTimer>
00025
00026
00027 #include <klocale.h>
00028 #include <kmessagebox.h>
00029 #include <kdebug.h>
00030 #include <kstandarddirs.h>
00031
00032
00033 #include "gameview.h"
00034 #include "thememanager.h"
00035 #include "lskatglobal.h"
00036
00037
00038
00039 GameView::GameView(QSize size, int advancePeriod, QGraphicsScene* scene, ThemeManager* theme, QWidget* parent)
00040 : QGraphicsView(scene, parent)
00041 {
00042
00043 mTheme = theme;
00044
00045
00046 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00047 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00048
00049
00050 setCacheMode(QGraphicsView::CacheBackground);
00051
00052
00053
00054 QTimer *timer = new QTimer(this);
00055 connect(timer, SIGNAL(timeout()), this, SLOT(updateAndAdvance()));
00056 timer->start(advancePeriod);
00057
00058
00059
00060 resize(size);
00061 scene->setSceneRect(0, 0, this->width(), this->height());
00062 adjustSize();
00063
00064
00065 setInteractive(true);
00066
00067
00068 mTheme->rescale(this->width());
00069 }
00070
00071
00072
00073 void GameView::updateAndAdvance()
00074 {
00075 scene()->advance();
00076
00077
00078
00079
00080 }
00081
00082
00083
00084
00085 void GameView::resizeEvent(QResizeEvent* e)
00086 {
00087 if (global_debug > 2) kDebug() <<"RESIZE EVENT " << e->size() << endl;
00088
00089
00090 if (scene())
00091 {
00092 scene()->setSceneRect(0,0, e->size().width(), e->size().height());
00093 }
00094
00095
00096 QSizeF size = QSizeF(e->size());
00097
00098 double aspect = size.width() / size.height();
00099 if (global_debug > 2) kDebug() << "Aspect=" << aspect << " theme aspect="<< mTheme->aspectRatio() << endl;
00100 if (aspect > mTheme->aspectRatio()) mTheme->rescale(int(e->size().height()*mTheme->aspectRatio()));
00101 else mTheme->rescale(int(e->size().width()));
00102 }
00103
00104
00105
00106 void GameView::paintEvent(QPaintEvent* event)
00107 {
00108 QPaintEvent* newEvent = new QPaintEvent(event->region().boundingRect());
00109 QGraphicsView::paintEvent(newEvent);
00110 delete newEvent;
00111 }
00112
00113
00114
00115 void GameView::mousePressEvent(QMouseEvent *ev)
00116 {
00117 if (ev->button() != Qt::LeftButton) return ;
00118
00119 QPointF point = ev->pos();
00120 emit signalLeftMousePress(point.toPoint());
00121 }
00122
00123
00124 #include "gameview.moc"