Example #1
0
//! [7]
QGroupBox *Window::createNonExclusiveGroup()
{
    QGroupBox *groupBox = new QGroupBox(tr("Non-Exclusive Checkboxes"));
    groupBox->setFlat(true);
//! [7]

//! [8]
    QCheckBox *checkBox1 = new QCheckBox(tr("&Checkbox 1"));
    QCheckBox *checkBox2 = new QCheckBox(tr("C&heckbox 2"));
    checkBox2->setChecked(true);
    QCheckBox *tristateBox = new QCheckBox(tr("Tri-&state button"));
    tristateBox->setTristate(true);
//! [8]
    tristateBox->setCheckState(Qt::PartiallyChecked);

//! [9]
    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->addWidget(checkBox1);
    vbox->addWidget(checkBox2);
    vbox->addWidget(tristateBox);
    vbox->addStretch(1);
    groupBox->setLayout(vbox);

    return groupBox;
}
Example #2
0
void BrowseWidget::parseGenrePanel(const QString &id, QNetworkReply *reply) {
  Q_UNUSED(id);

  auto api = API::sharedAPI()->sharedAniListAPI();
  auto request_url = reply->request().url().toDisplayString();

  if (request_url.startsWith(api->API_GENRES.toDisplayString())) {
    auto data = reply->readAll();
    auto array = QJsonDocument::fromJson(data).array();
    auto width = 0;
    auto metric = this->fontMetrics();

    for (auto value : array) {
      auto object = value.toObject();
      QCheckBox *chk = new QCheckBox(this);

      chk->setText(object.value("genre").toString());
      chk->setTristate();

      width = qMax(width, metric.width(chk->text()));

      m_ui->genre_list->addWidget(chk);
    }

    m_ui->genre_area->setMinimumWidth(width * 2);
  }
}
Example #3
0
int drv_checkbox(int drvid, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6, void* a7, void* a8, void* a9)
{
    handle_head* head = (handle_head*)a0;
    QCheckBox *self = (QCheckBox*)head->native;
    switch (drvid) {
    case CHECKBOX_INIT: {
        drvNewObj(a0,new QCheckBox);
        break;
    }
    case CHECKBOX_SETCHECK: {
        self->setCheckState((Qt::CheckState)drvGetInt(a1));
        break;
    }
    case CHECKBOX_CHECK: {
        drvSetInt(a1,self->checkState());
        break;
    }
    case CHECKBOX_SETTRISTATE: {
        self->setTristate(drvGetBool(a1));
        break;
    }
    case CHECKBOX_ISTRISTATE: {
        drvSetBool(a1,self->isTristate());
        break;
    }
    case CHECKBOX_ONSTATECHANGED: {
        QObject::connect(self,SIGNAL(stateChanged(int)),drvNewSignal(self,a1,a2),SLOT(call(int)));
        break;
    }
    default:
        return 0;
    }
    return 1;
}
Example #4
0
QWidget* DSiNo::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
 QCheckBox *editor = new QCheckBox( parent );
 editor->setText( index.model()->headerData( index.column(), Qt::Horizontal ).toString() );
 editor->setTristate( false );
 editor->setPalette( option.palette );
 editor->setFont( option.font );
 editor->setBackgroundRole( QPalette::Background );
 return editor;
}
void AlignsPropertyGridWidget::OnAlignCheckBoxStateChanged(int state)
{
    if (activeMetadata == NULL)
    {
        // No control already assinged.
        return;
    }

    QCheckBox* senderWidget = dynamic_cast<QCheckBox*>(QObject::sender());
    if (senderWidget == NULL)
    {
        Logger::Error("OnCheckBoxStateChanged - sender is NULL!");
        return;
    }

    // After the first change don't allow the checkbox to be tristate.
    senderWidget->setTristate(false);
    
    PROPERTYGRIDWIDGETSITER iter = propertyGridWidgetsMap.find(senderWidget);
    if (iter == propertyGridWidgetsMap.end())
    {
        Logger::Error("OnCheckBoxStateChanged - unable to find attached property in the propertyGridWidgetsMap!");
        return;
    }

	// Don't update the property if the text wasn't actually changed.
	bool isPropertyValueDiffers = false;
    bool curValue = PropertiesHelper::GetAllPropertyValues<bool>(this->activeMetadata, iter->second.getProperty().name(),
																 isPropertyValueDiffers);

	// In case we have differences in property values for different widgets - force update the states too.
	bool newValue = (state == Qt::Checked);
	if ((curValue == newValue) && !isPropertyValueDiffers)
	{
		return;
	}

    BaseCommand* command = new ChangeAlignPropertyCommand(activeMetadata, iter->second, newValue);
    CommandsController::Instance()->ExecuteCommand(command);
	SafeRelease(command);
}
Example #6
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWidget wgt;
    QCheckBox* pchkNormal = new QCheckBox("&Normal Check Box");
    pchkNormal->setChecked(true);

    QCheckBox* pchkTristate = new QCheckBox("&Tristate Check Box");
    pchkTristate->setTristate(true);
    pchkTristate->setCheckState(Qt::PartiallyChecked);

    QVBoxLayout* pvbxLayout = new QVBoxLayout;
    pvbxLayout->addWidget(pchkNormal);
    pvbxLayout->addWidget(pchkTristate);

    wgt.setLayout(pvbxLayout);
    wgt.show();

    return a.exec();
}
Example #7
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow) {
  ui->setupUi(this);

  QFile styleFile(":/style.css");
  styleFile.open(QFile::ReadOnly);
  QString styleSheet = QLatin1String(styleFile.readAll());
  qApp->setStyleSheet(styleSheet);

  QPixmap window_icon;
  QFile iconFile(":/icon.png");
  iconFile.open(QFile::ReadOnly);
  QByteArray icon_data = iconFile.readAll();
  window_icon.loadFromData(icon_data);
  qApp->setWindowIcon(QIcon(window_icon));

  awesome = new QtAwesome(qApp);
  settings = new Settings(this);
  window_watcher = new WindowWatcher(this);
  anitomy = new AnitomyWrapper();
  event_timer = new QTimer(this);
  watch_timer = new QTimer(this);
  uptime_timer = new QElapsedTimer;
  progress_bar = new QProgressBar(ui->statusBar);
  over = new Overlay(this);
  torrent_refresh_time = 0;
  user_refresh_time =
      settings->getValue(Settings::UserRefreshTime, D_USER_REFRESH_TIME)
          .toInt();
  download_rule = 0;
  download_count = 0;
  hasUser = false;

  uptime_timer->start();
  watch_timer->setSingleShot(true);

  awesome->initFontAwesome();

  bool check_for_updates =
      settings->getValue(Settings::CheckUpdates, D_CHECK_FOR_UPDATES).toBool();

  if (check_for_updates) {
    connect(FvUpdater::sharedUpdater(), &FvUpdater::restartRequested,
            [&]() {  // NOLINT
              QString app = QApplication::applicationFilePath();
              QStringList arguments = QApplication::arguments();
              QString wd = QDir::currentPath();
              QProcess::startDetached(app, arguments, wd);
              elegantClose(true);
            });

    FvUpdater::sharedUpdater()->CheckForUpdatesSilent();
  }

  QFont font = ui->listTabs->tabBar()->font();
  font.setCapitalization(QFont::Capitalize);
  ui->listTabs->tabBar()->setFont(font);

  int currentYear = QDate::currentDate().year();
  int lowerYear = currentYear - 10;

  while (currentYear > lowerYear) {
    ui->comboYear->addItem(QString::number(currentYear));
    currentYear--;
  }

  QWidget *container = new QWidget(ui->scrollArea);
  layout = new FlowLayout(container);
  ui->scrollArea->setWidget(container);
  container->setLayout(layout);

  QWidget *container2 = new QWidget(ui->scrollArea_2);
  layout2 = new FlowLayout(container2);
  layout2->disableSort();
  ui->scrollArea_2->setWidget(container2);
  container2->setLayout(layout2);

  QVariantMap black;
  black.insert("color", QColor(0, 0, 0));
  black.insert("color-active", QColor(0, 0, 0));
  black.insert("color-disabled", QColor(0, 0, 0));
  black.insert("color-selected", QColor(0, 0, 0));

  ui->airingButton->setIcon(awesome->icon(fa::clocko, black));
  ui->torrentsButton->setIcon(awesome->icon(fa::rss, black));
  ui->animeButton->setIcon(awesome->icon(fa::bars, black));
  ui->seasonsButton->setIcon(awesome->icon(fa::th, black));
  ui->statisticsButton->setIcon(awesome->icon(fa::piechart, black));

  ui->tabWidget->tabBar()->hide();
  ui->tabWidget->setCurrentIndex(UserTabs::tAnime);
  ui->listTabs->setCurrentIndex(0);

  ui->statusBar->addWidget(progress_bar);
  ui->statusBar->layout()->setContentsMargins(1, 0, 0, 0);
  progress_bar->setRange(0, 100);
  progress_bar->setValue(5);
  progress_bar->setFormat("Authorizing");

  QSettings s;
  restoreGeometry(s.value("mainWindowGeometry").toByteArray());
  restoreState(s.value("mainWindowState").toByteArray());

  connect(&user_future_watcher, SIGNAL(finished()), SLOT(userLoaded()));
  connect(&user_list_future_watcher, SIGNAL(finished()),
          SLOT(userListLoaded()));

  connect(ui->animeButton, SIGNAL(clicked()), SLOT(showAnimeTab()));
  connect(ui->airingButton, SIGNAL(clicked()), SLOT(showAiringTab()));
  connect(ui->torrentsButton, SIGNAL(clicked()), SLOT(showTorrentsTab()));
  connect(ui->seasonsButton, SIGNAL(clicked()), SLOT(showBrowseTab()));
  connect(ui->actionSettings, SIGNAL(triggered()), SLOT(showSettings()));
  connect(ui->statisticsButton, SIGNAL(clicked()), SLOT(showStatisticsTab()));

  connect(ui->actionExit, &QAction::triggered, [&, this]() {  // NOLINT
    this->elegantClose();
  });

  connect(ui->actionAbout, &QAction::triggered, [&, this]() {  // NOLINT
    About *about = new About(this);
    about->show();
  });

  connect(ui->actionHelp, &QAction::triggered, [&, this]() {  // NOLINT
    QDesktopServices::openUrl(QUrl("http://app.shinjiru.me/support.php"));
  });

  connect(ui->actionRL, &QAction::triggered, [&, this]() {  // NOLINT
    loadUser();
  });

  connect(ui->actionAS, &QAction::triggered, [&]() {  // NOLINT
    SearchPanel *sp = new SearchPanel(this);
    sp->show();
  });

  connect(ui->actionARR, &QAction::triggered, [&, this]() {  // NOLINT
    SettingsDialog *s = new SettingsDialog(this);
    s->showSmartTitles();

    connect(s, &QDialog::accepted, [&, this]() {  // NOLINT
      Settings set;

      toggleAnimeRecognition(
          set.getValue(Settings::AnimeRecognitionEnabled, D_ANIME_RECOGNITION)
              .toBool());

      torrents_enabled =
          set.getValue(Settings::TorrentsEnabled, D_TORRENTS_ENABLED).toBool();

      reloadSmartTitles();
      reloadRules();
    });
  });

  connect(qApp, SIGNAL(aboutToQuit()), SLOT(elegantClose()));

  connect(ui->actionVAL, SIGNAL(triggered()), SLOT(viewAnimeList()));
  connect(ui->actionVD, SIGNAL(triggered()), SLOT(viewDashboard()));
  connect(ui->actionVP, SIGNAL(triggered()), SLOT(viewProfile()));
  connect(ui->actionEAR, SIGNAL(triggered(bool)),
          SLOT(toggleAnimeRecognition(bool)));
  connect(ui->actionExport, SIGNAL(triggered()), SLOT(exportListJSON()));
  connect(ui->actionUpdate, SIGNAL(triggered()), FvUpdater::sharedUpdater(),
          SLOT(CheckForUpdatesNotSilent()));

  connect(window_watcher, SIGNAL(title_found(QString)), SLOT(watch(QString)));
  connect(watch_timer, SIGNAL(timeout()), SLOT(updateEpisode()));
  connect(event_timer, SIGNAL(timeout()), SLOT(eventTick()));

  connect(ui->torrentTable, SIGNAL(customContextMenuRequested(QPoint)),
          SLOT(torrentContextMenu(QPoint)));
  connect(ui->torrentFilter, SIGNAL(textChanged(QString)),
          SLOT(filterTorrents(QString)));
  connect(ui->chkHideUnknown, SIGNAL(toggled(bool)),
          SLOT(filterTorrents(bool)));
  connect(ui->refreshButton, SIGNAL(clicked()), SLOT(refreshTorrentListing()));

  connect(ui->actionEAR, SIGNAL(toggled(bool)), SLOT(applyEAR()));

  connect(ui->tabWidget, &QTabWidget::currentChanged, [&, this](  // NOLINT
                                                          int tab) {
    if (tab != 0) {
      this->over->removeDrawing("blank_table");
      this->over->removeDrawing("no anime");
      ui->listTabs->show();
      ui->listFilterLineEdit->show();
    } else {
      this->filterList(3);

      if (hasUser && (User::sharedUser()->getAnimeList().count() == 0)) {
        this->addNoAnimePrompt();
      }
    }
  });

  ui->actionEAR->setChecked(
      settings->getValue(Settings::AnimeRecognitionEnabled, D_ANIME_RECOGNITION)
          .toBool());

  this->toggleAnimeRecognition(ui->actionEAR->isChecked());

  QString genrelist =
      "Action, Adult, Adventure, Cars, Comedy, Dementia, Demons, Doujinshi, "
      "Drama, Ecchi, Fantasy, Game, Gender Bender, Harem, Hentai, Historical, "
      "Horror, Josei, Kids, Magic, Martial Arts, Mature, Mecha, Military, "
      "Motion Comic, Music, Mystery, Mythological , Parody, Police, "
      "Psychological, Romance, Samurai, School, Sci-Fi, Seinen, Shoujo, Shoujo "
      "Ai, Shounen, Shounen Ai, Slice of Life, Space, Sports, Super Power, "
      "Supernatural, Thriller, Tragedy, Vampire, Yaoi, Yuri";
  QStringList genres = genrelist.split(", ");

  for (QString genre : genres) {
    QCheckBox *chk = new QCheckBox();

    chk->setText(genre);
    chk->setTristate(true);

    ui->genreList->addWidget(chk);
  }

  connect(ui->listFilterLineEdit, SIGNAL(textChanged(QString)),
          SLOT(filterList(QString)));
  connect(ui->listFilterLineEdit, SIGNAL(returnPressed()), SLOT(showSearch()));
  connect(ui->listTabs, SIGNAL(currentChanged(int)), SLOT(filterList(int)));

  connect(ui->browseButton, SIGNAL(clicked()), SLOT(loadBrowserData()));

  this->show();
  createActions();
  initTray();
  trayIcon->show();

  int result = API::sharedAPI()->verifyAPI();

  if (result == AniListAPI::OK) {
    connect(API::sharedAPI()->sharedAniListAPI(), &AniListAPI::access_granted,
            [&, this]() {  // NOLINT
              progress_bar->setValue(10);
              progress_bar->setFormat("Access granted");
              loadUser();

              event_timer->start(1000);
            });

    connect(API::sharedAPI()->sharedAniListAPI(), &AniListAPI::access_denied,
            [&, this](QString error) {  // NOLINT
              qCritical() << error;

              if (isVisible()) {
                QMessageBox::critical(this, "Shinjiru", tr("Error: ") + error);
              }
            });
  } else if (result == AniListAPI::NO_CONNECTION) {
    qDebug() << "Starting Shinjiru in offline mode";
    hasUser = User::sharedUser()->loadLocal();
  }

  reloadRules();
}