Example #1
0
int main(int argc, char *argv[])
{
   QApplication a(argc, argv);
   std::random_device rd;
   random_engine gen(rd());

   int imageSize = 300;
   QList<QImage> images;
   for (int n = 0; n < 28; ++n) images << randomImage(imageSize, gen);
   std::uniform_int_distribution<> dImage(0, images.size()-1);

   QStackedWidget display;
   QPushButton ready("I'm Ready!");
   QLabel label, labelHidden;
   display.addWidget(&ready);
   display.addWidget(&label);
   display.addWidget(&labelHidden);

   QTimer splashTimer;
   QStateMachine machine;
   QState s1(&machine), s2(&machine), s3(&machine), s4(&machine);
   splashTimer.setSingleShot(true);

   QObject::connect(&s1, &QState::entered, [&]{
      display.setCurrentWidget(&ready);
      ready.setDefault(true);
      ready.setFocus();
   });
   s1.addTransition(&ready, "clicked()", &s2);

   QObject::connect(&s2, &QState::entered, [&]{
      label.setPixmap(QPixmap::fromImage(images.at(dImage(gen))));
      display.setCurrentWidget(&label);
      splashTimer.start(250 + std::uniform_int_distribution<>(1500, 3000)(gen));
   });
   s2.addTransition(&splashTimer, "timeout()", &s3);

   QObject::connect(&s3, &QState::entered, [&]{
      display.setCurrentWidget(&labelHidden);
      splashTimer.start(2000);
   });
   s3.addTransition(&splashTimer, "timeout()", &s4);

   QObject::connect(&s4, &QState::entered, [&]{
      display.setCurrentWidget(&label);
      splashTimer.start(3000);
   });
   s4.addTransition(&splashTimer, "timeout()", &s1);

   machine.setInitialState(&s1);
   machine.start();
   display.show();

   return a.exec();
}
Example #2
0
File: main.cpp Project: SirYacc/ter
int main( int argc, char *argv[] )
{

    QApplication a( argc, argv );

    QMainWindow mainWindow;

    HGRSVM svm = HGRSVM();
    svm.train( 100 );

    QStackedWidget *stackedWidget = new QStackedWidget;

    MyMainWindow *myMainWindow = new MyMainWindow( stackedWidget );

    stackedWidget->addWidget( myMainWindow );
    stackedWidget->setCurrentWidget( myMainWindow );

    mainWindow.setCentralWidget(stackedWidget);
    mainWindow.setWindowTitle( "Hand gesture recognition for ArDrone" );
    mainWindow.resize(950, 500);
    mainWindow.show();

    thread th1( runArdrone );


    int status = a.exec();



    order = 1;
 th1.join();

    return status;
}
Example #3
0
void
InsertPageCommand::execute()
{
    KFormDesigner::Container *container = m_form->objectTree()->lookup(m_containername)->container();
    QWidget *parent = m_form->objectTree()->lookup(m_parentname)->widget();
    if (m_name.isEmpty()) {
        m_name = container->form()->objectTree()->generateUniqueName(
                     container->form()->library()->displayName("QWidget").toLatin1(),
                     /*!numberSuffixRequired*/false);
    }

    QWidget *page = container->form()->library()->createWidget(
        "QWidget", parent, m_name.toLatin1(), container);
    page->setAutoFillBackground(true);
//    page->setPaletteBackgroundColor(Qt::red);
    KFormDesigner::ObjectTreeItem *item = container->form()->objectTree()->lookup(m_name);

    QByteArray classname = parent->metaObject()->className();
    if (classname == "KFDTabWidget") {
        TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(parent);
        QString n = i18n("Page %1", tab->count() + 1);
        tab->addTab(page, n);
        tab->setCurrentWidget(page);
        item->addModifiedProperty("title", n);
    } else if (classname == "QStackedWidget" || /* compat */ classname == "QWidgetStack") {
        QStackedWidget *stack = dynamic_cast<QStackedWidget*>(parent);
        stack->addWidget(page);
        stack->setCurrentWidget(page);
        item->addModifiedProperty("stackIndex", stack->indexOf(page));
    }
}
Example #4
0
int main(int argc,char **argv)
{
    QApplication app(argc,argv);

    QCoreApplication::setOrganizationName("Rabitsa");
    QCoreApplication::setApplicationName("filters");
    QApplication::setStyle(new QPlastiqueStyle);

    QSettings s;
    
    IoNetClient net( s.value("/ioserv/hostname","localhost").toString());
    net.setCmode(
#ifdef WIN32
                false
#else
                s.value("/ioserv/cmode",true).toBool()
#endif
    );
    QStackedWidget main;
    QColor cl;
    QPalette pal;
    cl.setRgb(90,132,201);
    pal.setColor(QPalette::Background,cl);
    main.setPalette(pal);

    QTranslator translator;
    translator.load("filters_"+QLocale::system().name(),":/translate");
    app.installTranslator(&translator);

    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    
    mMainForm *mainForm = new mMainForm(net);
    
    main.addWidget(mainForm);
    main.setCurrentWidget(mainForm);


    if(QApplication::desktop()->size().width()>1366 && QApplication::desktop()->size().height()> 768)
    {
        main.resize(1366,768);
        main.show();
    }
    else
    {
        main.showFullScreen();
    }

    return app.exec();
}
static void recreate_instruments_widget_from_state(vector_t *state){
  QStackedWidget* tabs = instruments_widget->tabs;

  while(tabs->count()>0)
    tabs->removeWidget(tabs->currentWidget());

  //vector_t *names = (vector_t*)state->elements[0];
  vector_t *pages = (vector_t*)state->elements[0];

  for(int i=pages->num_elements-1; i>=0; i--){
    QWidget *page = (QWidget*)pages->elements[i];
    tabs->insertWidget(0,page);//,(const char*)names->elements[i]);
  }

  tabs->setCurrentWidget((QWidget*)state->elements[1]);
}
Example #6
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    auto *proxyStyle = new TabBarProxyStyle;
    app.setStyle(proxyStyle);

    QWidget widget;
    QStackedWidget stackedWidget;
    QTabBar tabBar;
    tabBar.setDocumentMode(true);
    tabBar.setTabsClosable(true);
    tabBar.setMovable(true);
    tabBar.setExpanding(false);

    // top
    tabBar.setShape(QTabBar::RoundedNorth);
    // bottom
//    tabBar.setShape(QTabBar::RoundedSouth);
    // left
//    tabBar.setShape(QTabBar::RoundedWest);
    // right
//    tabBar.setShape(QTabBar::RoundedEast);

    const auto shortLabel = QStringLiteral("Tab %1");
    const auto longLabel = QStringLiteral("An Extremely Long Tab Label %1");

    QMap<int, QWidget*> tabs;
    for (int i = 0; i < TabCount; i++) {
        QString tabNumberString = QString::number(i);
        QLabel *label = new QLabel(QStringLiteral("Tab %1 content").arg(tabNumberString));
        tabs[i] = label;
        label->setAlignment(Qt::AlignCenter);
        stackedWidget.addWidget(label);
        tabBar.addTab(shortLabel.arg(tabNumberString));
    }

    QObject::connect(&tabBar, &QTabBar::tabMoved, [&tabs](int from, int to) {
        QWidget *thisWidget = tabs[from];
        QWidget *thatWidget = tabs[to];
        tabs[from] = thatWidget;
        tabs[to] = thisWidget;
    });

    QObject::connect(&tabBar, &QTabBar::currentChanged, [&stackedWidget, &tabs](int index) {
        if (index >= 0)
            stackedWidget.setCurrentWidget(tabs[index]);
    });

    QObject::connect(&tabBar, &QTabBar::tabCloseRequested, [&stackedWidget, &tabBar, &tabs](int index) {
        QWidget *widget = tabs[index];
        tabBar.removeTab(index);
        for (int i = index + 1; i < TabCount; i++)
            tabs[i-1] = tabs[i];
        int currentIndex = tabBar.currentIndex();
        if (currentIndex >= 0)
            stackedWidget.setCurrentWidget(tabs[currentIndex]);
        delete widget;
    });

    QLayout *layout;
    switch (tabBar.shape()) {
    case QTabBar::RoundedEast:
    case QTabBar::TriangularEast:
        tabBar.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
        layout = new QHBoxLayout(&widget);
        layout->addWidget(&stackedWidget);
        layout->addWidget(&tabBar);
        break;
    case QTabBar::RoundedWest:
    case QTabBar::TriangularWest:
        tabBar.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
        layout = new QHBoxLayout(&widget);
        layout->addWidget(&tabBar);
        layout->addWidget(&stackedWidget);
        break;
    case QTabBar::RoundedNorth:
    case QTabBar::TriangularNorth:
        tabBar.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
        layout = new QVBoxLayout(&widget);
        layout->addWidget(&tabBar);
        layout->addWidget(&stackedWidget);
        break;
    case QTabBar::RoundedSouth:
    case QTabBar::TriangularSouth:
        tabBar.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
        layout = new QVBoxLayout(&widget);
        layout->addWidget(&stackedWidget);
        layout->addWidget(&tabBar);
        break;
    }

    TabBarForm form;
    layout->addWidget(&form);
    layout->setAlignment(&form, Qt::AlignHCenter);

    form.ui->documentModeButton->setChecked(tabBar.documentMode());
    QObject::connect(form.ui->documentModeButton, &QCheckBox::toggled, [&] {
        tabBar.setDocumentMode(form.ui->documentModeButton->isChecked());
        // QMacStyle (and maybe other styles) requires a re-polish to get the right font
        QApplication::sendEvent(&tabBar, new QEvent(QEvent::ThemeChange));
    });

    form.ui->movableTabsButton->setChecked(tabBar.isMovable());
    QObject::connect(form.ui->movableTabsButton, &QCheckBox::toggled, [&] {
        tabBar.setMovable(form.ui->movableTabsButton->isChecked());
        tabBar.update();
    });

    form.ui->closableTabsButton->setChecked(tabBar.tabsClosable());
    QObject::connect(form.ui->closableTabsButton, &QCheckBox::toggled, [&] {
        tabBar.setTabsClosable(form.ui->closableTabsButton->isChecked());
        tabBar.update();
    });

    form.ui->expandingTabsButton->setChecked(tabBar.expanding());
    QObject::connect(form.ui->expandingTabsButton, &QCheckBox::toggled, [&] {
        tabBar.setExpanding(form.ui->expandingTabsButton->isChecked());
        tabBar.update();
    });

    form.ui->displayIconButton->setChecked(!tabBar.tabIcon(0).isNull());
    QObject::connect(form.ui->displayIconButton, &QCheckBox::toggled, [&] {
        const auto icon = form.ui->displayIconButton->isChecked() ?
                          tabBar.style()->standardIcon(QStyle::SP_ComputerIcon) : QIcon();
        for (int i = 0; i < tabBar.count(); i++)
            tabBar.setTabIcon(i, icon);
    });

    form.ui->longLabelButton->setChecked(false);
    QObject::connect(form.ui->longLabelButton, &QCheckBox::toggled, [&] {
        const auto &label = form.ui->longLabelButton->isChecked() ? longLabel : shortLabel;
        for (int i = 0; i < tabBar.count(); i++)
            tabBar.setTabText(i, label.arg(i));
    });

    QObject::connect(form.ui->shapeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [&](int index) {
        Q_UNUSED(index);
        // TODO
    });

    if (proxyStyle->alignment == Qt::AlignLeft)
        form.ui->leftAlignedButton->setChecked(true);
    else if (proxyStyle->alignment == Qt::AlignRight)
        form.ui->rightAlignedButton->setChecked(true);
    else
        form.ui->centeredButton->setChecked(true);
    QObject::connect(form.ui->textAlignmentGroup, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked), [&](QAbstractButton *b) {
        proxyStyle->alignment = b == form.ui->leftAlignedButton ? Qt::AlignLeft :
                                b == form.ui->rightAlignedButton ? Qt::AlignRight : Qt::AlignCenter;
        QApplication::sendEvent(&tabBar, new QEvent(QEvent::StyleChange));
    });

    layout->setMargin(12);
    widget.show();

    return app.exec();
}