MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), isLeftPressDown(false),
      scene(NULL), ui(new Ui::MainWindow), server(NULL), about_window(NULL),
      minButton(NULL), maxButton(NULL), normalButton(NULL), closeButton(NULL),
      versionInfomationReply(NULL), changeLogReply(NULL)
{
    ui->setupUi(this);
    setWindowTitle(tr("QSanguosha-Hegemony") + " " + Sanguosha->getVersion());
#ifdef Q_OS_WIN
    setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
#endif
    setAttribute(Qt::WA_TranslucentBackground);

    setMouseTracking(true);
    setMinimumWidth(800);
    setMinimumHeight(580);

    fetchUpdateInformation();

    connection_dialog = new ConnectionDialog(this);
    connect(ui->actionStart_Game, SIGNAL(triggered()), connection_dialog, SLOT(exec()));
    connect(connection_dialog, SIGNAL(accepted()), this, SLOT(startConnection()));

    config_dialog = new ConfigDialog(this);
    connect(ui->actionConfigure, SIGNAL(triggered()), config_dialog, SLOT(show()));
    connect(config_dialog, SIGNAL(bg_changed()), this, SLOT(changeBackground()));
    connect(config_dialog, SIGNAL(tableBg_changed()), this, SLOT(changeBackground()));

    connect(ui->actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
    connect(ui->actionAcknowledgement_2, SIGNAL(triggered()), this, SLOT(on_actionAcknowledgement_triggered()));

    StartScene *start_scene = new StartScene(this);

    QList<QAction *> actions;
    actions << ui->actionStart_Game
        << ui->actionStart_Server
        << ui->actionPC_Console_Start
        << ui->actionReplay
        << ui->actionConfigure
        << ui->actionGeneral_Overview
        << ui->actionCard_Overview
        << ui->actionAbout;

    foreach(QAction *action, actions)
        start_scene->addButton(action);

#if defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
    ui->menuSumMenu->setAttribute(Qt::WA_TranslucentBackground);
    ui->menuGame->setAttribute(Qt::WA_TranslucentBackground);
    ui->menuView->setAttribute(Qt::WA_TranslucentBackground);
    ui->menuOptions->setAttribute(Qt::WA_TranslucentBackground);
    ui->menuDIY->setAttribute(Qt::WA_TranslucentBackground);
    ui->menuCheat->setAttribute(Qt::WA_TranslucentBackground);
    ui->menuHelp->setAttribute(Qt::WA_TranslucentBackground);
#endif

    view = new FitView(scene);

    setCentralWidget(view);
    restoreFromConfig();

    roundCorners();

    BackLoader::preload();
    gotoScene(start_scene);

    addAction(ui->actionFullscreen);

#if defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
    menu = new QPushButton(this);
    menu->setMenu(ui->menuSumMenu);
    menu->setProperty("control", true);
    StyleHelper::getInstance()->setIcon(menu, QChar(0xf0c9), 15);
    menu->setToolTip(tr("<font color=%1>Config</font>").arg(Config.SkillDescriptionInToolTipColor.name()));
#endif

#if defined(Q_OS_WIN)
    minButton = new QPushButton(this);
    minButton->setProperty("control", true);

    maxButton = new QPushButton(this);
    maxButton->setProperty("bold", true);
    maxButton->setProperty("control", true);

    normalButton = new QPushButton(this);
    normalButton->setProperty("bold", true);
    normalButton->setProperty("control", true);

    closeButton= new QPushButton(this);
    closeButton->setObjectName("closeButton");
    closeButton->setProperty("control", true);

    StyleHelper::getInstance()->setIcon(minButton, QChar(0xf068), 15);
    StyleHelper::getInstance()->setIcon(maxButton, QChar(0xf106), 15);
    StyleHelper::getInstance()->setIcon(normalButton, QChar(0xf107), 15);
    StyleHelper::getInstance()->setIcon(closeButton, QChar(0xf00d), 15);

    minButton->setToolTip(tr("<font color=%1>Minimize</font>").arg(Config.SkillDescriptionInToolTipColor.name()));
    connect(minButton, SIGNAL(clicked()), this, SLOT(showMinimized()));
    maxButton->setToolTip(tr("<font color=%1>Maximize</font>").arg(Config.SkillDescriptionInToolTipColor.name()));
    connect(maxButton, SIGNAL(clicked()), this, SLOT(showMaximized()));
    normalButton->setToolTip(tr("<font color=%1>Restore downward</font>").arg(Config.SkillDescriptionInToolTipColor.name()));
    connect(normalButton, SIGNAL(clicked()), this, SLOT(showNormal()));
    closeButton->setToolTip(tr("<font color=%1>Close</font>").arg(Config.SkillDescriptionInToolTipColor.name()));
    connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));

    menuBar()->hide();
#elif defined(Q_OS_ANDROID)
    ui->menuSumMenu->removeAction(ui->menuView->menuAction());
#endif
    repaintButtons();

#ifndef Q_OS_ANDROID
    QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
    animation->setDuration(1000);
    animation->setStartValue(0);
    animation->setEndValue(1);
    animation->setEasingCurve(QEasingCurve::OutCurve);
    animation->start(QAbstractAnimation::DeleteWhenStopped);
#endif

    start_scene->showOrganization();

    systray = NULL;
}
AbstractConfig::AbstractConfig(AbstractContent * content, AbstractConfig_PARENT * parent)
    : AbstractConfig_TYPE(parent)
    , m_content(content)
    , m_commonUi(new Ui::AbstractConfig())
#if !defined(MOBILE_UI)
    , m_closeButton(0)
    , m_okButton(0)
#endif
    , m_frame(FrameFactory::defaultPanelFrame())
{
#if !defined(MOBILE_UI)
    // close button
    m_closeButton = new StyledButtonItem(tr(" x "), font(), this);//this, ":/data/button-close.png", ":/data/button-close-hovered.png", ":/data/button-close-pressed.png");
    connect(m_closeButton, SIGNAL(clicked()), this, SIGNAL(requestClose()));

    // WIDGET setup (populate contents and set base palette (only) to transparent)
    QWidget * widget = new QWidget();
    m_commonUi->setupUi(widget);
    QPalette pal;
    QColor oldColor = pal.window().color();
    pal.setBrush(QPalette::Window, Qt::transparent);
    widget->setPalette(pal);
    pal.setBrush(QPalette::Window, oldColor);
    m_commonUi->tab->setPalette(pal);
#else
    m_commonUi->setupUi(this);
#endif

    populateFrameList();

    // select the frame
    quint32 frameClass = m_content->frameClass();
    if (frameClass != Frame::NoFrame) {
        for (int i = 0; i < m_commonUi->framesList->count(); ++i) {
            QListWidgetItem * item = m_commonUi->framesList->item(i);
            if (item->data(Qt::UserRole).toUInt() == frameClass) {
                item->setSelected(true);
                break;
            }
        }
    }

    // read other properties
    m_commonUi->reflection->setChecked(m_content->mirrored());
    m_commonUi->contentLocked->setChecked(m_content->locked());
    m_commonUi->fixedPosition->setChecked(m_content->fixedPosition());
    m_commonUi->fixedRotation->setChecked(m_content->fixedRotation());
    m_commonUi->fixedPerspective->setChecked(m_content->fixedPerspective());

    connect(m_commonUi->front, SIGNAL(clicked()), m_content, SLOT(slotStackFront()));
    connect(m_commonUi->raise, SIGNAL(clicked()), m_content, SLOT(slotStackRaise()));
    connect(m_commonUi->lower, SIGNAL(clicked()), m_content, SLOT(slotStackLower()));
    connect(m_commonUi->back, SIGNAL(clicked()), m_content, SLOT(slotStackBack()));
    connect(m_commonUi->save, SIGNAL(clicked()), m_content, SLOT(slotSaveAs()));
    connect(m_commonUi->background, SIGNAL(clicked()), m_content, SIGNAL(requestBackgrounding()));
    connect(m_commonUi->del, SIGNAL(clicked()), m_content, SIGNAL(requestRemoval()));

    connect(m_commonUi->contentLocked, SIGNAL(stateChanged(int)), m_content, SLOT(slotSetLocked(int)));
    connect(m_commonUi->fixedPosition, SIGNAL(stateChanged(int)), m_content, SLOT(slotSetFixedPosition(int)));
    connect(m_commonUi->fixedRotation, SIGNAL(stateChanged(int)), m_content, SLOT(slotSetFixedRotation(int)));
    connect(m_commonUi->fixedPerspective, SIGNAL(stateChanged(int)), m_content, SLOT(slotSetFixedPerspective(int)));

    connect(m_commonUi->newFrame, SIGNAL(clicked()), this, SLOT(slotAddFrame()));
    connect(m_commonUi->removeFrame, SIGNAL(clicked()), this, SLOT(slotRemoveFrame()));
    connect(m_commonUi->lookApplyAll, SIGNAL(clicked()), this, SLOT(slotLookApplyAll()));
    connect(m_commonUi->framesList, SIGNAL(itemSelectionChanged()), this, SLOT(slotFrameSelectionChanged()));
    connect(m_commonUi->reflection, SIGNAL(toggled(bool)), this, SLOT(slotReflectionToggled(bool)));

    // ITEM setup
#if !defined(MOBILE_UI)
    setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
    setWidget(widget);
    static qreal s_propZBase = 99999;
    setZValue(s_propZBase++);
#endif

#if !defined(MOBILE_UI) && QT_VERSION >= 0x040600
    // fade in animation
    QPropertyAnimation * ani = new QPropertyAnimation(this, "opacity");
    ani->setEasingCurve(QEasingCurve::OutCubic);
    ani->setDuration(400);
    ani->setStartValue(0.0);
    ani->setEndValue(1.0);
    ani->start(QPropertyAnimation::DeleteWhenStopped);
#endif
}
Exemple #3
0
void FancyTabProxyStyle::drawControl(
    ControlElement element, const QStyleOption* option,
    QPainter* p, const QWidget* widget) const
{

    const QStyleOptionTab* v_opt = qstyleoption_cast<const QStyleOptionTab*>(option);

    if (element != CE_TabBarTab || !v_opt) {
        QProxyStyle::drawControl(element, option, p, widget);
        return;
    }

    const QRect rect = v_opt->rect;
    const bool selected = v_opt->state & State_Selected;
    const bool vertical_tabs = v_opt->shape == QTabBar::RoundedWest;
    const QString text = v_opt->text;

    if (selected) {
        //background
        p->save();
        QLinearGradient grad(rect.topLeft(), rect.topRight());
        grad.setColorAt(0, QColor(255, 255, 255, 140));
        grad.setColorAt(1, QColor(255, 255, 255, 210));
        p->fillRect(rect.adjusted(0, 0, 0, -1), grad);
        p->restore();

        //shadows
        p->setPen(QColor(0, 0, 0, 110));
        p->drawLine(rect.topLeft() + QPoint(1, -1), rect.topRight() - QPoint(0, 1));
        p->drawLine(rect.bottomLeft(), rect.bottomRight());
        p->setPen(QColor(0, 0, 0, 40));
        p->drawLine(rect.topLeft(), rect.bottomLeft());

        //highlights
        p->setPen(QColor(255, 255, 255, 50));
        p->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0, 2));
        p->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0, 1));
        p->setPen(QColor(255, 255, 255, 40));
        p->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight());
        p->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1));
        p->drawLine(rect.bottomLeft() + QPoint(0, -1), rect.bottomRight() - QPoint(0, 1));
    }

    QTransform m;
    if (vertical_tabs) {
        m = QTransform::fromTranslate(rect.left(), rect.bottom());
        m.rotate(-90);
    }
    else {
        m = QTransform::fromTranslate(rect.left(), rect.top());
    }

    const QRect draw_rect(QPoint(0, 0), m.mapRect(rect).size());

    p->save();
    p->setTransform(m);

    QRect icon_rect(QPoint(8, 0), v_opt->iconSize);
    QRect text_rect(icon_rect.topRight() + QPoint(4, 0), draw_rect.size());
    text_rect.setRight(draw_rect.width());
    icon_rect.translate(0, (draw_rect.height() - icon_rect.height()) / 2);

    QFont boldFont(p->font());
    boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
    boldFont.setBold(true);
    p->setFont(boldFont);
    p->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
    int textFlags = Qt::AlignHCenter | Qt::AlignVCenter;
    p->drawText(text_rect, textFlags, text);
    p->setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor());
    if (widget) {
        const QString fader_key = "tab_" + text + "_fader";
        const QString animation_key = "tab_" + text + "_animation";

        const QString tab_hover = widget->property("tab_hover").toString();
        int fader = widget->property(fader_key.toUtf8().constData()).toInt();
        QPropertyAnimation* animation = widget->property(animation_key.toUtf8().constData()).value<QPropertyAnimation*>();

        if (!animation) {
            QWidget* mut_widget = const_cast<QWidget*>(widget);
            fader = 0;
            mut_widget->setProperty(fader_key.toUtf8().constData(), fader);
            animation = new QPropertyAnimation(mut_widget, fader_key.toUtf8(), mut_widget);
            connect(animation, SIGNAL(valueChanged(QVariant)), mut_widget, SLOT(update()));
            mut_widget->setProperty(animation_key.toUtf8().constData(), QVariant::fromValue(animation));
        }

        if (text == tab_hover) {
            if (animation->state() != QAbstractAnimation::Running && fader != 40) {
                animation->stop();
                animation->setDuration(80);
                animation->setEndValue(40);
                animation->start();
            }
        }
        else {
            if (animation->state() != QAbstractAnimation::Running && fader != 0) {
                animation->stop();
                animation->setDuration(160);
                animation->setEndValue(0);
                animation->start();
            }
        }

        if (!selected) {
            p->save();
            p->fillRect(draw_rect, QColor(255, 255, 255, fader));
            p->setPen(QPen(QColor(255, 255, 255, fader), 1.0));
            p->drawLine(draw_rect.topLeft(), vertical_tabs ? draw_rect.bottomLeft() : draw_rect.topRight());
            p->drawLine(draw_rect.bottomRight(), vertical_tabs ? draw_rect.topRight() : draw_rect.bottomLeft());
            p->restore();
        }
    }

    Utils::StyleHelper::drawIconWithShadow(v_opt->icon, icon_rect, p, selected ? QIcon::Selected : QIcon::Normal);

    p->drawText(text_rect.translated(0, -1), textFlags, text);

    p->restore();
}
void SlidingStackedWidget::slideInWgt(QWidget * newWidget, Direction direction)
{
    if (active)
    {
        // At the moment, do not allow re-entrance before an animation is
        // completed. Other possibility may be to finish the previous animation
        // abrupt, or to revert the previous animation with a counter
        // animation, before going ahead or to revert the previous animation
        // abrupt and all those only, if the newwidget is not the same as that
        // of the previous running animation.
        return;
    }
    else
        active=true;

    Direction directionHint;
    int now = currentIndex();
    int next = indexOf(newWidget);
    if (now == next)
    {
        active = false;
        return;
    }
    else if (now < next)
        directionHint = vertical ? TOP2BOTTOM : RIGHT2LEFT;
    else
        directionHint=vertical ? BOTTOM2TOP : LEFT2RIGHT;

    if (direction == AUTOMATIC)
        direction = directionHint;

    int offsetX = frameRect().width();
    int offsetY = frameRect().height();

    // The following is important, to ensure that the new widget
    // has correct geometry information when sliding in first time
    widget(next)->setGeometry(0, 0, offsetX, offsetY);

    if (direction == BOTTOM2TOP)
    {
        offsetX = 0;
        offsetY = -offsetY;
    }
    else if (direction == TOP2BOTTOM)
        offsetX = 0;
    else if (direction == RIGHT2LEFT)
    {
        offsetX = -offsetX;
        offsetY = 0;
    }
    else if (direction == LEFT2RIGHT)
        offsetY = 0;

    // Re-position the next widget outside/aside of the display area
    QPoint pNext = widget(next)->pos();
    QPoint pNow = widget(now)->pos();
    pNow = pNow;

    widget(next)->move(pNext.x() - offsetX, pNext.y() - offsetY);
    widget(next)->show();
    widget(next)->raise();

    // Animate both, the now and next widget to the side, using animation framework
    QPropertyAnimation *animNow = new QPropertyAnimation(widget(now), "pos");

    animNow->setDuration(speed);
    animNow->setEasingCurve(animationType);
    animNow->setStartValue(QPoint(pNow.x(), pNow.y()));
    animNow->setEndValue(QPoint(offsetX + pNow.x(), offsetY + pNow.y()));
    QPropertyAnimation *animNext = new QPropertyAnimation(widget(next), "pos");
    animNext->setDuration(speed);
    animNext->setEasingCurve(animationType);
    animNext->setStartValue(QPoint(-offsetX + pNext.x(), offsetY + pNext.y()));
    animNext->setEndValue(QPoint(pNext.x(), pNext.y()));

    QParallelAnimationGroup *animGroup = new QParallelAnimationGroup;

    animGroup->addAnimation(animNow);
    animGroup->addAnimation(animNext);

    QObject::connect(animGroup, SIGNAL(finished()), this, SLOT(animationDoneSlot()));
    this->next = next;
    this->now = now;
    active = true;
    animGroup->start();

    // Note: the rest is done via a connect from the animation ready;
    // animation->finished() provides a signal when animation is done;
    // so we connect this to some post processing slot,
    // that we implement here below in animationDoneSlot.
}
void SlidingStackedWidget::slideInWgt(QWidget * newwidget, enum t_direction direction) {

        if (m_active) {
                return; // at the moment, do not allow re-entrance before an animation is completed.
                //other possibility may be to finish the previous animation abrupt, or
                //to revert the previous animation with a counter animation, before going ahead
                //or to revert the previous animation abrupt
                //and all those only, if the newwidget is not the same as that of the previous running animation.
        }
        else m_active=true;

        enum t_direction directionhint;
        int now=currentIndex();		//currentIndex() is a function inherited from QStackedWidget
        int next=indexOf(newwidget);
        if (now==next) {
                m_active=false;
                return;
        }
        else if (now<next){
                directionhint=m_vertical ? TOP2BOTTOM : RIGHT2LEFT;
        }
        else {
                directionhint=m_vertical ? BOTTOM2TOP : LEFT2RIGHT;
        }
        if (direction == AUTOMATIC) {
                direction=directionhint;
        }
        //NOW....
        //calculate the shifts

        int offsetx=frameRect().width(); //inherited from mother
        int offsety=frameRect().height();//inherited from mother

        //the following is important, to ensure that the new widget
        //has correct geometry information when sliding in first time
        widget(next)->setGeometry ( 0,  0, offsetx, offsety );

        if (direction==BOTTOM2TOP)  {
                offsetx=0;
                offsety=-offsety;
        }
        else if (direction==TOP2BOTTOM) {
                offsetx=0;
                //offsety=offsety;
        }
        else if (direction==RIGHT2LEFT) {
                offsetx=-offsetx;
                offsety=0;
        }
        else if (direction==LEFT2RIGHT) {
                //offsetx=offsetx;
                offsety=0;
        }
        //re-position the next widget outside/aside of the display area
        QPoint pnext=widget(next)->pos();
        QPoint pnow=widget(now)->pos();
        m_pnow=pnow;

        widget(next)->move(pnext.x()-offsetx,pnext.y()-offsety);
        //make it visible/show
        widget(next)->show();
        widget(next)->raise();
        //animate both, the now and next widget to the side, using animation framework
        QPropertyAnimation *animnow = new QPropertyAnimation(widget(now), "pos");

        animnow->setDuration(m_speed);
        animnow->setEasingCurve(m_animationtype);
        animnow->setStartValue(QPoint(pnow.x(), pnow.y()));
        animnow->setEndValue(QPoint(offsetx+pnow.x(), offsety+pnow.y()));
        QPropertyAnimation *animnext = new QPropertyAnimation(widget(next), "pos");
        animnext->setDuration(m_speed);
        animnext->setEasingCurve(m_animationtype);
        animnext->setStartValue(QPoint(-offsetx+pnext.x(), offsety+pnext.y()));
        animnext->setEndValue(QPoint(pnext.x(), pnext.y()));

        QParallelAnimationGroup *animgroup = new QParallelAnimationGroup;

        animgroup->addAnimation(animnow);
        animgroup->addAnimation(animnext);

        QObject::connect(animgroup, SIGNAL(finished()),this,SLOT(animationDoneSlot()));
        m_next=next;
        m_now=now;
        m_active=true;
        animgroup->start();
        emit this->animationStarted(next);
        //note; the rest is done via a connect from the animation ready;
        //animation->finished() provides a signal when animation is done;
        //so we connect this to some post processing slot,
        //that we implement here below in animationDoneSlot.
}
Exemple #6
0
void FancyTabProxyStyle::drawControl(
    ControlElement element, const QStyleOption* option,
    QPainter* p, const QWidget* widget) const {

  const QStyleOptionTabV3* v_opt = qstyleoption_cast<const QStyleOptionTabV3*>(option);

  if (element != CE_TabBarTab || !v_opt) {
    QProxyStyle::drawControl(element, option, p, widget);
    return;
  }

  const QRect rect = v_opt->rect;
  const bool selected = v_opt->state & State_Selected;
  const bool vertical_tabs = v_opt->shape == QTabBar::RoundedWest;
  const QString text = v_opt->text;

  QTransform m;
  if (vertical_tabs) {
    m = QTransform::fromTranslate(rect.left(), rect.bottom());
    m.rotate(-90);
  } else {
    m = QTransform::fromTranslate(rect.left(), rect.top());
  }

  const QRect draw_rect(QPoint(0, 0), m.mapRect(rect).size());

  if (!selected && GtkStyle::isActive()) {
      p->fillRect(option->rect, option->palette.background());
  }

  p->save();
  p->setTransform(m);

  QRect icon_rect(QPoint(8, 0), v_opt->iconSize);
  QRect text_rect(icon_rect.topRight() + QPoint(4, 0), draw_rect.size());
  text_rect.setRight(draw_rect.width());
  icon_rect.translate(0, (draw_rect.height() - icon_rect.height()) / 2);

    QStyleOptionViewItemV4 styleOpt;
    styleOpt.palette=option->palette;
    styleOpt.rect=draw_rect;
    if (QStyleOptionTab::Beginning==v_opt->position) {
        styleOpt.rect.adjust(0, 0, -1, 0);
    }
    styleOpt.state=option->state;
    styleOpt.state&=~(QStyle::State_Selected|QStyle::State_MouseOver);
    styleOpt.state|=QStyle::State_Selected|QStyle::State_Enabled;
    styleOpt.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
    styleOpt.showDecorationSelected=true;
    bool drawBgnd=true;
    int fader = 1;

    if (!selected && drawBgnd) {
        const QString fader_key = "tab_" + text + "_fader";
        const QString animation_key = "tab_" + text + "_animation";

        const QString tab_hover = widget->property("tab_hover").toString();
        fader=widget->property(fader_key.toUtf8().constData()).toInt();
        QPropertyAnimation* animation = widget->property(animation_key.toUtf8().constData()).value<QPropertyAnimation*>();

        if (!animation) {
            QWidget* mut_widget = const_cast<QWidget*>(widget);
            fader = 0;
            mut_widget->setProperty(fader_key.toUtf8().constData(), fader);
            animation = new QPropertyAnimation(mut_widget, fader_key.toUtf8(), mut_widget);
            connect(animation, SIGNAL(valueChanged(QVariant)), mut_widget, SLOT(update()));
            mut_widget->setProperty(animation_key.toUtf8().constData(), QVariant::fromValue(animation));
        }

        if (text == tab_hover) {
            if (animation->state() != QAbstractAnimation::Running && fader != 40) {
                animation->stop();
                animation->setDuration(80);
                animation->setEndValue(50);
                animation->start();
            }
        } else {
            if (animation->state() != QAbstractAnimation::Running && fader != 0) {
                animation->stop();
                animation->setDuration(160);
                animation->setEndValue(0);
                animation->start();
            }
        }

        if (fader<1) {
            drawBgnd=false;
        } else {
            QColor col(styleOpt.palette.highlight().color());
            col.setAlpha(fader);
            styleOpt.palette.setColor(styleOpt.palette.currentColorGroup(), QPalette::Highlight, col);
        }
    }

    if (drawBgnd) {
        if (!selected && GtkStyle::isActive()) {
            GtkStyle::drawSelection(styleOpt, p, (fader*1.0)/150.0);
        } else {
            QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &styleOpt, p, 0);
        }
    }
//     drawRoundedRect(p, draw_rect, 3, col);


//   QFont boldFont(p->font());
//   boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
// //   boldFont.setBold(true);
//   p->setFont(boldFont);
//   p->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
  int textFlags = Qt::AlignTop | Qt::AlignVCenter;
//   p->drawText(text_rect, textFlags, text);
//   p->setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor());
    p->setPen(selected && option->state&State_Active
              ? QApplication::palette().highlightedText().color() : QApplication::palette().foreground().color());

  drawIcon(v_opt->icon, icon_rect, p, v_opt->iconSize,
           selected && option->state&State_Active);

  QString txt=text;
  txt.replace("&", "");
  txt=p->fontMetrics().elidedText(txt, elideMode(), text_rect.width());

  p->drawText(text_rect.translated(0, -1), textFlags, txt);

  p->restore();
}
Exemple #7
0
void FCenterWindow::cloudAntimation(animation_Direction direction)
{
    QLabel* circle = new QLabel(stackWidget->currentWidget());
    QLabel* line = new QLabel(this);
    line->setObjectName(QString("AntimationLine"));
    line->resize(0, 2);
    line->show();
    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
        circle->setPixmap(QPixmap::grabWidget(stackWidget->widget(preindex), stackWidget->widget(preindex)->geometry()));
    #else
        circle->setPixmap(stackWidget->widget(preindex)->grab());
    #endif

//    circle->setScaledContents(true);
    circle->show();
    circle->resize(stackWidget->currentWidget()->size());
    QPropertyAnimation *animation = new QPropertyAnimation(circle, "geometry");

    animation->setDuration(500);
    animation->setStartValue(circle->geometry());

//    QPropertyAnimation* animation_line = new QPropertyAnimation(line, "size");
//    animation_line->setDuration(500);
//    animation_line->setEasingCurve(QEasingCurve::OutQuart);

    switch (direction) {
    case animationTop:
        animation->setEndValue(QRect(circle->x(), circle->y() - 10, circle->width(), 0));
        break;
    case animationTopRight:
        animation->setEndValue(QRect(circle->width(), 0, 0, 0));
        break;
    case animationRight:
        line->move(0, stackWidget->y() - 2);
        animation->setEndValue(QRect(circle->width() + 3, 0, 0, circle->height()));
//        animation_line->setStartValue(QSize(0, 2));
//        animation_line->setEndValue(QSize(stackWidget->width(), 2));
        break;
    case animationBottomRight:
        animation->setEndValue(QRect(circle->width(), circle->height(), 0, 0));
        break;
    case animationBottom:
        animation->setEndValue(QRect(0, circle->height() + 10, circle->width(), 0));
        break;
    case animationBottomLeft:
        animation->setEndValue(QRect(0, circle->height(), 0, 0));
        break;
    case animationLeft:
        animation->setEndValue(QRect(-3, 0, 0, circle->height()));
        line->move(stackWidget->x(), stackWidget->y() - 2);
//        animation_line->setStartValue(QSize(0, 2));
//        animation_line->setEndValue(QSize(stackWidget->width(), 2));
        break;
    case animationTopLeft:
        animation->setEndValue(QRect(0, 0, 0, 0));
        break;
    case animationCenter:
        animation->setEndValue(QRect(circle->width()/2, circle->height()/2, 0, 0));
        break;
    default:
        break;
    }
    animation->setEasingCurve(QEasingCurve::OutQuart);

    QPropertyAnimation* animation_opacity = new QPropertyAnimation(circle, "windowOpacity");
    animation_opacity->setDuration(500);
    animation_opacity->setStartValue(1);
    animation_opacity->setEndValue(0);
    animation_opacity->setEasingCurve(QEasingCurve::OutQuart);

    QParallelAnimationGroup *group = new QParallelAnimationGroup;

    connect(group,SIGNAL(finished()), circle, SLOT(hide()));
    connect(group,SIGNAL(finished()), circle, SLOT(deleteLater()));
    connect(group,SIGNAL(finished()), line, SLOT(deleteLater()));
    connect(group,SIGNAL(finished()), group, SLOT(deleteLater()));
    connect(group,SIGNAL(finished()), animation, SLOT(deleteLater()));
    connect(group,SIGNAL(finished()), animation_opacity, SLOT(deleteLater()));
//    connect(group,SIGNAL(finished()), animation_line, SLOT(deleteLater()));
    group->addAnimation(animation);
    group->addAnimation(animation_opacity);
//    group->addAnimation(animation_line);
    group->start();
}
Exemple #8
0
  /*
  Most important function of an interactor component
  When an event arrive on your interactor : this function is call
  You have to process it and return true. If the event do nothing in your interactor : this function
  return false;
  */
  bool eventFilter(QObject *, QEvent *e) {

    /*
    If you have clicked on a node/edge, information widget is visible.
    And if you use the wheel of the mouse we hide the information widget
    */
    if (_informationWidgetItem->isVisible() && e->type() == QEvent::Wheel) {
      _informationWidgetItem->setVisible(false);
      return false;
    }

    /*
    Check if the event is a mouse event
    */
    QMouseEvent *qMouseEv = dynamic_cast<QMouseEvent *>(e);

    if (qMouseEv != nullptr) {
      GlMainView *glMainView = static_cast<GlMainView *>(view());

      /*
      Check if event is a left mouse button press
      */
      if (e->type() == QEvent::MouseButtonPress && qMouseEv->button() == Qt::LeftButton) {

        /*
        If you have clicked on a node/edge, information widget is visible.
        And if you reclick : hide it
        */
        if (_informationWidgetItem->isVisible()) {
          _informationWidgetItem->setVisible(false);
        } else {

          /*
          Select entities under the mouse cursor
          The result of selection is stored in SelectedEntity
          And pickNodesEdges return true if you click on node or edge
          */
          SelectedEntity selectedEntity;

          if (glMainView->getGlMainWidget()->pickNodesEdges(qMouseEv->x(), qMouseEv->y(),
                                                            selectedEntity)) {

            /*
            Change text of the information label with
            - If you click on a node : "Click on node id : nodeId"
            - If you click on an edge : "Click on edge id : edgeId"
            */
            QString text("Click on ");

            if (selectedEntity.getEntityType() == SelectedEntity::NODE_SELECTED)
              text += "node ";
            else
              text += "edge ";

            text += " id : " + QString::number(selectedEntity.getComplexEntityId());

            /*
            - Update QLabel with new text
            - Auto resize QLabel
            - Set position of the label at mouse position
            - Display it
            */
            _informationLabel->setText(text);
            _informationLabel->adjustSize();
            _informationWidgetItem->setPos(qMouseEv->pos());
            _informationWidgetItem->setVisible(true);

            /*
            Here we just add a small smooth animation on the label pop
            */
            QPropertyAnimation *animation =
                new QPropertyAnimation(_informationWidgetItem, "opacity");
            animation->setDuration(100);
            animation->setStartValue(0.);
            animation->setEndValue(0.99);
            animation->start();

            /*
            We have treated the event so we return true
            */
            return true;
          }
        }
      }
    }

    /*
    We don't have treated the event se we return false
    */
    return false;
  }
Exemple #9
0
void ScCodeEditor::blinkCode( const QTextCursor & c )
{
    if( !c.document() || !c.hasSelection() ) return;

    Settings::Manager *settings = Main::settings();
    QTextCharFormat evalCodeTextFormat = settings->getThemeVal("evaluatedCode");

    QTextDocument *doc = c.document();

    int startPos = c.selectionStart();
    int endPos = c.selectionEnd();
    QTextBlock startBlock = doc->findBlock(startPos);
    QTextBlock endBlock = doc->findBlock(endPos);
    startPos -= startBlock.position();
    endPos -= endBlock.position();

    // Get the bounds of visible blocks within the cursor's selection:

    QTextBlock block = firstVisibleBlock();
    int idx = block.blockNumber();
    int sidx = startBlock.blockNumber();

    QTextBlock firstBlock, lastBlock;
    firstBlock = lastBlock = block;

    QRectF geom = blockBoundingGeometry(block).translated(contentOffset());
    qreal top = geom.top();
    qreal bottom = top;
    qreal width=0;

    while(block.isValid() && bottom < viewport()->rect().height())
    {
        if(block.isVisible())
        {
            QTextLayout *l = block.layout();
            QRectF r = l->boundingRect();
            bottom += r.height();
            if(idx < sidx) {
                // Block not within the selection. Will skip it.
                top = bottom;
            }
            else {
                // Block within the selection.
                width = qMax(width, l->maximumWidth() + r.left());
            }
        }

        if(block == endBlock) break;

        block = block.next();
        ++idx;
        if(top == bottom)
            firstBlock = block;
    }

    lastBlock = block;

    if(bottom == top) {
        //qDebug("no visible block.");
        return;
    }

    // Construct a pixmap to render the code on:

    QPixmap pix( QSize(qCeil(width), qCeil(bottom - top)) );
    pix.fill(QColor(0,0,0,0));

    // Render the visible blocks:

    QPainter painter(&pix);
    QVector<QTextLayout::FormatRange> selections;
    block = firstBlock;
    int y=0;
    while( block.isValid() )
    {
        if (block.isVisible())
        {
            QRectF blockRect = block.layout()->boundingRect();

            // Use extra char formatting to hide code outside of selection
            // and modify the appearance of selected code:

            QTextLayout::FormatRange range;
            selections.clear();

            int start = 0;
            if(block == startBlock) {
                range.start = 0;
                range.length = startPos;
                range.format.setForeground(QColor(0,0,0,0));
                range.format.setBackground(Qt::NoBrush);
                selections.append(range);
                start = startPos;
            }

            range.start = start;
            range.length = (block == endBlock ? endPos : block.length() - 1) - range.start;
            range.format = evalCodeTextFormat;
            selections.append(range);

            if(block == endBlock) {
                range.start = range.start + range.length;
                range.length = block.length() - 1 - range.start;
                range.format.setForeground(QColor(0,0,0,0));
                range.format.setBackground(Qt::NoBrush);
                selections.append(range);
            }

            block.layout()->draw(&painter, QPointF(0,y), selections);

            y += blockRect.height();
        }

        if(block == lastBlock) break;

        block = block.next();
    }

    // Create an overlay item to display the pixmap, and animate it:

    CodeFragmentOverlay *item = new CodeFragmentOverlay();
    item->setPixmap(pix);
    item->setPos(geom.left(), top);

    mOverlay->addItem(item);

    QPropertyAnimation *anim = new QPropertyAnimation(item, "opacity", item);
    anim->setDuration(mBlinkDuration);
    anim->setStartValue(1.0);
    anim->setEndValue(0.0);
    anim->setEasingCurve( QEasingCurve::InCubic );
    anim->start();

    connect(anim, SIGNAL(finished()), item, SLOT(deleteLater()));
}
Exemple #10
0
void BoardView::drawStones()
{
    static QPixmap*      bstone = new QPixmap(":/images/blackstone.gif");
    static QPixmap*      wstone = new QPixmap(":/images/wwstone.gif");
    if (this->_board != 0)
    {
        Coord* lastCoord = 0;
        QBrush lastBrush;
        for (unsigned int i = 0; i < this->_board->getSize(); i++)
        {
            for (unsigned int j = 0; j < this->_board->getSize(); j++)
            {
                QBrush brush;
                if (BoardCell::matchMask(*this->_board->getCell(i, j), WHITE))
                    brush = QBrush(Qt::white);
                else if (BoardCell::matchMask(*this->_board->getCell(i, j), BLACK))
                    brush = QBrush(Qt::black);
                if (!BoardCell::isEmpty(*this->_board->getCell(i, j)))
                {
                    Coord c = this->getCoord(i, j);
                    if (this->_board->getLastPlayed())
                    {
                        Coord lastCell = this->getCoord(this->_board->getLastPlayed()->x, this->_board->getLastPlayed()->y);
                        if (c.x == lastCell.x && c.y == lastCell.y)
                        {
                            lastCoord = new Coord(c.x, c.y);
                            lastBrush = brush;
                        }
                    }
                    if (!lastCoord || lastCoord->x != c.x || lastCoord->y != c.y)
                    {
                        QGraphicsPixmapItem* item;
                        double               width;
                        if (brush.color() == Qt::black)
                        {
                            item = this->_scene.addPixmap(*bstone);
                            width = bstone->width();
                        }
                        else
                        {
                            item = this->_scene.addPixmap(*wstone);
                            width = wstone->width();
                        }
                        item->setPos(c.x, c.y);
                        item->setScale(this->_lineSpacing/width);
                    }
                }
            }
        }
        if (lastCoord)
        {
            Stone* stone = new Stone();
            double width;

            if (lastBrush.color() == Qt::black)
            {
                stone->setPixmap(*bstone);
                width = bstone->width();
            }
            else
            {
                stone->setPixmap(*wstone);
                width = wstone->width();
            }
            stone->initScaleAndOffset(lastCoord->x, lastCoord->y,
                                      this->_lineSpacing/width, this->_lineSpacing/2);
            this->_scene.addItem(stone);
            QPropertyAnimation* animation = new QPropertyAnimation(stone, "scale");
            animation->setDuration(200);
            animation->setStartValue(0.0);
            animation->setEndValue(this->_lineSpacing/width);
            animation->setEasingCurve(QEasingCurve::OutBounce);
            animation->start();
            delete lastCoord;
        }
    }
    else
        std::cout << "drawStones(): Warning: No board set in BoardView" << std::endl;
}
void DraftScoreWindow::setScores(double rating1, double rating2, double rating3,
                                 QString synergy1, QString synergy2, QString synergy3)
{
    double ratings[3] = {rating1, rating2, rating3};
    QString synergies[3] = {synergy1, synergy2, synergy3};
    double maxRating = std::max(std::max(rating1,rating2),rating3);

    for(int i=0; i<3; i++)
    {
        int rating255 = std::max(std::min((int)(ratings[i]*2.55), 255), 0);
        int r = std::min(255, (255 - rating255)*2);
        int g = std::min(255,rating255*2);
        int b = 0;

        scoresPushButton[i]->setText(QString::number((int)ratings[i]));
        scoresPushButton[i]->setStyleSheet(
            "QPushButton{background-color: "

            "qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, "
            "stop: 0 black, "
            "stop: 0.5 rgb("+ QString::number(r) +","+ QString::number(g) +","+ QString::number(b) +"), "
            "stop: 1 black);"

            "border-style: solid;border-color: black;" +
            ((!synergies[i].isEmpty())?"border-bottom-style: dotted;":"") +

            "border-width: " + QString::number(scoreWidth/20) + "px;border-radius: "
            + QString::number(scoreWidth/3) + "px;}");

        QPropertyAnimation *animation = new QPropertyAnimation(scoresPushButton[i], "maximumHeight");
        animation->setDuration(ANIMATION_TIME);
        animation->setStartValue(0);
        animation->setEndValue(scoreWidth);
        animation->setEasingCurve(QEasingCurve::OutBounce);
        animation->start();


        animation = new QPropertyAnimation(scoresPushButton[i], "minimumHeight");
        animation->setDuration(ANIMATION_TIME);
        animation->setStartValue(0);
        animation->setEndValue(scoreWidth);
        animation->setEasingCurve(QEasingCurve::OutBounce);
        animation->start();

        scoresPushButton[i]->setDrawArrow(!synergies[i].isEmpty());
        scoresPushButton[i]->setDrawHLines(ratings[i]==maxRating);


        //Insert synergies
        synergiesListWidget[i]->clear();

        QStringList synergiesList = synergies[i].split(" - ", QString::SkipEmptyParts);
        foreach(QString name, synergiesList)
        {
            QString code = Utility::cardEnCodeFromName(name);
            DeckCard deckCard(code);
            deckCard.listItem = new QListWidgetItem(synergiesListWidget[i]);
            deckCard.draw();
        }

        synergiesListWidget[i]->setMaximumWidth(0);
    }
Exemple #12
0
void QQHuntPixmapItem::animate()
{
	m_animation->clear();
	m_listPixmapProp.clear();
	int timeMs = QuteTools::randInt(MIN_DURATION, MAX_DURATION);

	//Recuperation des bornes
	QRectF sceneRect = scene()->sceneRect();
	float maxX = sceneRect.width() - boundingRect().width();
	float maxY = sceneRect.height() - boundingRect().height();

	//Et du point initial
	QPointF curPos = pos();

	//Calcul du nouveau vecteur vitesse
	float angle = (((float) qrand()) / INT_MAX) * M_PI_2;
	angle -= M_PI_4;

	QQMatrix2x2 rotMatrix;
	rotMatrix(0, 0) = qCos(angle);
	rotMatrix(0, 1) = qSin(angle);
	rotMatrix(1, 0) = 0.0 - rotMatrix(0,1);
	rotMatrix(1, 1) = rotMatrix(0,0);

	m_speedVec = rotMatrix * m_speedVec;

	//Decoupage du temps d'animation en tranche selon les rencontres avec les bords.
	while(timeMs > 0)
	{
		QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "pos");
		pAnimation->setStartValue(curPos);
		connect(pAnimation, SIGNAL(finished()), this, SLOT(loadNextPixMap()));

		float angle = qAcos(m_speedVec(X_VALUE)); // 0 <= angle <= Pi
		QQPixmapProp pixmapProp = animPixmapProp(angle);
		m_listPixmapProp.append(pixmapProp);

		QQMatrix1x2 resSpeedVec = m_speedVec * ((float) SPEED_FACTOR)
											 * (timeMs / (float) (MAX_DURATION - MIN_DURATION));
		float destPosX = curPos.x() + resSpeedVec(X_VALUE);
		float destPosY = curPos.y() + resSpeedVec(Y_VALUE);

		float xFactor = 1;
		if(destPosX < 0)
			xFactor = (0.0 - curPos.x() / (destPosX - curPos.x()));
		else if(destPosX > maxX)
			xFactor = (maxX - curPos.x()) / (destPosX - curPos.x());

		float yFactor = 1;
		if(destPosY < 0)
			yFactor = (0.0 - curPos.y() / (destPosY - curPos.y()));
		else if(destPosY > maxY)
			yFactor = (maxY - curPos.y()) / (destPosY - curPos.y());

		//qDebug() << "xFactor" << xFactor << "yFactor" << yFactor;
		//Collision de bord detectee
		if(xFactor < 1 || yFactor < 1)
		{
			float realtime = 0;
			if(xFactor <= yFactor) // on touche gauche/droite avant haut/bas
			{
				realtime = timeMs * xFactor;
				curPos = QPointF(curPos.x() + (destPosX - curPos.x()) * xFactor,
								 curPos.y() + (destPosY - curPos.y()) * xFactor);

				m_speedVec(X_VALUE) = 0.0 - m_speedVec(X_VALUE);
				if(xFactor == yFactor)
					m_speedVec(Y_VALUE) = 0.0 - m_speedVec(Y_VALUE);
			}
			else if(xFactor > yFactor) // on touche haut/bas avant gauche/droite
			{
				realtime = timeMs * yFactor;
				curPos = QPointF(curPos.x() + (destPosX - curPos.x()) * yFactor,
								 curPos.y() + (destPosY - curPos.y()) * yFactor);

				m_speedVec(Y_VALUE) = 0.0 - m_speedVec(Y_VALUE);
			}

			pAnimation->setDuration(realtime);
			timeMs -= realtime;
			pAnimation->setEndValue(curPos);
		}
		else
		{
			pAnimation->setDuration(timeMs);
			timeMs = 0;
			pAnimation->setEndValue(QPointF(destPosX, destPosY));
		}
		m_animation->addAnimation(pAnimation);
	}
	loadNextPixMap();
	m_animation->start(QAbstractAnimation::KeepWhenStopped);
}
Exemple #13
0
int main(int argc, char* argv[])
{
    QGuiApplication app(argc, argv);
    Qt3D::QWindow view;
    Qt3D::QInputAspect *input = new Qt3D::QInputAspect;
    view.registerAspect(input);

    // Root entity
    Qt3D::QEntity *rootEntity = new Qt3D::QEntity();

    // Camera
    Qt3D::QCamera *cameraEntity = view.defaultCamera();

    cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
    cameraEntity->setPosition(QVector3D(0, 0, -40.0f));
    cameraEntity->setUpVector(QVector3D(0, 1, 0));
    cameraEntity->setViewCenter(QVector3D(0, 0, 0));
    input->setCamera(cameraEntity);

    // Material
    Qt3D::QMaterial *material = new Qt3D::QPhongMaterial(rootEntity);

    // Torus
    Qt3D::QEntity *torusEntity = new Qt3D::QEntity(rootEntity);
    Qt3D::QTorusMesh *torusMesh = new Qt3D::QTorusMesh;
    torusMesh->setRadius(5);
    torusMesh->setMinorRadius(1);
    torusMesh->setRings(100);
    torusMesh->setSlices(20);

    Qt3D::QTransform *torusTransform = new Qt3D::QTransform;
    Qt3D::QScaleTransform *torusScaleTransform = new Qt3D::QScaleTransform;
    torusScaleTransform->setScale3D(QVector3D(1.5, 1, 0.5));

    Qt3D::QRotateTransform *torusRotateTransform = new Qt3D::QRotateTransform;
    torusRotateTransform->setAxis(QVector3D(1, 0, 0));
    torusRotateTransform->setAngleDeg(45);

    torusTransform->addTransform(torusScaleTransform);
    torusTransform->addTransform(torusRotateTransform);


    torusEntity->addComponent(torusMesh);
    torusEntity->addComponent(torusTransform);
    torusEntity->addComponent(material);

    // Sphere
    Qt3D::QEntity *sphereEntity = new Qt3D::QEntity(rootEntity);
    Qt3D::QSphereMesh *sphereMesh = new Qt3D::QSphereMesh;
    sphereMesh->setRadius(3);

    Qt3D::QTransform *sphereTransform = new Qt3D::QTransform;
    Qt3D::QTranslateTransform *sphereTranslateTransform = new Qt3D::QTranslateTransform;
    sphereTranslateTransform->setTranslation(QVector3D(20, 0, 0));

    Qt3D::QRotateTransform *sphereRotateTransform = new Qt3D::QRotateTransform;
    QPropertyAnimation *sphereRotateTransformAnimation = new QPropertyAnimation(sphereRotateTransform);
    sphereRotateTransformAnimation->setTargetObject(sphereRotateTransform);
    sphereRotateTransformAnimation->setPropertyName("angle");
    sphereRotateTransformAnimation->setStartValue(QVariant::fromValue(0));
    sphereRotateTransformAnimation->setEndValue(QVariant::fromValue(360));
    sphereRotateTransformAnimation->setDuration(10000);
    sphereRotateTransformAnimation->setLoopCount(-1);
    sphereRotateTransformAnimation->start();

    sphereRotateTransform->setAxis(QVector3D(0, 1, 0));
    sphereRotateTransform->setAngleDeg(0);

    sphereTransform->addTransform(sphereTranslateTransform);
    sphereTransform->addTransform(sphereRotateTransform);

    sphereEntity->addComponent(sphereMesh);
    sphereEntity->addComponent(sphereTransform);
    sphereEntity->addComponent(material);

    view.setRootEntity(rootEntity);
    view.show();

    return app.exec();
}
RocketStorageSelectionDialog::RocketStorageSelectionDialog(RocketPlugin *plugin, MeshmoonStorage *storage, const QStringList &suffixFilters, 
                                                           bool allowChangingFolder, MeshmoonStorageItem &startDirectory, QWidget *parent) :
    QDialog(parent),
    plugin_(plugin),
    storage_(storage),
    suffixFilters_(suffixFilters),
    allowChangingFolder_(allowChangingFolder),
    startDirectory_(startDirectory),
    currentFolder_(0)
{
    // Setup UI
    ui_.setupUi(this);
    ui_.scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui_.lineEditFilter->installEventFilter(this);

    ui_.buttonSelect->setAutoDefault(false);
    ui_.buttonCancel->setAutoDefault(false);

    view_ = new RocketStorageListWidget(this, plugin_);
    view_->SetPreviewFileOnMouse(true);
    view_->setSelectionMode(QAbstractItemView::SingleSelection);

    QVBoxLayout *l = new QVBoxLayout(ui_.scrollAreaWidgetContents);
    l->setSpacing(0);
    l->setContentsMargins(0,0,0,0);
    l->addWidget(view_);
    ui_.scrollAreaWidgetContents->setLayout(l);

    // Connections
    connect(view_, SIGNAL(itemClicked(QListWidgetItem*)), SLOT(OnItemClicked(QListWidgetItem*)));
    connect(view_, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(OnItemDoubleClicked(QListWidgetItem*)));
    connect(ui_.buttonSelect, SIGNAL(clicked()), SLOT(OnSelect()), Qt::QueuedConnection);
    connect(ui_.buttonCancel, SIGNAL(clicked()), SLOT(reject()), Qt::QueuedConnection);
    connect(this, SIGNAL(rejected()), SLOT(OnCancel()));
    connect(ui_.lineEditFilter, SIGNAL(textChanged(const QString&)), SLOT(OnFilterChanged(const QString&)));

    // Dialog setup
    setAttribute(Qt::WA_DeleteOnClose, true);
    setWindowModality(parent != 0 ? Qt::WindowModal : Qt::ApplicationModal);
    setWindowFlags(parent != 0 ? Qt::Tool : Qt::SplashScreen);
    setWindowTitle(parent != 0 ? "Meshmoon Storage Picker" : "");
    setModal(true);

    // Center to main window or to parent window.
    if (!parent)
    {
        plugin_->Notifications()->DimForeground();
        plugin_->Notifications()->CenterToMainWindow(this);
    }
    else
        plugin_->Notifications()->CenterToWindow(parent, this);
    
    // Show and activate
    show();
    setFocus(Qt::ActiveWindowFocusReason);
    activateWindow();
    
    // If this is a splash dialog animate opacity
    if (!parent)
    {
        setWindowOpacity(0.0);

        QPropertyAnimation *showAnim = new QPropertyAnimation(this, "windowOpacity", this);
        showAnim->setStartValue(0.0);
        showAnim->setEndValue(1.0);
        showAnim->setDuration(300);
        showAnim->setEasingCurve(QEasingCurve(QEasingCurve::InOutQuad)); 
        showAnim->start();
    }

    if (!plugin_ || !storage_)
    {
        view_->addItem(new QListWidgetItem("Failed to list storage content"));
        return;
    }
    if (storage_->RootDirectory().IsNull())
        view_->addItem(new QListWidgetItem("Loading..."));

    MeshmoonStorageAuthenticationMonitor *auth = storage_->Authenticate();
    connect(auth, SIGNAL(Completed()), SLOT(OnStorageAuthCompleted()), Qt::QueuedConnection);
    connect(auth, SIGNAL(Canceled()), SLOT(reject()), Qt::QueuedConnection);
    connect(auth, SIGNAL(Failed(const QString&)), SLOT(reject()), Qt::QueuedConnection);
}
EinstellungHauptlicht::EinstellungHauptlicht(QWidget *parent, steuerungThreadLicht *s, ModelThreadLicht *m) :
    QDialog(parent),
    ui(new Ui::EinstellungHauptlicht)
{
    ui->setupUi(this);
    ui->pushButton_back->setVisible(false);

    if(SlinderarduinoEnable == true)
    {
        Slider = new thread_Slider(this);
    }
    sThread = s;
    mThread = m;

    //slide in animation
    QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
    connect(animation, SIGNAL(finished()), this, SLOT(afterAnimation()));
    animation->setDuration(500);
    animation->setStartValue(QRect(-800,0,800,480));
    animation->setEndValue(QRect(0,0,800,480));
    animation->setEasingCurve(QEasingCurve::OutExpo);
    animation->start();

    //put all PushButtons in Array to be able to loop through them
    ArrayOfPushButtons.append(ui->pushButton_1);
    ArrayOfPushButtons.append(ui->pushButton_2);
    ArrayOfPushButtons.append(ui->pushButton_3);
    ArrayOfPushButtons.append(ui->pushButton_4);
    ArrayOfPushButtons.append(ui->pushButton_5);
    ArrayOfPushButtons.append(ui->pushButton_6);
    ArrayOfPushButtons.append(ui->pushButton_7);
    ArrayOfPushButtons.append(ui->pushButton_8);
    ArrayOfPushButtons.append(ui->pushButton_9);

    //Setup Sliders
    if(SlinderarduinoEnable == true){
        Slider->init(sThread->Hauptlicht_Data[0]/2.55, 0,0,0);
        Slider->start();
    }


    //setup backgrounds, borders
    for (int i = 0; i < ArrayOfPushButtons.length(); i++)
    {
        ArrayOfPushButtons[i]->setStyleSheet("border: 2px solid black; border-radius: 10px;");
        ArrayOfPushButtons[i]->setChecked(false);
    }
    SetAllButtonsColor();
    ui->horizontalSlider->setSliderPosition(sThread->Hauptlicht_Data[0]/2.55);
    //connect(ui->horizontalSlider, SIGNAL(sliderMoved(int)), this, SLOT(SliderHellChanged(int)));//<----for testing

    //setup button AnAus
    if (sThread->getStatusHauptlicht()) ui->pushButton_AnAus->setText("Aus");
    else ui->pushButton_AnAus->setText("An");
  //Communication between Threads
    //Slider -> UI
    if(SlinderarduinoEnable == true) connect(Slider, SIGNAL(Slider1_Changed(int)), this, SLOT(SliderHellChanged(int)));

    //UI -> steuerungThreadLicht
    connect(this, SIGNAL(HelligkeitChanged(int)), sThread, SLOT(SetHauptlicht(int)));
    connect(this,SIGNAL(toggelhauptlicht()), sThread,SLOT(hauptlichtNetzteilOnOff()));
    connect(this,SIGNAL(hauptlichtOn(int)),sThread,SLOT(SetHauptlicht(int)));

    emit hauptlichtOn(1);
}
Exemple #16
0
	void GlanceShower::Start ()
	{
		if (!TabWidget_)
		{
			qWarning () << Q_FUNC_INFO
				<< "no tab widget set";
			return;
		}

		const int count = TabWidget_->count ();
		if (count < 2)
		{
			emit finished (true);
			return;
		}

		QAnimationGroup *animGroup = new QParallelAnimationGroup;

		const int sqr = std::sqrt ((double)count);
		int rows = sqr;
		int cols = sqr;
		if (rows * cols < count)
			++cols;
		if (rows * cols < count)
			++rows;

		const QRect& screenGeom = QApplication::desktop ()->
				screenGeometry (Core::Instance ().GetReallyMainWindow ());
		const int width = screenGeom.width ();
		const int height = screenGeom.height ();

		const int singleW = width / cols;
		const int singleH = height / rows;

		const int wW = singleW * 4 / 5;
		const int wH = singleH * 4 / 5;

		qreal scaleFactor = 0;
		QSize sSize;

		const int animLength = 400;

		QProgressDialog pg;
		pg.setMinimumDuration (1000);
		pg.setRange (0, count);

		for (int row = 0; row < rows; ++row)
			for (int column = 0;
					column < cols && column + row * cols < count;
					++column)
			{
				const int idx = column + row * cols;
				pg.setValue (idx);
				QWidget *w = TabWidget_->widget (idx);

				if (!sSize.isValid ())
					sSize = w->size () / 2;
				if (sSize != w->size ())
					w->resize (sSize * 2);

				if (std::fabs (scaleFactor) < std::numeric_limits<qreal>::epsilon ())
					scaleFactor = std::min (static_cast<qreal> (wW) / sSize.width (),
							static_cast<qreal> (wH) / sSize.height ());

				QPixmap pixmap (sSize * 2);
				w->render (&pixmap);
				pixmap = pixmap.scaled (sSize,
						Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

				{
					QPainter p (&pixmap);
					QPen pen (Qt::black);
					pen.setWidth (2 / scaleFactor + 1);
					p.setPen (pen);
					p.drawRect (QRect (QPoint (0, 0), sSize));
				}

				GlanceItem *item = new GlanceItem (pixmap);
				item->SetIndex (idx);
				connect (item,
						SIGNAL (clicked (int)),
						this,
						SLOT (handleClicked (int)));

				Scene_->addItem (item);
				item->setTransformOriginPoint (sSize.width () / 2, sSize.height () / 2);
				item->setScale (scaleFactor);
				item->SetIdealScale (scaleFactor);
				item->setOpacity (0);
				item->moveBy (column * singleW, row * singleH);

				QAnimationGroup *pair = new QParallelAnimationGroup;

				QPropertyAnimation *posAnim = new QPropertyAnimation (item, "Pos");
				posAnim->setDuration (animLength);
				posAnim->setStartValue (QPointF (0, 0));
				posAnim->setEndValue (QPointF (column * singleW, row * singleH));
				posAnim->setEasingCurve (QEasingCurve::OutSine);
				pair->addAnimation (posAnim);

				QPropertyAnimation *opacityAnim = new QPropertyAnimation (item, "Opacity");
				opacityAnim->setDuration (animLength);
				opacityAnim->setStartValue (0.);
				opacityAnim->setEndValue (1.);
				pair->addAnimation (opacityAnim);

				animGroup->addAnimation (pair);
			}

		setScene (Scene_);

		setGeometry (screenGeom);
		animGroup->start ();

		Q_FOREACH (QGraphicsItem* item, items ())
		{
			GlanceItem *itm = qgraphicsitem_cast<GlanceItem*> (item);
			itm->SetItemList (items ());
		}
Exemple #17
0
bossWindow::bossWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::bossWindow)
{
    ui->setupUi(this);
#pragma region window initialize
    QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
    animation->setDuration(700);
    animation->setStartValue(0);
    animation->setEndValue(1);
    animation->start();
    //界面动画,改变透明度的方式出现0 - 1渐变
    //设置窗体标题栏隐藏并设置位于顶层
    QPalette palette;
    setWindowOpacity(1);
    QPixmap pixmap("image/uiBG.png");
    palette.setBrush(ui->Under->backgroundRole(),QBrush(pixmap));
    ui->Under->setPalette(palette);
    ui->Under->setMask(pixmap.mask());  //可以将图片中透明部分显示为透明的
    ui->Under->setAutoFillBackground(true);

    ui->lineEdit_passwd->setEchoMode(QLineEdit::Password);

    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
    //构建最小化、最大化、关闭按钮
    QToolButton *minButton = new QToolButton(this);
    QToolButton *closeButton= new QToolButton(this);
    connect (minButton,SIGNAL(clicked()),this,SLOT(showMinimized()));
    connect (closeButton,SIGNAL(clicked()),this,SLOT(wind_close()));//构建新槽 关闭当前窗口=注销
    //获取最小化、关闭按钮图标
    QPixmap minPix  = style()->standardPixmap(QStyle::SP_TitleBarMinButton);
    QPixmap closePix = style()->standardPixmap(QStyle::SP_TitleBarCloseButton);
    //设置最小化、关闭按钮图标
    minButton->setIcon(minPix);
    closeButton->setIcon(closePix);
    //设置最小化、关闭按钮在界面的位置
    minButton->setGeometry(700-30,10,20,20);
    closeButton->setGeometry(700-8,10,20,20);
    //设置鼠标移至按钮上的提示信息
    minButton->setToolTip(tr("最小化"));
    closeButton->setToolTip(tr("关闭"));
    //设置最小化、关闭按钮的样式
    minButton->setStyleSheet("background-color:transparent;");
    closeButton->setStyleSheet("background-color:transparent;");
    qDebug()<< "asdasd";
//    ui->frame_menu->hide();
    ui->frame_order->hide();//查看页面隐藏
    ui->frame_scy->hide();
    ui->label_username->setText(all_SCY[active_scy].show_username());//用户名设置
    ui->lcdNumber_amount->display(all_SCY[active_scy].show_amount_count());//总金额
    ui->lcdNumber_counter->display(all_SCY[active_scy].show_order_count());//总订单数

#pragma endregion window initialize

    int i;

    /*菜单初始化*/
    model_menu2->setHorizontalHeaderItem(0,new QStandardItem(QObject::tr("Name")));//行标设置
    model_menu2->setHorizontalHeaderItem(1,new QStandardItem(QObject::tr("Price")));
    model_menu2->setHorizontalHeaderItem(2,new QStandardItem(QObject::tr("Rank")));
    ui->tableView_menu->setSelectionBehavior(QAbstractItemView::SelectRows);//点击选中行
    ui->tableView_menu->setEditTriggers(QAbstractItemView::NoEditTriggers);//不能编辑
    /*输出菜单至界面*/
    for (i = 0;i<all_food.size();i++)
    {
        model_menu2->setItem(i, 0, new QStandardItem(all_food[i].show_food_name()));//输出菜品名字
        model_menu2->setItem(i, 1, new QStandardItem(QString::number(all_food[i].show_food_price(),10)));//价格
        model_menu2->setItem(i, 2, new QStandardItem("★★★★★"));//评分
    }
    ui->tableView_menu->setModel(model_menu2);//讲model与tableview关联

    ui->tableView_menu->setColumnWidth(0,184);//设置列宽
    ui->tableView_menu->setColumnWidth(1,86);
    ui->tableView_menu->setColumnWidth(2,86);


    model_orders->setHorizontalHeaderItem(0,new QStandardItem(QObject::tr("OrderID")));
    model_orders->setHorizontalHeaderItem(1,new QStandardItem(QObject::tr("Address")));
    model_orders->setHorizontalHeaderItem(2,new QStandardItem(QObject::tr("Amount")));
    model_orders->setHorizontalHeaderItem(3,new QStandardItem(QObject::tr("state")));
    model_orders->setHorizontalHeaderItem(4,new QStandardItem(QObject::tr("Customer")));
    model_orders->setHorizontalHeaderItem(5,new QStandardItem(QObject::tr("Deliver")));
    ui->tableView_orders ->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableView_orders->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableView_orders->setModel(model_orders);

    ui->tableView_orders->setColumnWidth(0,50);
    ui->tableView_orders->setColumnWidth(1,200);
    ui->tableView_orders->setColumnWidth(2,50);
    ui->tableView_orders->setColumnWidth(3,80);
    ui->tableView_orders->setColumnWidth(4,80);
    ui->tableView_orders->setColumnWidth(5,80);

    set_view_orders();

    model_scy->setHorizontalHeaderItem(0,new QStandardItem(QObject::tr("ID")));
    model_scy->setHorizontalHeaderItem(1,new QStandardItem(QObject::tr("Name")));
    model_scy->setHorizontalHeaderItem(2,new QStandardItem(QObject::tr("Delivering order")));
    model_scy->setHorizontalHeaderItem(3,new QStandardItem(QObject::tr("Amount count")));
    model_scy->setHorizontalHeaderItem(4,new QStandardItem(QObject::tr("Order count")));
    ui->tableView_scy ->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableView_scy->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableView_scy->setModel(model_scy);
    set_view_scy();
}
void SameSizeLayoutSnapshotChangeDelegateBase::_changeSnapshotImplementation(WidgetListSnapshot sourceSnapshot, WidgetListSnapshot targetSnapshot,
                                                                       SameSizeHorizontalLayoutingInformations layoutingInformations)
{
#ifdef ENABLE_SNAPSHOT_HANDLING_LOGGING
    DLogS << "_changeSnapshotImplementation";
#endif
    DynamicDelegateBasedHighPerformanceSameSizeLayoutBase *castedParentLayout = this->getCastedParentLayout();
    if(castedParentLayout == NULL) {
        WLog(" ! Cannot get or cast Parent layout - cannot perform the snapshot-change");
        return;
    }

    QList<ItemMovedData> movedItems;
    //QString targetSnapshotItem;
    //QString sourceSnapshotItem;
    QList<QWidget *> targetSnapshotOrderedItems = targetSnapshot.getOrderedItems();
    QList<QWidget *> sourceSnapshotOrderedItems = sourceSnapshot.getOrderedItems();
    int targetSnapshotItemCount = targetSnapshotOrderedItems.size();
    int sourceSnapshotItemCount = sourceSnapshotOrderedItems.size();

    //
    // scan for added or moved target-items
#ifdef ENABLE_SNAPSHOT_HANDLING_LOGGING
    DLog(" -- target");
    DLogS << " targetSnapshotOrderedItems cnt: " << targetSnapshotItemCount;
#endif
    for(int i = 0; i < targetSnapshotItemCount; i++)
    {
        bool isFound = false;
        for(int j = 0; j < sourceSnapshotItemCount; j++)
        {
            if(targetSnapshotOrderedItems[i] == sourceSnapshotOrderedItems[j])
            {
                isFound = true;

                // check it's position
                if(i != j)
                {
                    // it's position is changed
                    movedItems << ItemMovedData(targetSnapshotOrderedItems[i], j, i);
                }

                break;
            }
        }

        if(!isFound)
        {
            // it's not in the source, so add it
            QWidget *notYetPresentedWidget = targetSnapshotOrderedItems[i];
            if(notYetPresentedWidget != NULL)
            {
                // to ensure it will be in the right place also add a move
                //movedItems << ItemMovedData(targetSnapshotOrderedItems[i], 0, i);
                int idx = i;

#if 0
                int rowIndex = idx % layoutingInformations.getItemsPerRowCount();
                int columnIndex = 0;
                if(layoutingInformations.getItemsPerRowCount() > 0) {
                    columnIndex = floor((double)idx / (double)layoutingInformations.getItemsPerRowCount());
                }

                //QPoint thePos = QPoint(idx * layoutInformations.getItemSize().width(), layoutInformations.getItemPositionY());
//                QPoint thePos = QPoint(idx * GuiConfigurations::iconImagePresenterWidgetSizeHint().width(), // !warning! hack alert!
//                                       layoutInformations.getItemPositionY());

                QPoint thePos = QPoint(rowIndex * layoutingInformations.getItemSize().width(), columnIndex * layoutingInformations.getItemSize().height());
#endif
                QRect itemGeom = castedParentLayout->getItemGeometryByIndexAndCalculatedMargins(idx);

                notYetPresentedWidget->setGeometry(itemGeom);

                notYetPresentedWidget->show(); // set it visible
                this->addShowAnimationToCurrentAnimationGroup(notYetPresentedWidget, layoutingInformations);

#ifdef ENABLE_SNAPSHOT_HANDLING_LOGGING
                DLog("SHOW Widget, with index:") << idx;
#endif
            }
            else
            {
                WLog(" !!! icon presenter not found - in changeSnapshot");
            }
        }
    }

    //
    // have to scan for elements which are removed or hidden (presented in source but not in the target)
#ifdef ENABLE_SNAPSHOT_HANDLING_LOGGING
    DLog(" -- source");
    DLogS << " sourceSnapshotItemCount cnt: " << sourceSnapshotItemCount;
#endif
    for(int i = 0; i < sourceSnapshotItemCount; i++)
    {
        bool isFound = false;
        for(int j = 0; j < targetSnapshotItemCount; j++)
        {
            if(sourceSnapshotOrderedItems[i] == targetSnapshotOrderedItems[j])
            {
                isFound = true;
                break;
            }
        }

        if(!isFound)
        {
            // it's not in the target, so hide it
            QWidget *hideThisWidget = sourceSnapshotOrderedItems[i];

            if(hideThisWidget != NULL)
            {
                this->_addToCurrentlyHidingItems(hideThisWidget);
                this->addHideAnimationToCurrentAnimationGroup(hideThisWidget);

#ifdef ENABLE_SNAPSHOT_HANDLING_LOGGING
                DLog("HIDE Widget, with index:") << i;
#endif
            }
            else
            {
                WLog(" !!! icon presenter not found - in changeSnapshot");
            }
        }
    }

    //
    // make the move animations
    if(movedItems.size() > 0)
    {
        for(int i = 0; i < movedItems.size(); i++)
        {
//            QString item = movedItems[i].getItem();
//            IconPresenterWidget *iconPresenter = this->iconPresenterListDelegate->getIconPresenterWidgetByTitle(item);
            QWidget *moveThisWidget = movedItems[i].getItem();
            if(moveThisWidget != NULL)
            {
                int oldIndex = movedItems[i].getOldIndex();
                int newIndex = movedItems[i].getNewIndex();

#if 0
                int oldRowIndex = oldIndex % layoutingInformations.getItemsPerRowCount();
                int oldColumnIndex = 0;
                if(layoutingInformations.getItemsPerRowCount() > 0) {
                    oldColumnIndex = floor((double)oldIndex / (double)layoutingInformations.getItemsPerRowCount());
                }

                int newRowIndex = newIndex % layoutingInformations.getItemsPerRowCount();
                int newColumnIndex = 0;
                if(layoutingInformations.getItemsPerRowCount() > 0) {
                    newColumnIndex = floor((double)newIndex / (double)layoutingInformations.getItemsPerRowCount());
                }

                //QPoint thePos = QPoint(idx * layoutInformations.getItemSize().width(), layoutInformations.getItemPositionY());
//                QPoint thePos = QPoint(idx * GuiConfigurations::iconImagePresenterWidgetSizeHint().width(), // !warning! hack alert!
//                                       layoutInformations.getItemPositionY());

                QPoint oldPos = QPoint(oldRowIndex * layoutingInformations.getItemSize().width(), oldColumnIndex * layoutingInformations.getItemSize().height());
                QPoint newPos = QPoint(newRowIndex * layoutingInformations.getItemSize().width(), newColumnIndex * layoutingInformations.getItemSize().height());

//                QPoint oldPos = QPoint(oldIndex * layoutInformations.getItemSize().width(), layoutInformations.getItemPositionY());
//                QPoint newPos = QPoint(newIndex * layoutInformations.getItemSize().width(), layoutInformations.getItemPositionY());
#endif

                QRect oldGeom = castedParentLayout->getItemGeometryByIndexAndCalculatedMargins(oldIndex);
                QRect newGeom = castedParentLayout->getItemGeometryByIndexAndCalculatedMargins(newIndex);

#if 0
                QPropertyAnimation *animation = new QPropertyAnimation(iconPresenter, "geometry");
                animation->setDuration(GuiConfigurations::iconPresenterMoveAnimationDuration());
                animation->setStartValue(QRect(oldPos, iconPresenter->geometry().size()));
                animation->setEndValue(QRect(newPos, iconPresenter->geometry().size()));
                animation->setEasingCurve(QEasingCurve::InOutQuart);
                animGroup->addAnimation(animation);
#endif

                //DLog() << " !! MOVE" << oldPos.x() << oldPos.y() << newPos.x() << newPos.y();
                this->addMoveAnimationToCurrentAnimationGroup(moveThisWidget, oldGeom.topLeft(), newGeom.topLeft());

#ifdef ENABLE_SNAPSHOT_HANDLING_LOGGING
                DLog("MOVE Widget, with from index to index:") << oldIndex << newIndex;
#endif
            }
            else
            {
                WLog(" !!! icon presenter not found - in changeSnapshot, move animations");
            }
        }
    }
}
void Widget::resizeEvent(QResizeEvent *event)
{
	if(m_layout->count()) {
		QRect desktop = qApp->desktop()->availableGeometry();

		bool animate = (x() < 0) && m_animation;
		if(!animate) {
			switch(m_position) {
				case TopLeft:
					move(desktop.left(), desktop.top());
				break;

				case TopRight:
					move(desktop.right() - width(), desktop.top());
				break;

				case BottomLeft:
					move(desktop.left(), desktop.bottom() - height());
				break;

				case BottomRight:
					move(desktop.right() - width(), desktop.bottom() - height());
				break;
			}
		} else {
			QPoint target;
			QPropertyAnimation *animation = new QPropertyAnimation(this, "pos");

			switch(m_position) {
				case TopLeft:
					move(desktop.left(), desktop.top() - height());
					target = QPoint(desktop.left(), desktop.top());
				break;

				case TopRight:
					move(desktop.right() - width(), desktop.top() - height());
					target = QPoint(desktop.right() - width(), desktop.top());
				break;

				case BottomLeft:
				{
					move(desktop.left(), desktop.bottom());
					target = QPoint(desktop.left(), desktop.bottom() - height());
				}
				break;

				case BottomRight:
				{
					move(desktop.right() - width(), desktop.bottom());
					target = QPoint(desktop.right() - width(), desktop.bottom() - height());
				}
				break;
			}

			animation->setStartValue(pos());
			animation->setEndValue(target);
			animation->setDuration(150);
			animation->start(QPropertyAnimation::DeleteWhenStopped);
		}
	}
}
void Manager::on_pushButton_clicked()
{
    progressBar->setValue(0);
    Database conn;
    QSqlQueryModel * model = new QSqlQueryModel();

    conn.connOpen("Inventory");
    QSqlQuery * qry = new QSqlQuery(conn.mydb);


    QString Band_Name = ui->lineEdit_band_name->text();
    QString Album = ui->lineEdit_Album->text();
    QString Type = ui->comboBox_Type->currentText();
    qint32 minPrice = 0;
    if(!ui->lineEdit_price_min->text().isEmpty())
        minPrice = ui->lineEdit_price_min->text().toInt();
    qint32 maxPrice = 99999;
    progressBar->setValue(25);
    if(!ui->lineEdit_price_max->text().isEmpty())
        maxPrice = ui->lineEdit_price_max->text().toInt();

    if(Type == "Select a Type")
        Type = "";

    qint32 xs_int = 999;
    qint32 s_int = 999;
    qint32 m_int = 999;
    qint32 l_int = 999;
    qint32 xl_int = 999;
    qint32 xxl_int = 999;
    progressBar->setValue(50);
    if(!ui->checkBox_XS->isChecked() && !ui->checkBox_S->isChecked() && !ui->checkBox_M->isChecked() &&
            !ui->checkBox_L->isChecked() && !ui->checkBox_XL->isChecked() && !ui->checkBox_xxl->isChecked())
    {
        QString queryString;
        QTextStream queryStream(&queryString);
        queryStream
                << "SELECT * FROM Inventory WHERE \"Price\" >= '"
                << minPrice << "' AND \"Price\" <= '"
                << maxPrice << "' AND Band LIKE '%"+Band_Name+"%' AND Album LIKE '%"+Album+"%' AND Type LIKE '"+Type+"%'";
        qry->prepare(queryString);
    }
    else
    {
        if(ui->checkBox_XS->isChecked())
            xs_int = 0;
        if(ui->checkBox_S->isChecked())
            s_int = 0;
        if(ui->checkBox_M->isChecked())
            m_int = 0;
        if(ui->checkBox_L->isChecked())
            l_int = 0;
        if(ui->checkBox_XL->isChecked())
            xl_int = 0;
        if(ui->checkBox_xxl->isChecked())
            xxl_int = 0;

        QString queryString;
        QTextStream queryStream(&queryString);

        queryStream
                << "SELECT * FROM Inventory WHERE \"XS(Quantity)\" > '"
                   << xs_int << "' AND \"Price\" >= '"
                   << minPrice << "' AND \"Price\" <= '"
                   << maxPrice << "' AND Band LIKE '%" << Band_Name << "%' AND Album LIKE '%"+Album+"%' AND Type LIKE '"+Type+"%' OR \"S(Quantity)\" > '"
                   << s_int << "' AND \"Price\" >= '"
                   << minPrice << "' AND \"Price\" <= '"
                   << maxPrice << "' AND Band LIKE '%" << Band_Name << "%' AND Album LIKE '%"+Album+"%' AND Type LIKE '"+Type+"%' OR \"M(Quantity)\" > '"
                   << m_int << "' AND \"Price\" >= '"
                   << minPrice << "' AND \"Price\" <= '"
                   << maxPrice << "' AND Band LIKE '%" << Band_Name << "%' AND Album LIKE '%"+Album+"%' AND Type LIKE '"+Type+"%' OR \"L(Quantity)\" > '"
                   << l_int << "' AND \"Price\" >= '"
                   << minPrice << "' AND \"Price\" <= '"
                   << maxPrice << "' AND Band LIKE '%" << Band_Name << "%' AND Album LIKE '%"+Album+"%' AND Type LIKE '"+Type+"%' OR \"XL(Quantity)\" > '"
                   << xl_int << "' AND \"Price\" >= '"
                   << minPrice << "' AND \"Price\" <= '"
                   << maxPrice << "' AND Band LIKE '%" << Band_Name << "%' AND Album LIKE '%"+Album+"%' AND Type LIKE '"+Type+"%' OR \"XXL(Quantity)\" > '"
                   << xxl_int << "' AND \"Price\" >= '"
                   << minPrice << "' AND \"Price\" <= '"
                   << maxPrice << "' AND Band LIKE '%" << Band_Name << "%' AND Album LIKE '%"+Album+"%' AND Type LIKE '"+Type+"%'";
        qry->prepare(queryString);

    }
    progressBar->setValue(75);

    if(!qry->exec())
    {
        QMessageBox::critical(this, tr("Error"), qry->lastError().text());
    }
    model->setQuery(*qry);
    ui->tableView_Master->setModel(model);

    qint32 i = (model->rowCount());
    QString str;

    str.append(QString("%1").arg(i));
    progressBar->setValue(100);

    QGraphicsOpacityEffect* opacityEffect = new QGraphicsOpacityEffect(this);
         opacityEffect->setOpacity(1.0);
         ui->statusbar->setGraphicsEffect(opacityEffect);
         QPropertyAnimation* anim = new QPropertyAnimation(this);
         anim->setTargetObject(opacityEffect);
         anim->setPropertyName("opacity");
         anim->setDuration(4000);
         anim->setStartValue(opacityEffect->opacity());
         anim->setEndValue(0);
         anim->setEasingCurve(QEasingCurve::OutQuad);
         anim->start(QAbstractAnimation::DeleteWhenStopped);


    ui->label_results->setText(str + " Results Found!");

}
Exemple #21
0
void slideTop2BottomWidget(QWidget *top, QWidget *bottom, int delay)
{
    bottom->show();
    top->show();
    bottom->resize(top->size());

    QRect topStart = QRect(0, 0, top->width(), top->height());
    QRect topEnd = topStart;
    topEnd.moveTo(0, top->height());

    QPropertyAnimation *animation = new QPropertyAnimation(top, "geometry");
    animation->setDuration(delay);
    animation->setEasingCurve(QEasingCurve::InOutCubic);
    animation->setStartValue(topStart);
    animation->setEndValue(topEnd);
    animation->start();
    animation->connect(animation, &QPropertyAnimation::finished,
                       animation, &QPropertyAnimation::deleteLater);
    animation->connect(animation, &QPropertyAnimation::finished,
                       top, &QWidget::hide);

    QRect bottomStart = QRect(0, -top->height(), bottom->width(), bottom->height());
    QRect bottomEnd = bottomStart;
    bottomEnd.moveBottom(top->height() - 1);

    QPropertyAnimation *animation2 = new QPropertyAnimation(bottom, "geometry");
    animation2->setEasingCurve(QEasingCurve::InOutCubic);
    animation2->setDuration(delay);
    animation2->setStartValue(bottomStart);
    animation2->setEndValue(bottomEnd);
    animation2->start();
    animation2->connect(animation2, &QPropertyAnimation::finished,
                        animation2, &QPropertyAnimation::deleteLater);

    auto bottomOpacity = new QGraphicsOpacityEffect(bottom);
    bottom->setGraphicsEffect(bottomOpacity);
    bottomOpacity->setOpacity(0);

    QPropertyAnimation *animation3 = new QPropertyAnimation(bottomOpacity, "opacity");
    animation3->setEasingCurve(QEasingCurve::InCubic);
    animation3->setDuration(delay);
    animation3->setStartValue(0);
    animation3->setEndValue(1);
    animation3->start();
    animation3->connect(animation3, &QPropertyAnimation::finished,
                        animation3, &QPropertyAnimation::deleteLater);
    animation3->connect(animation3, &QPropertyAnimation::finished,
    bottom, [ = ]() {
        bottom->setGraphicsEffect(nullptr);
    });


    auto topOpacity = new QGraphicsOpacityEffect(top);
    top->setGraphicsEffect(topOpacity);
    topOpacity->setOpacity(0.99);

    QPropertyAnimation *animation4 = new QPropertyAnimation(topOpacity, "opacity");
    animation4->setEasingCurve(QEasingCurve::InCubic);
    animation4->setDuration(delay);
    animation4->setStartValue(0.99);
    animation4->setEndValue(0);
    animation4->start();
    animation4->connect(animation4, &QPropertyAnimation::finished,
                        animation4, &QPropertyAnimation::deleteLater);
    animation4->connect(animation4, &QPropertyAnimation::finished,
    bottom, [ = ]() {
        top->setGraphicsEffect(nullptr);
    });
}
Exemple #22
0
// updateFrom is the item that has changed---all children must be recomputed
// if invalid, redo the whole breadcrumb
void
Breadcrumb::updateButtons( const QModelIndex& updateFrom )
{
//     qDebug() << "Updating buttons:" << updateFrom.data();
    int cur = 0;
    QModelIndex idx = updateFrom;
    for ( int i = 0; i < m_buttons.count(); i++ )
    {
//         qDebug() << "Checking if this breadcrumb item changed:" << m_buttons[ i ]->currentIndex().data() << updateFrom.data() << ( m_buttons[ i ]->currentIndex() != updateFrom);
        if ( m_buttons[ i ]->currentIndex() == updateFrom )
        {
            cur = i;
            break;
        }
    }

    // We set the parent index, so go up one
    idx = idx.parent();

    // Ok, changed all indices that are at cur or past it. lets update them
    // When we get to the "end" of the tree, the leaf node is the chart itself
//     qDebug() << "DONE and beginning iteration:" << idx.data();
    while ( m_model->rowCount( idx ) > 0 )
    {
//         qDebug() << "CHANGED AND iterating:" << idx.data();
        BreadcrumbButton* btn = 0;
        if ( m_buttons.size() <= cur )
        {
            // We have to create a new button, doesn't exist yet
            btn = new BreadcrumbButton( this, m_model );
            connect( btn, SIGNAL( currentIndexChanged( QModelIndex ) ), this, SLOT( breadcrumbComboChanged( QModelIndex ) ) );

            m_buttonlayout->addWidget( btn );
            btn->show();

            // Animate all buttons except the first
            if ( m_buttons.count() > 0 && isVisible() )
            {
                QPropertyAnimation* animation = new QPropertyAnimation( btn, "pos" );
                animation->setDuration( 300 );
                animation->setStartValue( m_buttons.last()->pos() );
                animation->setEndValue( btn->pos() );
                animation->start( QAbstractAnimation::DeleteWhenStopped );
            }

            m_buttons.append( btn );
        }
        else
        {
            // Got a button already, we just want to change the contents
            btn = m_buttons[ cur ];
        }

        // The children of idx are what populates this combobox.
        // It takes care of setting the default/user-populated value.
        btn->setParentIndex( idx );

        // Repeat with children
        idx = btn->currentIndex();

        cur++;
    }

    // extra buttons to delete! (cur is 0-indexed)
    while ( m_buttons.size() > cur )
    {
        BreadcrumbButton* b = m_buttons.takeLast();
        m_buttonlayout->removeWidget( b );
        b->deleteLater();
    }

    // Now we're at the leaf, lets activate the chart
    emit activateIndex( idx );
}
void OverviewDockWidget::addOverviewShape(OwlClass *cls)
{
    qreal x = cls->overviewshape->pos().rx();
    qreal y = cls->overviewshape->pos().ry();
    int stat = cls->overviewshape->getStatus();

    int gid = getGItemID(cls->shortname);
    if(gid!=-1){
        if(stat==gitem_status[gid]){
            QPropertyAnimation * ani = new QPropertyAnimation(gitems[gid], "pos");
            ani->setDuration(600);
            ani->setStartValue(oripos[gid]);
            qreal ex = oripos[gid].rx() + (x - oriabspos[gid].rx());
            qreal ey = oripos[gid].ry() + (y - oriabspos[gid].ry());
            ani->setEndValue(QPointF(ex, ey));
            oripos[gid]=QPointF(ex,ey);
            oriabspos[gid]=QPointF(x,y);
            ani_group->addAnimation(ani);

            return;
        }
        else{
            m_scene->removeItem(gitems[gid]);
            gitems.removeAt(gid);
            gitem_status.removeAt(gid);
            oripos.removeAt(gid);
            oriabspos.removeAt(gid);
        }
    }

    OverviewShape *its = NULL;
    switch(stat)
    {
    case OverviewClassShape::STATUS_Hide:
        break;
    case OverviewClassShape::STATUS_OutDetailview:
//        it = m_scene->addRect(x-2,y-2,4,4,QPen(QColor("black")),QBrush(QColor("gray")));
        its = new OverviewShape();
        its->setRect(x-2,y-2,4,4);
        its->setPen(QPen(QColor("black")));
        its->setBrush(QBrush(QColor("gray")));
        m_scene->addItem(its);

//        cout<<"x,y = "<<x<<","<<y<<endl;
//        cout<<"POS = "<<its->pos().rx()<<","<<its->pos().ry()<<endl;

        break;
    case OverviewClassShape::STATUS_InDetailview_Default:
//        it = m_scene->addRect(x-3,y-3,6,6,QPen(QColor("black")),QBrush(OwlClass::CLASS_SHAPE_COLOR));
        its = new OverviewShape();
        its->setRect(x-3,y-3,6,6);
        its->setPen(QPen(QColor("black")));
        its->setBrush(QBrush(OwlClass::CLASS_SHAPE_COLOR));
        m_scene->addItem(its);

        break;
    case OverviewClassShape::STATUS_InDetailview_Focused:
//        it = m_scene->addRect(x-3,y-3,6,6,QPen(QColor("black")),QBrush(OwlClass::CLASS_SHAPE_FOCUSED_COLOR));
        its = new OverviewShape();
        its->setRect(x-3,y-3,6,6);
        its->setPen(QPen(QColor("black")));
        its->setBrush(QBrush(OwlClass::CLASS_SHAPE_FOCUSED_COLOR));
        m_scene->addItem(its);
        break;
    case OverviewClassShape::STATUS_InDetailview_SubFocused:
//        it = m_scene->addRect(x-3,y-3,6,6,QPen(QColor("black")),QBrush(OwlClass::SUBCLASS_SHAPE_FOCUSED_COLOR));
        its = new OverviewShape();
        its->setRect(x-3,y-3,6,6);
        its->setPen(QPen(QColor("black")));
        its->setBrush(QBrush(OwlClass::SUBCLASS_SHAPE_FOCUSED_COLOR));
        m_scene->addItem(its);
        break;
    case OverviewClassShape::STATUS_InDetailview_SuperFocused:
//        it = m_scene->addRect(x-3,y-3,6,6,QPen(QColor("black")),QBrush(OwlClass::SUPERCLASS_SHAPE_FOCUSED_COLOR));
        its = new OverviewShape();
        its->setRect(x-3,y-3,6,6);
        its->setPen(QPen(QColor("black")));
        its->setBrush(QBrush(OwlClass::SUPERCLASS_SHAPE_FOCUSED_COLOR));
        m_scene->addItem(its);
        break;
    case OverviewClassShape::STATUS_COMPACT:
    {
        QGraphicsTextItem * io = new QGraphicsTextItem();
        io->setPos(x-8,y-8);
        QFont font;
        font.setPixelSize(7);
        font.setBold(false);
        font.setFamily("Calibri");
        io->setFont(font);
        io->setDefaultTextColor(QColor("black"));

        QString s = QString::number(cls->subclasses.size());
        io->setPlainText(s);

        QGraphicsItem * it = m_scene->addRect(x-6,y-4,12,8,QPen(QColor("black")),QBrush(QColor("pink"),Qt::LinearGradientPattern));
        m_scene->addItem(io);
        this->lines.append(io);
        this->lines.append(it);

        for(int i=0;i<cls->subclasses.size();i++){
            double sx = x+0.0001*i;
            double sy = y+0.0001*i;
            cls->subclasses[i]->overviewshape->setCentrePos(QPointF(sx,sy));
            this->addOverviewShape(cls->subclasses[i]);
            int gidx = getGItemID(cls->subclasses[i]->shortname);
            if(gidx!=-1)this->hideclasses.append(gitems[gidx]);
        }
    }
        break;
    default:
        break;
    }
    if(its != NULL){
        its->setToolTip(cls->shortname);
        oripos.append(its->pos());
        oriabspos.append(QPointF(x,y));
        gitems.append(its);
        gitem_status.append(stat);
    }
}
Exemple #24
0
//! [10]
Robot::Robot(QGraphicsItem *parent)
    : RobotPart(parent)
{
    setFlag(ItemHasNoContents);

    QGraphicsObject *torsoItem = new RobotTorso(this);
    QGraphicsObject *headItem = new RobotHead(torsoItem);
    QGraphicsObject *upperLeftArmItem = new RobotLimb(torsoItem);
    QGraphicsObject *lowerLeftArmItem = new RobotLimb(upperLeftArmItem);
    QGraphicsObject *upperRightArmItem = new RobotLimb(torsoItem);
    QGraphicsObject *lowerRightArmItem = new RobotLimb(upperRightArmItem);
    QGraphicsObject *upperRightLegItem = new RobotLimb(torsoItem);
    QGraphicsObject *lowerRightLegItem = new RobotLimb(upperRightLegItem);
    QGraphicsObject *upperLeftLegItem = new RobotLimb(torsoItem);
    QGraphicsObject *lowerLeftLegItem = new RobotLimb(upperLeftLegItem);
//! [10]

//! [11]
    headItem->setPos(0, -18);
    upperLeftArmItem->setPos(-15, -10);
    lowerLeftArmItem->setPos(30, 0);
    upperRightArmItem->setPos(15, -10);
    lowerRightArmItem->setPos(30, 0);
    upperRightLegItem->setPos(10, 32);
    lowerRightLegItem->setPos(30, 0);
    upperLeftLegItem->setPos(-10, 32);
    lowerLeftLegItem->setPos(30, 0);
//! [11]

//! [12]
    QParallelAnimationGroup *animation = new QParallelAnimationGroup(this);

    QPropertyAnimation *headAnimation = new QPropertyAnimation(headItem, "rotation");
    headAnimation->setStartValue(20);
    headAnimation->setEndValue(-20);
    QPropertyAnimation *headScaleAnimation = new QPropertyAnimation(headItem, "scale");
    headScaleAnimation->setEndValue(1.1);
    animation->addAnimation(headAnimation);
    animation->addAnimation(headScaleAnimation);
//! [12]

    QPropertyAnimation *upperLeftArmAnimation = new QPropertyAnimation(upperLeftArmItem, "rotation");
    upperLeftArmAnimation->setStartValue(190);
    upperLeftArmAnimation->setEndValue(180);
    animation->addAnimation(upperLeftArmAnimation);

    QPropertyAnimation *lowerLeftArmAnimation = new QPropertyAnimation(lowerLeftArmItem, "rotation");
    lowerLeftArmAnimation->setStartValue(50);
    lowerLeftArmAnimation->setEndValue(10);
    animation->addAnimation(lowerLeftArmAnimation);

    QPropertyAnimation *upperRightArmAnimation = new QPropertyAnimation(upperRightArmItem, "rotation");
    upperRightArmAnimation->setStartValue(300);
    upperRightArmAnimation->setEndValue(310);
    animation->addAnimation(upperRightArmAnimation);

    QPropertyAnimation *lowerRightArmAnimation = new QPropertyAnimation(lowerRightArmItem, "rotation");
    lowerRightArmAnimation->setStartValue(0);
    lowerRightArmAnimation->setEndValue(-70);
    animation->addAnimation(lowerRightArmAnimation);

    QPropertyAnimation *upperLeftLegAnimation = new QPropertyAnimation(upperLeftLegItem, "rotation");
    upperLeftLegAnimation->setStartValue(150);
    upperLeftLegAnimation->setEndValue(80);
    animation->addAnimation(upperLeftLegAnimation);

    QPropertyAnimation *lowerLeftLegAnimation = new QPropertyAnimation(lowerLeftLegItem, "rotation");
    lowerLeftLegAnimation->setStartValue(70);
    lowerLeftLegAnimation->setEndValue(10);
    animation->addAnimation(lowerLeftLegAnimation);

    QPropertyAnimation *upperRightLegAnimation = new QPropertyAnimation(upperRightLegItem, "rotation");
    upperRightLegAnimation->setStartValue(40);
    upperRightLegAnimation->setEndValue(120);
    animation->addAnimation(upperRightLegAnimation);

    QPropertyAnimation *lowerRightLegAnimation = new QPropertyAnimation(lowerRightLegItem, "rotation");
    lowerRightLegAnimation->setStartValue(10);
    lowerRightLegAnimation->setEndValue(50);
    animation->addAnimation(lowerRightLegAnimation);

    QPropertyAnimation *torsoAnimation = new QPropertyAnimation(torsoItem, "rotation");
    torsoAnimation->setStartValue(5);
    torsoAnimation->setEndValue(-20);
    animation->addAnimation(torsoAnimation);

//! [13]
    for (int i = 0; i < animation->animationCount(); ++i) {
        QPropertyAnimation *anim = qobject_cast<QPropertyAnimation *>(animation->animationAt(i));
        anim->setEasingCurve(QEasingCurve::SineCurve);
        anim->setDuration(2000);
    }

    animation->setLoopCount(-1);
    animation->start();
//! [13]
}
void CrashReportDialog::sendReport()
{
    if (m_uploadReply)
        return;

    if (!m_allowReport->isChecked())
    {
        done(m_finalResult);
        return;
    }

    QString platform =
#if defined(Q_OS_WIN)
                       QLatin1String("windows");
#elif defined(Q_OS_MAC)
                       QLatin1String("mac");
#elif defined(Q_OS_LINUX)
                       QLatin1String("linux");
#else
                       QLatin1String("unknown");
#endif

    QNetworkAccessManager *nam = new QNetworkAccessManager(this);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    QUrl queryUrl(m_reportUrl);
#else
    QUrlQuery queryUrl(m_reportUrl);
    QUrl url;
#endif
    queryUrl.addQueryItem(QLatin1String("version"), qApp->applicationVersion());
    queryUrl.addQueryItem(QLatin1String("platform"), platform);
    if (!m_emailInput->text().isEmpty())
        queryUrl.addQueryItem(QLatin1String("email"), m_emailInput->text());

    if (!m_dumpFile.exists() || !m_dumpFile.open(QIODevice::ReadOnly))
    {
        queryUrl.addQueryItem(QLatin1String("dump"), QLatin1String("0"));
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
        url.setQuery(queryUrl);
#endif
        m_uploadReply = nam->get(QNetworkRequest(url));
    }
    else
    {
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
        url.setQuery(queryUrl);
#endif
        QNetworkRequest req(url);
        const char *boundary = "UPLOADDUMP";
        req.setHeader(QNetworkRequest::ContentTypeHeader, QByteArray("multipart/form-data; boundary=") + boundary);

        QByteArray data;
        data.append("--");
        data.append(boundary);
        data.append("\r\ncontent-disposition: form-data; name=\"dump\"; filename=\"temp.dmp\"\r\nContent-Transfer-Encoding: binary\r\nContent-Length: ");
        data.append(m_dumpFile.size());
        data.append("\r\nContent-type: application/x-octet-stream\r\n\r\n");
        data.append(m_dumpFile.readAll());
        data.append("\r\n--");
        data.append(boundary);
        data.append("--\r\n");
        m_dumpFile.close();

        m_uploadReply = nam->post(req, data);
    }

    connect(m_uploadReply, SIGNAL(finished()), SLOT(uploadFinished()));
    bool ok = connect(m_uploadReply, SIGNAL(uploadProgress(qint64,qint64)), SLOT(setUploadProgress(qint64)));
    Q_UNUSED(ok);
    Q_ASSERT(ok);
    m_uploadProgress->setMaximum((int)m_dumpFile.size());

    m_stackLayout->setCurrentIndex(1);

    setFixedHeight(QWIDGETSIZE_MAX);
    QPropertyAnimation *resizeAnimation = new QPropertyAnimation(this, "size");
    resizeAnimation->setEndValue(QSize(width(), minimumSizeHint().height()));
    resizeAnimation->setDuration(150);
    resizeAnimation->setEasingCurve(QEasingCurve::InQuad);
    resizeAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
Exemple #26
0
void Barbel::Scene::initScene()
{
    //Setup Framegraph
    if (m_frameGraph == Q_NULLPTR)
        m_frameGraph = new Qt3D::QFrameGraph();
    if (m_forwardRenderer == Q_NULLPTR)
        m_forwardRenderer = new Qt3D::QForwardRenderer();

    m_forwardRenderer->setClearColor(Qt::black);
    m_frameGraph->setActiveFrameGraph(m_forwardRenderer);
    m_rootEntity->addComponent(m_frameGraph);

    //Test Objects
    Barbel::Player *player = new Barbel::Player(m_rootEntity);
    player->setTranslation(QVector3D(0.0f, 0.0f, 0.0f));
    setActiveCamera(player->camera());
    activeCamera()->lens()->setAspectRatio(m_cameraAspectRatio);


    QVector3D startPostion(0.0f, 0.0f, 0.0f);
    QVector3D secondPosition(10.0f, 10.0f, 10.0f);
    QVector3D thirdPosition(-10.0f, 0.0f, 10.0f);

    QVector3D startAngles(0.0f, 0.0f, 0.0f);
    QVector3D secondAngles(45.0f, 150.0f, 0.0f);
    QVector3D thirdAngles(0.0f, 200.0f, 0.0f);
    QVector3D finalAngles(0.0f, 360.0f, 0.0f);


    QSequentialAnimationGroup *animationGroup = new QSequentialAnimationGroup(this);

    QParallelAnimationGroup *parallelAnimationGroup1 = new QParallelAnimationGroup(this);

    QPropertyAnimation *animation = new QPropertyAnimation(player, "translation", this);
    animation->setDuration(5000);
    animation->setStartValue(startPostion);
    animation->setEndValue(secondPosition);
    parallelAnimationGroup1->addAnimation(animation);

    QPropertyAnimation *rotationAnimation = new QPropertyAnimation(player, "rotation", this);
    rotationAnimation->setDuration(5000);
    rotationAnimation->setStartValue(startAngles);
    rotationAnimation->setEndValue(secondAngles);
    parallelAnimationGroup1->addAnimation(rotationAnimation);

    animationGroup->addAnimation(parallelAnimationGroup1);

    QParallelAnimationGroup *parallelAnimationGroup2 = new QParallelAnimationGroup(this);

    animation = new QPropertyAnimation(player, "translation", this);
    animation->setDuration(5000);
    animation->setStartValue(secondPosition);
    animation->setEndValue(thirdPosition);
    parallelAnimationGroup2->addAnimation(animation);

    rotationAnimation = new QPropertyAnimation(player, "rotation", this);
    rotationAnimation->setDuration(5000);
    rotationAnimation->setStartValue(secondAngles);
    rotationAnimation->setEndValue(thirdAngles);
    parallelAnimationGroup2->addAnimation(rotationAnimation);

    animationGroup->addAnimation(parallelAnimationGroup2);
    QParallelAnimationGroup *parallelAnimationGroup3 = new QParallelAnimationGroup(this);

    animation = new QPropertyAnimation(player, "translation", this);
    animation->setDuration(5000);
    animation->setStartValue(thirdPosition);
    animation->setEndValue(startPostion);
    parallelAnimationGroup3->addAnimation(animation);

    rotationAnimation = new QPropertyAnimation(player, "rotation", this);
    rotationAnimation->setDuration(5000);
    rotationAnimation->setStartValue(thirdAngles);
    rotationAnimation->setEndValue(finalAngles);
    parallelAnimationGroup3->addAnimation(rotationAnimation);

    animationGroup->addAnimation(parallelAnimationGroup3);
    animationGroup->setLoopCount(-1);
    animationGroup->start();

    //Test Cubes
    Qt3D::QPhongMaterial *phongMaterial1 = new Qt3D::QPhongMaterial();
    phongMaterial1->setDiffuse(QColor(94, 141, 25));
    phongMaterial1->setSpecular(Qt::white);
    Qt3D::QPhongMaterial *phongMaterial2 = new Qt3D::QPhongMaterial();
    phongMaterial2->setDiffuse(QColor(129, 23, 71));
    phongMaterial2->setSpecular(Qt::white);

    for (int z = -5; z < 5; z++) {
        for (int y = -5; y < 5; y++) {
            for (int x = -5; x < 5; x++) {
                float xSize = (rand() % 10000) / 10000.0;
                float ySize = (rand() % 10000) / 10000.0;
                float zSize = (rand() % 10000) / 10000.0;
                Barbel::TestCube *cube = new TestCube(QVector3D(x, y, z), QVector3D(xSize, ySize, zSize), m_rootEntity);
                if (y % 2)
                    cube->addComponent(phongMaterial1);
                else
                    cube->addComponent(phongMaterial2);
            }
        }
    }
}
Exemple #27
0
        void EtherSceneController::StartLoginAnimation()
        {
            if (!login_animations_)
                return;

            login_animations_->clear();
            login_animations_->setDirection(QAbstractAnimation::Forward);

            // Get all Infocards
            QVector<View::InfoCard*> t_obj = top_menu_->GetObjects();
            t_obj += bottom_menu_->GetObjects();

            QPropertyAnimation *anim;
            foreach (View::InfoCard* card, t_obj)
            {
                // Animate opacity from current to 0 for every card except the selected cards
                if (card != last_active_bottom_card_ && card != last_active_top_card_)
                {
                    anim = new QPropertyAnimation(card, "opacity", login_animations_);
                    anim->setStartValue(card->opacity());
                    anim->setEndValue(0);
                    anim->setDuration(2000);
                    anim->setEasingCurve(QEasingCurve::InOutSine);
                    login_animations_->addAnimation(anim);
                }
            }

            // Fade animation for add remove widgets
            anim = new QPropertyAnimation(avatar_addremove_widget_, "opacity", login_animations_);
            anim->setStartValue(avatar_addremove_widget_->opacity());
            anim->setEndValue(0);
            anim->setDuration(2000);
            anim->setEasingCurve(QEasingCurve::InOutSine);
            login_animations_->addAnimation(anim);

            anim = new QPropertyAnimation(world_addremove_widget_, "opacity", login_animations_);
            anim->setStartValue(world_addremove_widget_->opacity());
            anim->setEndValue(0);
            anim->setDuration(2000);
            anim->setEasingCurve(QEasingCurve::InOutSine);
            login_animations_->addAnimation(anim);

            // Animate selected cards position
            QPropertyAnimation* anim1 = new QPropertyAnimation(last_active_top_card_, "pos", login_animations_);
            QPropertyAnimation* anim2 = new QPropertyAnimation(avatar_info_widget_, "pos", login_animations_);

            QPropertyAnimation* anim3 = new QPropertyAnimation(last_active_bottom_card_, "pos", login_animations_);
            QPropertyAnimation* anim4 = new QPropertyAnimation(world_info_widget_, "pos", login_animations_);

            qreal diff = avatar_info_widget_->mapRectToScene(avatar_info_widget_->rect()).bottom() - world_info_widget_->mapRectToScene(world_info_widget_->rect()).top();
            diff /=2;

            if (diff < 0)
                diff *= -1;

            // Calculate positions
            QPointF pos1 = last_active_top_card_->pos();
            pos1.setY(pos1.y() + diff + 3);

            QPointF pos2 = avatar_info_widget_->pos();
            pos2.setY(pos2.y() + diff + 3);

            QPointF pos3 = last_active_bottom_card_->pos();
            pos3.setY(pos3.y() - diff - 3);

            QPointF pos4 = world_info_widget_->pos();
            pos4.setY(pos4.y() - diff - 3);

            anim1->setStartValue(last_active_top_card_->pos());
            anim1->setEndValue(pos1);
            anim1->setDuration(2000);
            anim1->setEasingCurve(QEasingCurve::InOutSine);

            anim2->setStartValue(avatar_info_widget_->pos());
            anim2->setEndValue(pos2);
            anim2->setDuration(2000);
            anim2->setEasingCurve(QEasingCurve::InOutSine);

            anim3->setStartValue(last_active_bottom_card_->pos());
            anim3->setEndValue(pos3);
            anim3->setDuration(2000);
            anim3->setEasingCurve(QEasingCurve::InOutSine);

            anim4->setStartValue(world_info_widget_->pos());
            anim4->setEndValue(pos4);
            anim4->setDuration(2000);
            anim4->setEasingCurve(QEasingCurve::InOutSine);

            // Add animations to the group
            login_animations_->addAnimation(anim1);
            login_animations_->addAnimation(anim2);
            login_animations_->addAnimation(anim3);
            login_animations_->addAnimation(anim4);

            // Start animations
            login_animations_->start();
        }