コード例 #1
0
ファイル: repairerDialogs.cpp プロジェクト: nfrey/qreal
void PatchSaveDialog::run()
{	if (checkSavePath() && checkPatchPath()) {
		mRepairer->patchSave(savePath->text(), patchPath->text());
		close();
	}
	checkPatchPath();
}
コード例 #2
0
ファイル: repairerDialogs.cpp プロジェクト: nfrey/qreal
void PatchSaveDialog::openSaveDirectory() {
	//todo: improve it with QDir, current solution is incorrect
	QString startPath = savePath->text();
	if (startPath.length() > 1) {
		if (!startPath.endsWith("/"))
			startPath += '/';
		startPath += '.' + '.';
	}
	savePath->setText(QFileDialog::getExistingDirectory(this, tr("Choose save directory"), startPath));
	checkSavePath();
}
コード例 #3
0
ファイル: repairerDialogs.cpp プロジェクト: nfrey/qreal
PatchSaveDialog::PatchSaveDialog(QString savePathStr, QString patchPathStr, qReal::Repairer *repairer)
{
	mRepairer = repairer;

	layout = new QGridLayout();
	savePath = new QLineEdit(savePathStr);
	patchPath = new QLineEdit(patchPathStr);
	saveError = new QLabel(tr("Path is incorrect"));
	patchError = new QLabel(tr("Path is incorrect"));
	saveBrowse = new QPushButton(tr("Browse"));
	patchBrowse = new QPushButton(tr("Browse"));
	saveCaption = new QLabel(tr("Path to save: "));
	patchCaption = new QLabel(tr("Path to patch: "));
	commonLabel = new QLabel(tr("Choose paths to save and patch"));
	runButton = new QPushButton(tr("Patch"));

	saveError->setStyleSheet("QLabel {color : red; }");
	patchError->setStyleSheet("QLabel {color : red; }");

	connect(runButton, SIGNAL(clicked()), this, SLOT(run()));
	connect(this, SIGNAL(destroyed()), this, SLOT(releaseMemory()));
	connect(patchBrowse, SIGNAL(clicked()), this, SLOT(openPatchFile()));
	connect(saveBrowse, SIGNAL(clicked()), this, SLOT(openSaveDirectory()));
	connect(savePath, SIGNAL(editingFinished()), this, SLOT(checkSavePath()));
	connect(patchPath, SIGNAL(editingFinished()), this, SLOT(checkPatchPath()));

	layout->addWidget(commonLabel,0,0,1,-1,Qt::AlignLeft);
	layout->addWidget(saveCaption,1,0);
	layout->addWidget(savePath,1,1);
	layout->addWidget(saveBrowse,1,2);
	layout->addWidget(saveError,2,1,1,-1,Qt::AlignLeft);
	layout->addWidget(patchCaption,3,0);
	layout->addWidget(patchPath,3,1);
	layout->addWidget(patchBrowse,3,2);
	layout->addWidget(patchError,4,1,1,-1,Qt::AlignLeft);
	layout->addWidget(runButton,5,0,1,-1,Qt::AlignRight);

	saveError->hide();
	patchError->hide();

	setLayout(layout);

	int width = this->width();
	setFixedSize(width,heightForWidth(width));
}
コード例 #4
0
ファイル: mainwindow.cpp プロジェクト: Grandge/KanmusuMemory
MainWindow::Private::Private(MainWindow *parent)
    : q(parent)
    , settings(SETTING_FILE_NAME, SETTING_FILE_FORMAT)
    , trayIcon(QIcon(":/resources/KanmusuMemory32.png"))
{
    ui.setupUi(q);
    ui.webView->page()->networkAccessManager()->setCookieJar(new CookieJar(q));
    QNetworkDiskCache *cache = new QNetworkDiskCache(q);
    cache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
    cache->setMaximumCacheSize(1073741824); //about 1024MB
    ui.webView->page()->networkAccessManager()->setCache(cache);

    //通知タイマーのダイアログ作成
    m_timerDialog = new TimerDialog(q, &trayIcon, &settings);

    //メニュー
    connect(ui.capture, &QAction::triggered, [this](){ captureGame(); });
    connect(ui.actionCaptureAndEdit, &QAction::triggered, [this]() { captureGame(true); });
#ifndef DISABLE_CATALOG_AND_DETAIL_FLEET
    connect(ui.captureCatalog, &QAction::triggered, [this](){ captureCatalog(); });
    connect(ui.captureFleetDetail, &QAction::triggered, [this](){ captureFleetDetail(); });
#endif
    connect(ui.reload, &QAction::triggered, ui.webView, &QWebView::reload);
    connect(ui.exit, &QAction::triggered, q, &MainWindow::close);
    connect(ui.actionReturn_to_Kan_Colle, &QAction::triggered, [this]() {
        //艦これ読込み
        ui.webView->load(QUrl(URL_KANCOLLE));
    });
    connect(ui.actionClearAccessCache, &QAction::triggered, [this]() {
        //キャッシュをクリア
        ui.webView->page()->networkAccessManager()->cache()->clear();
    });
    //画像リスト
    connect(ui.viewMemory, &QAction::triggered, [this]() {
        checkSavePath();
        MemoryDialog dlg(settings.value(QStringLiteral("path")).toString(), q);
        dlg.exec();
        if(QFile::exists(dlg.imagePath())){
            switch(dlg.nextOperation()){
            case MemoryDialog::Tweet:
                //つぶやく
                openTweetDialog(dlg.imagePath());
                break;
            case MemoryDialog::Edit:
            {
                //編集
                QString format;
                if(settings.value(SETTING_GENERAL_SAVE_PNG, false).toBool())
                    format = QStringLiteral("png");
                else
                    format = QStringLiteral("jpg");
                QString path = makeFileName(format);
                QString editPath = makeFileName(format);
                openImageEditDialog(path ,dlg.imagePath(), editPath);
                break;
            }
            default:
                break;
            }
        }
    });
    //通知タイマー
    connect(ui.notificationTimer, &QAction::triggered, [this]() {
        m_timerDialog->show();
    });

    //設定ダイアログ表示
    connect(ui.preferences, &QAction::triggered, [this]() {
        SettingsDialog dlg(q);
        dlg.setSavePath(settings.value(QStringLiteral("path")).toString());
        dlg.setUnusedTwitter(settings.value(SETTING_GENERAL_UNUSED_TWITTER, false).toBool());
        dlg.setSavePng(settings.value(SETTING_GENERAL_SAVE_PNG, false).toBool());
        dlg.setMaskAdmiralName(settings.value(SETTING_GENERAL_MASK_ADMIRAL_NAME, false).toBool());
        dlg.setMaskHqLevel(settings.value(SETTING_GENERAL_MASK_HQ_LEVEL, false).toBool());
        if (dlg.exec()) {
            //設定更新
            settings.setValue(QStringLiteral("path"), dlg.savePath());
            settings.setValue(SETTING_GENERAL_UNUSED_TWITTER, dlg.unusedTwitter());
            settings.setValue(SETTING_GENERAL_SAVE_PNG, dlg.savePng());
            settings.setValue(SETTING_GENERAL_MASK_ADMIRAL_NAME, dlg.isMaskAdmiralName());
            settings.setValue(SETTING_GENERAL_MASK_HQ_LEVEL, dlg.isMaskHqLevel());
        }
    });

    //アバウト
    connect(ui.about, &QAction::triggered, [this]() {
        AboutDialog dlg(q);
        dlg.setVersion(KANMEMO_VERSION);
        dlg.setDevelopers(KANMEMO_DEVELOPERS);
        dlg.exec();
    });

    //フルスクリーン
    q->addAction(ui.actionFullScreen);
    connect(ui.actionFullScreen, &QAction::triggered, [this]() {
        if(q->isFullScreen()){
            //フルスクリーン解除
            q->setWindowState(q->windowState() ^ Qt::WindowFullScreen);
        }else if(ui.webView->gameExists()){
            //フルスクリーンじゃなくてゲームがある
            q->setWindowState(q->windowState() ^ Qt::WindowFullScreen);
        }else{
            //フルスクリーンでゲームがないときは何もしない
        }
    });

    //WebViewの読込み開始
    connect(ui.webView, &QWebView::loadStarted, [this](){
       ui.progressBar->show();
    });
    //WebViewの読込み完了
    connect(ui.webView, &QWebView::loadFinished, [this](bool ok) {
        if (ok) {
            ui.statusBar->showMessage(MainWindow::tr("complete"), STATUS_BAR_MSG_TIME);
//            if(ui.webView->url().toString().compare(URL_KANCOLLE) == 0){
//                setFullScreen();
//            }
        } else {
            ui.statusBar->showMessage(MainWindow::tr("error"), STATUS_BAR_MSG_TIME);
        }
        ui.progressBar->hide();
    });
    //WebViewの読込み状態
    connect(ui.webView, &QWebView::loadProgress, ui.progressBar, &QProgressBar::setValue);

    //通知アイコン
#ifdef Q_OS_WIN
    trayIcon.show();
#endif

#ifdef DISABLE_CATALOG_AND_DETAIL_FLEET
    ui.captureCatalog->setVisible(false);
    ui.captureFleetDetail->setVisible(false);
#endif
}
コード例 #5
0
ファイル: mainwindow.cpp プロジェクト: Grandge/KanmusuMemory
void MainWindow::Private::captureFleetDetail()
{
    qDebug() << "captureFleetDetail";

    //設定確認
    checkSavePath();

    QRect captureRect = DETAIL_RECT_CAPTURE;
    QImage resultImg(captureRect.width() * 2
                     , captureRect.height() * 3
                     ,QImage::Format_ARGB32);
    resultImg.fill(Qt::transparent);
    QPainter painter(&resultImg);

    GameScreen gameScreen(ui.webView->capture());
    if (!gameScreen.isVisible(GameScreen::Ship1Part))
    {
        ui.statusBar->showMessage(tr("not in organization"), STATUS_BAR_MSG_TIME);
        return;
    }

    //開始確認
    QMessageBox::StandardButton res = QMessageBox::warning(q
                                                           , tr("Kan Memo")
                                                           , tr("Capture the fleet ditail.\nPlease wait while a cup of coffee.")
                                                           , QMessageBox::Yes | QMessageBox::Cancel);
    if(res == QMessageBox::Cancel)
        return;

    //メニュー無効
    ui.menuBar->setEnabled(false);
    ui.toolBar->setEnabled(false);

    ui.webView->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui.statusBar->showMessage(tr("making fleet detail"), -1);
    ui.progressBar->show();
    ui.progressBar->setValue(0);
    for (int i = 0; i < 6; i++) {
        if (!gameScreen.isVisible(static_cast<GameScreen::PartType>(GameScreen::Ship1Part + i))) break;
        gameScreen.click(ui.webView, static_cast<GameScreen::PartType>(GameScreen::Ship1Part + i), GameScreen::WaitLonger);

        QImage tmpImg = ui.webView->capture().copy(captureRect);
        painter.drawImage(captureRect.width() * (i % 2)
                          , captureRect.height() * (i / 2)
                          , tmpImg);
        ui.progressBar->setValue((i + 1) * 100 / 6);
        gameScreen.click(ui.webView, GameScreen::Ship1Part);
    }
    ui.progressBar->hide();
    ui.webView->setAttribute(Qt::WA_TransparentForMouseEvents, false);
    ui.statusBar->clearMessage();

    char format[] = "jpg";
    QString path = makeFileName(QString(format));
    qDebug() << "path:" << path;

    //保存する
    ui.statusBar->showMessage(tr("saving to %1...").arg(path), STATUS_BAR_MSG_TIME);
    if(resultImg.save(path, format))
    {
        //つぶやくダイアログ
        openTweetDialog(path);
    }else{
        ui.statusBar->showMessage(tr("failed save image"), STATUS_BAR_MSG_TIME);
    }

    //メニュー復活
    ui.menuBar->setEnabled(true);
    ui.toolBar->setEnabled(true);
}
コード例 #6
0
ファイル: mainwindow.cpp プロジェクト: Grandge/KanmusuMemory
void MainWindow::Private::captureCatalog()
{
    qDebug() << "captureCatalog";

    //設定確認
    checkSavePath();

    QRect captureRect = CATALOG_RECT_CAPTURE;
    QList<QRect> shipRectList;
    {
        shipRectList << CATALOG_RECT_SHIP1
                     << CATALOG_RECT_SHIP2
                     << CATALOG_RECT_SHIP3;
    }
    QList<QRect> pageRectList;
    {
        pageRectList << CATALOG_RECT_PAGE1
                     << CATALOG_RECT_PAGE2
                     << CATALOG_RECT_PAGE3
                     << CATALOG_RECT_PAGE4
                     << CATALOG_RECT_PAGE5;
    }

    QImage resultImg(captureRect.width() * shipRectList.size()
                     , captureRect.height() * pageRectList.size()
                     ,QImage::Format_ARGB32);
    QPainter painter(&resultImg);

    QPoint currentPos = ui.webView->page()->mainFrame()->scrollPosition();
    QRect geometry = ui.webView->getGameRect();

    if (GameScreen(ui.webView->capture()).screenType() != GameScreen::CatalogScreen)
    {
        ui.webView->page()->mainFrame()->setScrollPosition(currentPos);
        ui.statusBar->showMessage(tr("not in catalog"), STATUS_BAR_MSG_TIME);
        return;
    }

    //開始確認
    QMessageBox::StandardButton res = QMessageBox::warning(q
                                                           , tr("Kan Memo")
                                                           , tr("Capture the catalog.\nPlease wait while a cup of coffee.")
                                                           , QMessageBox::Yes | QMessageBox::Cancel);
    if(res == QMessageBox::Cancel)
        return;

    //メニュー無効
    ui.menuBar->setEnabled(false);
    ui.toolBar->setEnabled(false);

    ui.webView->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui.statusBar->showMessage(tr("making catalog"), -1);
    ui.progressBar->show();
    ui.progressBar->setValue(0);
    for (int type = 0; type < shipRectList.size(); type++)
    {
        int tx = geometry.x()
                + (shipRectList.value(type).x() + qrand() % shipRectList.value(type).width());
        int ty = geometry.y()
                + (shipRectList.value(type).y() + qrand() % shipRectList.value(type).height());
        clickGame(QPoint(tx, ty));

        for (int page = 0; page < pageRectList.size(); page++)
        {
            int px = geometry.x()
                    + (pageRectList.value(page).x() + qrand() % pageRectList.value(page).width());
            int py = geometry.y()
                    + (pageRectList.value(page).y() + qrand() % pageRectList.value(page).height());
            clickGame(QPoint(px, py));

            QImage details = ui.webView->capture().copy(captureRect);
            painter.drawImage(captureRect.width() * type
                              , captureRect.height() * page
                              , details);

            ui.progressBar->setValue((pageRectList.size() * type + (page + 1)) * 100
                                     / (pageRectList.size() * shipRectList.size()) );
        }
    }
    ui.progressBar->hide();
    ui.webView->page()->mainFrame()->setScrollPosition(currentPos);
    ui.webView->setAttribute(Qt::WA_TransparentForMouseEvents, false);
    ui.statusBar->showMessage("", -1);

    char format[] = "jpg";
    QString path = makeFileName(QString(format));
    qDebug() << "path:" << path;

    //保存する
    ui.statusBar->showMessage(tr("saving to %1...").arg(path), STATUS_BAR_MSG_TIME);
    if(resultImg.save(path, format))
    {
        //つぶやくダイアログ
        openTweetDialog(path);
    }else{
        ui.statusBar->showMessage(tr("failed save image"), STATUS_BAR_MSG_TIME);
    }

    //メニュー復活
    ui.menuBar->setEnabled(true);
    ui.toolBar->setEnabled(true);
}
コード例 #7
0
ファイル: mainwindow.cpp プロジェクト: Grandge/KanmusuMemory
//思い出を残す
void MainWindow::Private::captureGame(bool andEdit)
{
    qDebug() << "captureGame";

    //設定確認
    checkSavePath();

    QImage img = ui.webView->capture();
    if (img.isNull())
    {
        ui.statusBar->showMessage(tr("failed capture image"), STATUS_BAR_MSG_TIME);
        return;
    }

    GameScreen gameScreen(img);

    if (gameScreen.isVisible(GameScreen::HeaderPart)) {
        //提督名をマスク
        if(settings.value(SETTING_GENERAL_MASK_ADMIRAL_NAME, false).toBool()) {
            maskImage(&img, ADMIRAL_RECT_HEADER);
        }
        //司令部レベルをマスク
        if(settings.value(SETTING_GENERAL_MASK_HQ_LEVEL, false).toBool()) {
            maskImage(&img, HQ_LEVEL_RECT_HEADER);
        }
    }

    QString format;
    if(settings.value(SETTING_GENERAL_SAVE_PNG, false).toBool())
        format = QStringLiteral("png");
    else
        format = QStringLiteral("jpg");

    QString path = makeFileName(format);
//    qDebug() << "path:" << path;

    if(andEdit){
        //編集もする
        QString tempPath = makeTempFileName(format);
        QString editPath = makeFileName(format);
//        qDebug() << "temp path:" << tempPath;

        //保存する
        ui.statusBar->showMessage(tr("saving to %1...").arg(tempPath), STATUS_BAR_MSG_TIME);
        if (img.save(tempPath, format.toUtf8().constData())) {
            //編集ダイアログ
            openImageEditDialog(path, tempPath, editPath);
        } else {
            ui.statusBar->showMessage(tr("failed save image"), STATUS_BAR_MSG_TIME);
        }
        //テンポラリのファイルを消す
        QFile::remove(tempPath);
    }else{
        //キャプチャーだけ

        //保存する
        ui.statusBar->showMessage(tr("saving to %1...").arg(path), STATUS_BAR_MSG_TIME);
        if (img.save(path, format.toUtf8().constData())) {
            //つぶやくダイアログ
            openTweetDialog(path);
        } else {
            ui.statusBar->showMessage(tr("failed save image"), STATUS_BAR_MSG_TIME);
        }
    }
}