Presenter::Presenter(IView *view) { this->view = view; this->game = new GameController(); QObject* qview = dynamic_cast<QObject*>(view); connect(qview, SIGNAL(onNewGame()), this->game, SLOT(onNewGame())); connect(qview, SIGNAL(onPause()), this->game, SLOT(onPause())); connect(qview, SIGNAL(onRotate()), this->game, SLOT(onRotate())); connect(qview, SIGNAL(onToLeft()), this->game, SLOT(onMoveLeft())); connect(qview, SIGNAL(onToRight()), this->game, SLOT(onMoveRight())); connect(qview, SIGNAL(onSpeedup()), this->game, SLOT(onSpeedup())); connect(qview, SIGNAL(onEndGame()), this->game, SLOT(onEnd())); connect(game, SIGNAL(onStateChanged()), this, SLOT(StateChange())); connect(game, SIGNAL(onGameEnd()), this, SLOT(EndGame())); // instead of speedup connect(qview, SIGNAL(onMakeMove()), this->game, SLOT(onMove())); }
void KUnitItem::slotMouseMove(QGraphicsSceneMouseEvent *event) { if (myMode == MouseMode_RESIZE) { QPointF curPoint(event->scenePos()); QPointF curPointItem = this->mapFromScene(curPoint); bool flagx = lastPoint.x() > oppositePos.x(); bool flagx1 = curPointItem.x() > oppositePos.x(); bool flagy = lastPoint.y() > oppositePos.y(); bool flagy1 = curPointItem.y() > oppositePos.y(); qreal dist = 0; QRectF rectf; rectf.setRect(m_frame.x() , m_frame.y() , m_frame.width() , m_frame.height()); KResizeFocus::PosInHost pos = curResizeFocus->getInHost(); if (pos == KResizeFocus::NORTH_MIDDLE) { QPointF br = dashRect->rect().bottomRight(); dist = Util::GetPointDistLine(oppositePos,br,curPointItem); if (dist < 20 || flagy != flagy1) { if (flagy) { curPointItem.setY(oppositePos.y() + 20); } else { curPointItem.setY(oppositePos.y() - 20); } dist = 20; } rectf.setY(curPointItem.y()); rectf.setHeight(dist); } else if(pos == KResizeFocus::SOUTH_MIDDLE) { QPointF br = dashRect->rect().topRight(); dist = Util::GetPointDistLine(oppositePos,br,curPointItem); if (dist < 20 || flagy != flagy1) { if (flagy) { curPointItem.setY(oppositePos.y() + 20); } else { curPointItem.setY(oppositePos.y() - 20); } dist = 20; } rectf.setHeight(dist); } else if(pos == KResizeFocus::EAST_MIDDLE) { QPointF br = dashRect->rect().bottomLeft(); dist = Util::GetPointDistLine(oppositePos,br,curPointItem); if (dist < 20 || flagx != flagx1) { if (flagx) { curPointItem.setX(oppositePos.x() + 20); } else { curPointItem.setX(oppositePos.x() - 20); } dist = 20; } rectf.setWidth(dist); } else if(pos == KResizeFocus::WEST_MIDDLE) { QPointF br = dashRect->rect().bottomRight(); dist = Util::GetPointDistLine(oppositePos,br,curPointItem); if (dist < 20 || flagx != flagx1) { if (flagx) { curPointItem.setX(oppositePos.x() + 20); } else { curPointItem.setX(oppositePos.x() - 20); } dist = 20; } rectf.setX(curPointItem.x()); rectf.setWidth(dist); } else if(pos == KResizeFocus::NORTH_WEST) { QPointF topRight = dashRect->rect().topRight(); QPointF bottomLeft = dashRect->rect().bottomLeft(); qreal distx = Util::GetPointDistLine(oppositePos,topRight,curPointItem); qreal disty = Util::GetPointDistLine(oppositePos,bottomLeft,curPointItem); if (distx < 20 || flagx != flagx1) { if (flagx) { curPointItem.setX(oppositePos.x() + 20); } else { curPointItem.setX(oppositePos.x() - 20); } distx = 20; } if (disty < 20 || flagy != flagy1) { if (flagy) { curPointItem.setY(oppositePos.y() + 20); } else { curPointItem.setY(oppositePos.y() - 20); } disty = 20; } rectf.setTopLeft(curPointItem); } else if(pos == KResizeFocus::NORTH_EAST) { QPointF topLeft = dashRect->rect().topLeft(); QPointF bottomRight = dashRect->rect().bottomRight(); qreal distx = Util::GetPointDistLine(oppositePos,topLeft,curPointItem); qreal disty = Util::GetPointDistLine(oppositePos,bottomRight,curPointItem); if (distx < 20 || flagx != flagx1) { if (flagx) { curPointItem.setX(oppositePos.x() + 20); } else { curPointItem.setX(oppositePos.x() - 20); } distx = 20; } if (disty < 20 || flagy != flagy1) { if (flagy) { curPointItem.setY(oppositePos.y() + 20); } else { curPointItem.setY(oppositePos.y() - 20); } disty = 20; } rectf.setTopRight(curPointItem); } else if(pos == KResizeFocus::SOUTH_EAST) { QPointF topRight = dashRect->rect().topRight(); QPointF bottomLeft = dashRect->rect().bottomLeft(); qreal disty = Util::GetPointDistLine(oppositePos,topRight,curPointItem); qreal distx = Util::GetPointDistLine(oppositePos,bottomLeft,curPointItem); if (distx < 20 || flagx != flagx1) { if (flagx) { curPointItem.setX(oppositePos.x() + 20); } else { curPointItem.setX(oppositePos.x() - 20); } distx = 20; } if (disty < 20 || flagy != flagy1) { if (flagy) { curPointItem.setY(oppositePos.y() + 20); } else { curPointItem.setY(oppositePos.y() - 20); } disty = 20; } rectf.setBottomRight(curPointItem); } else if(pos == KResizeFocus::SOUTH_WEST) { QPointF topLeft = dashRect->rect().topLeft(); QPointF bottomRight = dashRect->rect().bottomRight(); qreal disty = Util::GetPointDistLine(oppositePos,topLeft,curPointItem); qreal distx = Util::GetPointDistLine(oppositePos,bottomRight,curPointItem); if (distx < 20 || flagx != flagx1) { if (flagx) { curPointItem.setX(oppositePos.x() + 20); } else { curPointItem.setX(oppositePos.x() - 20); } distx = 20; } if (disty < 20 || flagy != flagy1) { if (flagy) { curPointItem.setY(oppositePos.y() + 20); } else { curPointItem.setY(oppositePos.y() - 20); } disty = 20; } rectf.setBottomLeft(curPointItem); } dashRect->setRect(rectf); } else if(myMode == MouseMode_ROTATE) { QPointF curPos = event->scenePos(); QPointF cpos = this->mapToScene(frame().center()); // qDebug()<<cpos; qreal angleLast = Util::ComputeAngle(mLastRotatePoint, cpos); qreal angleCur = Util::ComputeAngle(curPos, cpos); qreal angle = angleCur - angleLast; setAngle(angle); mLastRotatePoint = curPos; onRotate(); } else if(myMode == MouseMode_MOVE) { onMoving(); } else { QGraphicsItem::mouseMoveEvent(event); } }
kd::kd() { ready_to_die = false; /* Creating top-right area (Line input and button) */ item_input = new QLineEdit; item_button = new QPushButton(tr("Add")); item_button->setDefault(true); bottom_h_layout = new QHBoxLayout; bottom_h_layout->addWidget(item_input); bottom_h_layout->addWidget(item_button); items_tree = new QTreeWidget; items_tree->setColumnCount(2); items_tree->setHeaderLabels(QStringList() << tr("Goods") << tr("Price") ); added_items = new QTextBrowser; central_widget = new QSplitter; central_widget->addWidget(items_tree); central_widget->addWidget(added_items); central_widget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); /* Create right side (top area, suggest label and list of added items) */ item_suggest = new QLabel; right_v_layout = new QVBoxLayout; right_v_layout->addWidget(item_suggest); right_v_layout->addWidget(central_widget); right_v_layout->addLayout(bottom_h_layout); right_widget = new QWidget; right_widget->setLayout(right_v_layout); setCentralWidget( right_widget ); item_input->setFocus(); /* Restore window settings */ app_settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "Stinky", "Celtic House Menu"); app_settings->beginGroup("MainWindow"); resize(app_settings->value("Size", QSize(400, 400)).toSize()); move(app_settings->value("Position", QPoint(200, 200)).toPoint()); central_widget->restoreState( app_settings->value("Splitter").toByteArray() ); app_settings->endGroup(); menu_file = new QSettings(QSettings::IniFormat, QSettings::SystemScope, "Stinky", "Celtic House Menu"); qDebug() << "Menu in " << menu_file->fileName(); cards = new QSettings(QSettings::IniFormat, QSettings::SystemScope, "Stinky", "cards"); qDebug() << "Menu in " << cards->fileName(); // Cards debug QStringList ckeys = cards->allKeys(); for(int i = 0; i < ckeys.size(); ++i) { qDebug() << "Value:" << ckeys.at(i) << " = " << QString::fromUtf8( cards->value( ckeys.at(i), "Ы" ).toString().toAscii() ); } QString logs_dir = menu_file->value("Settings/LogsDir", "").toString(); if(logs_dir.length() > 1) logger = new Logger(logs_dir); else logger = new Logger; QString errmsg; if(logger->getError(errmsg) != QFile::NoError) { QMessageBox msgBox; msgBox.setIcon(QMessageBox::Critical); msgBox.setText(tr("Can not open log file.")); msgBox.setInformativeText(errmsg); msgBox.exec(); ready_to_die = true; return; } // readMenu QString tmpstr = QString("root"); readMenu(*items_tree->invisibleRootItem(), tmpstr, tmpstr); tmpstr = QString("launcher"); QTreeWidgetItem *tmpitem = new QTreeWidgetItem; QBrush *red = new QBrush(Qt::red); tmpitem->setForeground(0, *red); readMenu(*tmpitem, tmpstr, tmpstr); tmpitem->setText( 2, "/" ); items_tree->addTopLevelItem(tmpitem); /*End read menu*/ items_tree->expandAll(); items_tree->resizeColumnToContents(1); items_tree->resizeColumnToContents(0); items_tree->collapseAll(); totalprice = 0; QAction* a_quit = new QAction(this); QAction* a_rotate = new QAction(this); a_quit->setText( "Quit" ); a_rotate->setText( "Rotate" ); QMenu *filemenu = menuBar()->addMenu( "File" ); filemenu->addAction( a_quit ); filemenu->addAction( a_rotate ); //status_bar = new QStatusBar(central_widget); //statusBar(); updateCurrentTotal(); connect(a_quit, SIGNAL(triggered()), SLOT(close()) ); connect(a_rotate, SIGNAL(triggered()), SLOT(onRotate()) ); connect(item_button, SIGNAL(clicked()), SLOT(onAddButtonPress()) ); connect(item_input, SIGNAL(returnPressed()), SLOT(onAddButtonPress()) ); connect(item_input, SIGNAL(textChanged(QString)), SLOT(onTextChange(QString)) ); connect(items_tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), SLOT(onItemClick(QTreeWidgetItem*,int)) ); connect(items_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), SLOT(onDoubleClick(QTreeWidgetItem*,int)) ); }