-
Notifications
You must be signed in to change notification settings - Fork 14
/
mainwindow.cpp
1655 lines (1495 loc) · 68.4 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2013-2015 KanMemo Project.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "tweetdialog.h"
#include "settingsdialog.h"
#include "cookiejar.h"
#include "aboutdialog.h"
#include "memorydialog.h"
#include "imageeditdialog.h"
#include "timerdialog.h"
#include "updateinfodialog.h"
#include "fleetdetaildialog.h"
#include "gamescreen.h"
#include "webpageform.h"
#include "favoritemenu.h"
#include "recordingthread.h"
#include "recordingdialog.h"
#include "recognizeinfo.h"
#include "numberguide.h"
#include "kanmusumemory_global.h"
#include <QtCore/QDate>
#include <QtCore/QTime>
#include <QtCore/QString>
#include <QtCore/QDir>
#include <QtCore/QSettings>
#include <QtCore/QStandardPaths>
#include <QtNetwork/QNetworkDiskCache>
#include <QtWidgets/QMessageBox>
#include <QtWebKitWidgets/QWebFrame>
#include <QtWebKit/QWebElement>
#include <QSystemTrayIcon>
#include <QScreen>
#include <QtCore/QDebug>
#ifdef Q_OS_MAC
#include <QDesktopWidget>
#endif
#define URL_KANCOLLE "http://www.dmm.com/netgame/social/-/gadgets/=/app_id=854854/"
#define SPLIT_WEBPAGE_INDEX 1 //分割ウインドウの通常ブラウザのインデックス
#define STATUS_BAR_MSG_TIME 5000
class MainWindow::Private
{
public:
Private(MainWindow *parent, bool not_use_cookie);
~Private();
void captureGame(bool andEdit = false); //保存する
void checkSavePath(); //保存場所の確認
void openTweetDialog(const QString &path, bool force = false); //ツイートダイアログを開く
void openMemoryDialog();
void openSettingDialog();
void openRecordSettingDialog();
void updateProxyConfiguration();
void openAboutDialog();
void openImageEditDialog(const QString &path, const QString &tempPath, const QString &editPath);
void openManualCaptureFleetDetail();
void openManualCaptureFleetList();
void finishManualCaptureFleetDetail(FleetDetailDialog::NextOperationType next, QStringList file_list, int item_width, int item_height, int columns);
void captureCatalog();
void captureFleetDetail();
void setFullScreen();
void setGameSize(qreal factor);
void checkMajorDamageShip(const QPointF &pos, bool force = false);
void viewMajorDamageShip(const QImage &img, const GameScreen &gameScreen, QLabel *label);
void checkExpeditionRemainTime(const QPointF &pos);
QList<int> bakSplitterSizes; //幅のサイズ保存用にとっておく。(非表示だと0になってしまうから)
private:
void setWebSettings(); //Web関連の設定をする
void makeDialog(); //ダイアログの作成をする
void setButtleResultPosition(); //戦果報告の表示位置
void maskImage(QImage *img, const QRect &rect);
QString makeFileName(const QString &format, bool isfull = true) const;
QString makeTempFileName(const QString &format) const;
void clickGame(QPoint pos, bool wait_little = false);
QString combineImage(QStringList file_list, int item_width, int item_height, int columns);
void setSplitWindowVisiblity(bool visible);
bool isSplitWindowVisible();
void setSplitWindowOrientation(Qt::Orientation orientation);
MainWindow *q;
TweetDialog *m_tweetDialog;
TimerDialog *m_timerDialog;
UpdateInfoDialog *m_updateInfoDialog;
FleetDetailDialog *m_fleetDetailDialog;
FavoriteMenu m_favorite;
RecordingThread recordingThread;
bool dontViewButtleResult; //録画中は戦績表示しない
bool muteTimerSound; //録画中はミュート
RecognizeInfo m_recognizeInfo;
public:
Ui::MainWindow ui;
QSettings settings; //設定管理
QSystemTrayIcon trayIcon; //トレイアイコン
bool notUseCookie;
public slots:
void clickItem(){}
};
MainWindow::Private::Private(MainWindow *parent, bool not_use_cookie)
: q(parent)
, settings(QSettings::IniFormat, QSettings::UserScope, KANMEMO_PROJECT, KANMEMO_NAME)
, trayIcon(QIcon(":/resources/KanmusuMemory32.png"))
, m_favorite(q)
, notUseCookie(not_use_cookie)
, m_recognizeInfo(q)
{
ui.setupUi(q);
//Web関連の設定
setWebSettings();
//ダイアログの作成
makeDialog();
//戦績報告を非表示
ui.viewButtleResult->setVisible(false);
ui.viewButtleResult2->setVisible(false);
setButtleResultPosition();
///////////////////////////////////////////////////////////////
/// メニュー
///////////////////////////////////////////////////////////////
connect(ui.capture, &QAction::triggered, [this](){ captureGame(); });
connect(m_tweetDialog, &TweetDialog::triggeredCapture, [this]() { captureGame(); });
connect(ui.actionCaptureAndEdit, &QAction::triggered, [this]() { captureGame(true); });
connect(m_tweetDialog, &TweetDialog::triggeredCaptureAndEdit, [this]() { captureGame(true); });
#ifndef DISABLE_CATALOG_AND_DETAIL_FLEET
connect(ui.captureCatalog, &QAction::triggered, [this](){ captureCatalog(); });
connect(ui.captureFleetDetail, &QAction::triggered, [this](){ captureFleetDetail(); });
#else
//艦隊詳細
connect(ui.captureFleetDetail, &QAction::triggered, [this](){ openManualCaptureFleetDetail(); });
connect(m_tweetDialog, &TweetDialog::triggeredCaptureFleetDetail, [this]() { openManualCaptureFleetDetail(); });
connect(m_fleetDetailDialog, &FleetDetailDialog::finishedCaptureImages, [this](FleetDetailDialog::NextOperationType next, QStringList file_list, int item_width, int item_height, int columns){
finishManualCaptureFleetDetail(next, file_list, item_width, item_height, columns);
});
connect(m_fleetDetailDialog, &FleetDetailDialog::finished, [this](int result) {
Q_UNUSED(result);
finishManualCaptureFleetDetail(FleetDetailDialog::None, QStringList(), 0, 0, 1);
});
#endif
//艦隊リスト
connect(ui.captureFleetList, &QAction::triggered, [this](){ openManualCaptureFleetList(); });
connect(m_tweetDialog, &TweetDialog::triggeredCaptureFleetList, [this]() { openManualCaptureFleetList(); });
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]() { openMemoryDialog(); });
connect(m_tweetDialog, &TweetDialog::triggeredViewMemories, [this]() { openMemoryDialog(); });
//通知タイマー
connect(ui.notificationTimer, &QAction::triggered, [this]() { m_timerDialog->show(); });
connect(m_tweetDialog, &TweetDialog::triggeredNotificationTimer, [this]() { m_timerDialog->show(); });
//設定ダイアログ表示
connect(ui.preferences, &QAction::triggered, [this]() { openSettingDialog(); });
//アバウト
connect(ui.about, &QAction::triggered, [this]() { openAboutDialog(); });
//ツールバーの表示/非表示
connect(ui.actionViewToolBar, &QAction::changed, [this](){
ui.toolBar->setVisible(ui.actionViewToolBar->isChecked());
});
///////////////////////////////////////////////////////////////
/// 録画
///////////////////////////////////////////////////////////////
//起動時は必ず非表示
ui.recordLayout->setVisible(false);
//録画
connect(ui.actionRecord, &QAction::triggered, [this]() {
ui.recordLayout->setVisible(!ui.recordLayout->isVisible());
});
//録画設定
connect(ui.actionRecordPreferences, &QAction::triggered, [this](){
openRecordSettingDialog();
});
connect(ui.recordPreferencesButton, &QPushButton::clicked, [this](bool checked){
Q_UNUSED(checked);
openRecordSettingDialog();
});
//録画開始停止
connect(ui.recordButton, &QPushButton::clicked, [this](bool checked){
qDebug() << "click record button";
Q_UNUSED(checked);
settings.beginGroup(SETTING_RECORD);
recordingThread.setFps(settings.value(SETTING_RECORD_FPS, 20).toInt());
recordingThread.setAudioInputName(settings.value(SETTING_RECORD_AUDIO_SOURCE).toString());
QString save(settings.value(SETTING_RECORD_SAVE_PATH, QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)).toString());
if(save.right(1).compare("/") != 0){
save += "/";
}
recordingThread.setSavePath(save + makeFileName("mp4", false));
recordingThread.setToolPath(settings.value(SETTING_RECORD_TOOL_PATH, "ffmpeg").toString());
recordingThread.setTempPath(settings.value(SETTING_RECORD_TEMP_PATH, recordingThread.tempPath()).toString());
recordingThread.setSoundOffset(settings.value(SETTING_RECORD_SOUND_OFFSET, 0).toInt());
dontViewButtleResult = settings.value(SETTING_RECORD_DONT_VIEW_BUTTLE, true).toBool();
muteTimerSound = settings.value(SETTING_RECORD_MUTE_TIMER_SOUND, true).toBool();
settings.endGroup();
if(!recordingThread.isSettingValid()){
QMessageBox::warning(q, "warning", "Please input recording settings.");
openRecordSettingDialog();
}else if(!ui.webView->gameExists()){
ui.statusBar->showMessage(tr("failed to started recording."), STATUS_BAR_MSG_TIME);
}else if(recordingThread.status() == RecordingThread::Ready){
// recordingThread.setToolPath(QStringLiteral("D:\\ffmpeg\\bin\\ffmpeg.exe"));
// recordingThread.setToolParam(QStringLiteral("-r %1 -i %2 -vcodec libx264 -qscale:v 0 %3"));
// recordingThread.setSavePath(QStringLiteral("d:\\temp\\rec\\") + makeFileName("mp4", false));
// recordingThread.setAudioInputName(recordingThread.audioInputNames().at(0));
// recordingThread.setFps(20);
ui.recordButton->setChecked(true);
//ミュートする
m_timerDialog->setAlarmMute(muteTimerSound);
//録音開始
recordingThread.setWebView(ui.webView);
recordingThread.startRecording();
}else if(recordingThread.status() == RecordingThread::Recording){
//録音停止
recordingThread.stopRecording();
//ミュート解除
m_timerDialog->setAlarmMute(false);
//ボタンの表示
ui.recordButton->setChecked(false);
}else{
}
});
//録画の状態変化
connect(&recordingThread, &RecordingThread::statusChanged, [this](RecordingThread::RecordingStatus status){
switch(status){
case RecordingThread::Ready:
ui.recordStatusLabel->setText("Ready");
break;
case RecordingThread::Recording:
ui.recordStatusLabel->setText("Recording");
break;
case RecordingThread::Saving:
ui.recordStatusLabel->setText("Saving");
break;
case RecordingThread::Convert:
ui.recordStatusLabel->setText("Convert");
break;
default:
ui.recordStatusLabel->setText("Error");
break;
}
});
//録画時間
connect(&recordingThread, &RecordingThread::durationChanged, [this](const qint64 &duration){
long min = (duration / 1000) / 60;
long sec = (duration / 1000) % 60;
ui.recordingTimeLabel->setText(QString("%1:%2").arg(min, 2, 10, QLatin1Char('0')).arg(sec, 2, 10, QLatin1Char('0')));
});
//録画のテンポラリフォルダ作成
recordingThread.getTempPath(); //呼べば無ければ作られる
///////////////////////////////////////////////////////////////
/// ブラウザ
///////////////////////////////////////////////////////////////
//フルスクリーン
#ifdef Q_OS_MAC
//Macではショートカット無効(tweetDialogをモードレスにしたらctrl+Enterがかぶって拾えなくなったから)
ui.actionFullScreen->setShortcut(QKeySequence());
#endif
ui.actionFullScreen->setEnabled(false); //フルスクリーンすぐに直せないから
q->addAction(ui.actionFullScreen);
connect(ui.actionFullScreen, &QAction::triggered, [this]() {
if(q->isFullScreen()){
//フルスクリーン解除
q->setWindowState(q->windowState() ^ Qt::WindowFullScreen);
}else if(ui.webView->gameExists()){
//フルスクリーンじゃなくてゲームがある
ui.recordLayout->setVisible(false);
setSplitWindowVisiblity(false);
q->setWindowState(q->windowState() ^ Qt::WindowFullScreen);
}else{
//フルスクリーンでゲームがないときは何もしない
}
});
//ズーム
setGameSize(1); //初期状態
connect(ui.actionZoom050, &QAction::triggered, [this](){ setGameSize(0.5); });
connect(ui.actionZoom075, &QAction::triggered, [this](){ setGameSize(0.75); });
connect(ui.actionZoom100, &QAction::triggered, [this](){ setGameSize(1); });
connect(ui.actionZoom125, &QAction::triggered, [this](){ setGameSize(1.25); });
connect(ui.actionZoom150, &QAction::triggered, [this](){ setGameSize(1.5); });
connect(ui.actionZoom175, &QAction::triggered, [this](){ setGameSize(1.75); });
connect(ui.actionZoom200, &QAction::triggered, [this](){ setGameSize(2); });
//崩れるのでなし
ui.actionZoom050->setVisible(false);
ui.actionZoom075->setVisible(false);
///////////////////////////////////////////////////////////////
/// ウインドウ
///////////////////////////////////////////////////////////////
//ウインドウ分割
connect(ui.actionSplitWindow, &QAction::triggered, [this]() {
setSplitWindowVisiblity(!isSplitWindowVisible());
});
//左右に分割
connect(ui.actionHorizontalSplit, &QAction::triggered, [this]() {
setSplitWindowOrientation(Qt::Horizontal);
if(!isSplitWindowVisible())
setSplitWindowVisiblity(true);
});
//上下に分割
connect(ui.actionVerticalSplit, &QAction::triggered, [this]() {
setSplitWindowOrientation(Qt::Vertical);
if(!isSplitWindowVisible())
setSplitWindowVisiblity(true);
});
//分割を解除
connect(ui.actionDisableSplit, &QAction::triggered, [this]() {
if(isSplitWindowVisible())
setSplitWindowVisiblity(false);
});
//タブウインドウの再読み込み
connect(ui.actionReloadTab, &QAction::triggered, [this]() {
if(!isSplitWindowVisible())
return;
ui.tabWidget->reloadTab();
});
//タブウインドウにタブを追加
connect(ui.actionAddTab, &QAction::triggered, [this]() {
if(!isSplitWindowVisible())
return;
ui.tabWidget->newTab(QUrl("http://www.google.co.jp"));
});
//タブウインドウでタブを削除
connect(ui.actionRemoveTab, &QAction::triggered, [this]() {
if(!isSplitWindowVisible())
return;
ui.tabWidget->closeTab();
});
//タブで検索
q->addAction(ui.actionFindInTab);
connect(ui.actionFindInTab, &QAction::triggered, [this]() {
if(!isSplitWindowVisible())
return;
ui.tabWidget->find();
});
//タブ移動
q->addAction(ui.actionTabSwitchPrev);
q->addAction(ui.actionTabSwitchNext);
q->addAction(ui.actionTabSwitchPrev2);
q->addAction(ui.actionTabSwitchNext2);
connect(ui.actionTabSwitchPrev, &QAction::triggered, [this]() {
if(!isSplitWindowVisible())
return;
ui.tabWidget->prevTab();
});
connect(ui.actionTabSwitchNext, &QAction::triggered, [this]() {
if(!isSplitWindowVisible())
return;
ui.tabWidget->nextTab();
});
connect(ui.actionTabSwitchPrev2, &QAction::triggered, [this]() {
if(!isSplitWindowVisible())
return;
ui.tabWidget->prevTab();
});
connect(ui.actionTabSwitchNext2, &QAction::triggered, [this]() {
if(!isSplitWindowVisible())
return;
ui.tabWidget->nextTab();
});
///////////////////////////////////////////////////////////////
/// WebView
///////////////////////////////////////////////////////////////
//WebViewをクリック
connect(ui.webView, &WebView::mousePressed, [this](QMouseEvent *event) {
//艦隊の被弾状況を調べる
checkMajorDamageShip(event->localPos());
//遠征の残り時間を調べる
checkExpeditionRemainTime(event->localPos());
});
//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);
setGameSize(1); //元に戻す
// if(ui.webView->url().toString().compare(URL_KANCOLLE) == 0){
// qDebug() << "complete:" << ui.webView->url();
// 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);
///////////////////////////////////////////////////////////////
/// お気に入り
///////////////////////////////////////////////////////////////
//お気に入りの読込み
m_favorite.load(ui.favorite, true);
//お気に入りを選択した
connect(&m_favorite, &FavoriteMenu::selectFav, [this](const QUrl &url){
if(!isSplitWindowVisible())
setSplitWindowVisiblity(true);
ui.tabWidget->openUrl(url);
});
//お気に入りの更新
connect(ui.tabWidget, &TabWidget::updateFavorite, [this]() {
m_favorite.load(ui.favorite);
});
//お気に入りのダウンロード終了
connect(&m_favorite, &FavoriteMenu::downloadFinished, [this]() {
m_favorite.load(ui.favorite);
});
///////////////////////////////////////////////////////////////
/// ツイートダイアログ
/// ///////////////////////////////////////////////////////////
connect(m_tweetDialog, &TweetDialog::accepted, [this](){
//OK
settings.setValue(SETTING_GENERAL_TOKEN, m_tweetDialog->token());
settings.setValue(SETTING_GENERAL_TOKENSECRET, m_tweetDialog->tokenSecret());
settings.setValue(SETTING_GENERAL_USER_ID, m_tweetDialog->user_id());
settings.setValue(SETTING_GENERAL_SCREEN_NAME, m_tweetDialog->screen_name());
});
connect(m_tweetDialog, &TweetDialog::rejected, [this](){
//cancel
settings.setValue(SETTING_GENERAL_TOKEN, m_tweetDialog->token());
settings.setValue(SETTING_GENERAL_TOKENSECRET, m_tweetDialog->tokenSecret());
settings.setValue(SETTING_GENERAL_USER_ID, m_tweetDialog->user_id());
settings.setValue(SETTING_GENERAL_SCREEN_NAME, m_tweetDialog->screen_name());
});
///////////////////////////////////////////////////////////////
/// アップデート
///////////////////////////////////////////////////////////////
//アップデートの確認をする
m_updateInfoDialog->CheckUpdate();
connect(ui.actionUpdate, &QAction::triggered, [this](){ m_updateInfoDialog->CheckUpdate(); });
//アプデート確認の情報を元にお気に入りのアップデート
connect(m_updateInfoDialog, &UpdateInfoDialog::lastFavoriteUpdateDateChanged, [this](const QString &lastFavoriteUpdateDate){
m_favorite.updateFromInternet(lastFavoriteUpdateDate);
});
//アプデート確認の情報を元にタイマーのアップデート
connect(m_updateInfoDialog, &UpdateInfoDialog::lastTimerSelectGuideUpdateDateChanged, [this](const QString &lastTimerSelectGuideUpdateDate){
m_timerDialog->setLastTimerSelectGuideUpdateDate(lastTimerSelectGuideUpdateDate);
});
//アップデート確認の情報を元に画像解析情報のアップデート
connect(m_updateInfoDialog, &UpdateInfoDialog::lastRecognizeInfoUpdateDateChanged, [this](const QString &lastRecognizeInfoUpdateDate){
m_recognizeInfo.updateFromInternet(lastRecognizeInfoUpdateDate);
});
//画像解析系の設定を保持するクラス
m_recognizeInfo.load();
//アップデート確認
connect(&m_recognizeInfo, &RecognizeInfo::downloadFinished, [this](){
m_recognizeInfo.load();
});
//通知アイコン
#ifdef Q_OS_WIN
trayIcon.show();
#endif
#ifdef DISABLE_CATALOG_AND_DETAIL_FLEET
ui.captureCatalog->setVisible(false);
// ui.captureFleetDetail->setVisible(false);
#endif
}
MainWindow::Private::~Private()
{
delete m_fleetDetailDialog;
delete m_updateInfoDialog;
delete m_timerDialog;
delete m_tweetDialog;
}
//指定範囲をマスクする
void MainWindow::Private::maskImage(QImage *img, const QRect &rect)
{
int y0 = rect.y();
int x0 = rect.x();
int h = rect.height();
int w = rect.width();
for (int y = 0; y < h; y++) {
QRgb *row = reinterpret_cast<QRgb *>(img->scanLine(y0 + y)) + x0;
QRgb pixel = row[0];
for (int x = 0; x < w; x++) {
(*row++) = pixel;
}
}
}
//ファイル名を作成する
QString MainWindow::Private::makeFileName(const QString &format, bool isfull) const
{
if(isfull){
return QStringLiteral("%1/kanmusu_%2.%3")
.arg(settings.value(QStringLiteral("path")).toString())
.arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz")))
.arg(format.toLower());
}else{
return QStringLiteral("kanmusu_%1.%2")
.arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz")))
.arg(format.toLower());
}
}
//テンポラリのファイル名を作成する
QString MainWindow::Private::makeTempFileName(const QString &format) const
{
return QStringLiteral("%1/kanmusu_temp%2.%3")
.arg(QDir::tempPath())
.arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz")))
.arg(format.toLower());
}
//思い出を残す
void MainWindow::Private::captureGame(bool andEdit)
{
qDebug() << "captureGame";
//設定確認
checkSavePath();
//戦績報告のプレビューを一時的に消してキャプチャー
bool old_buttle_result = ui.viewButtleResult->isVisible();
bool old_buttle_result2 = ui.viewButtleResult2->isVisible();
ui.viewButtleResult->setVisible(false);
ui.viewButtleResult2->setVisible(false);
QImage img = ui.webView->capture();
ui.viewButtleResult->setVisible(old_buttle_result);
ui.viewButtleResult2->setVisible(old_buttle_result2);
if (img.isNull()){
ui.statusBar->showMessage(tr("failed capture image"), STATUS_BAR_MSG_TIME);
return;
}
GameScreen gameScreen(img, &m_recognizeInfo);
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);
}
}
}
//保存場所の確認
void MainWindow::Private::checkSavePath()
{
if(!settings.contains(QStringLiteral("path"))){
//設定を促す
QMessageBox::information(q
, tr("Kan Memo")
, tr("Please select a folder to save the image of KanMusu."));
QString savePath = SettingsDialog::selectSavePath(q, QDir::homePath());
if (savePath.isEmpty()) {
ui.statusBar->showMessage(tr("canceled"), STATUS_BAR_MSG_TIME);
return;
}
settings.setValue(QStringLiteral("path"), savePath);
}
}
//ツイートダイアログを開く
void MainWindow::Private::openTweetDialog(const QString &path, bool force)
{
//連携を使用しない
if(force == false && settings.value(SETTING_GENERAL_UNUSED_TWITTER, false).toBool()){
QMessageBox::information(q
, tr("Kan Memo")
, tr("saving to %1...").arg(path));
}else{
//画像を追加してダイアログを開く
m_tweetDialog->setToken(settings.value(SETTING_GENERAL_TOKEN, "").toString());
m_tweetDialog->setTokenSecret(settings.value(SETTING_GENERAL_TOKENSECRET, "").toString());
m_tweetDialog->user_id(settings.value(SETTING_GENERAL_USER_ID, "").toString());
m_tweetDialog->screen_name(settings.value(SETTING_GENERAL_SCREEN_NAME, "").toString());
m_tweetDialog->addImagePath(path);
m_tweetDialog->show();
}
}
//画像リストダイアログを開く
void MainWindow::Private::openMemoryDialog()
{
checkSavePath();
MemoryDialog dlg(settings.value(QStringLiteral("path")).toString(), q);
dlg.exec();
switch(dlg.nextOperation()){
case MemoryDialog::Tweet:
{
//つぶやく
foreach (QString file, dlg.selectedFiles()) {
if(QFile::exists(file)){
openTweetDialog(file, true);
}
}
break;
}
case MemoryDialog::Edit:
{
//編集
if(QFile::exists(dlg.imagePath())){
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;
}
}
//設定ダイアログを開く
void MainWindow::Private::openSettingDialog()
{
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());
dlg.setProxyEnable(settings.value(SETTING_GENERAL_PROXY_ENABLE, false).toBool());
dlg.setProxyHost(settings.value(SETTING_GENERAL_PROXY_HOST).toString());
dlg.setProxyPort(settings.value(SETTING_GENERAL_PROXY_PORT, 8888).toInt());
dlg.setUseCookie(settings.value(SETTING_GENERAL_USE_COOKIE, true).toBool());
dlg.setDisableContextMenu(settings.value(SETTING_GENERAL_DISABLE_CONTEXT_MENU, false).toBool());
dlg.setDisableExitShortcut(settings.value(SETTING_GENERAL_DISABLE_EXIT, DISABLE_EXIT_DEFAULT).toBool());
dlg.setViewButtleResult(settings.value(QStringLiteral(SETTING_GENERAL_VIEW_BUTTLE_RESULT), true).toBool());
dlg.setOperatingCombinedFleet(settings.value(QStringLiteral(SETTING_GENERAL_BUTTLE_RESULT_COMBINED), true).toBool());
dlg.setButtleResultPosition(static_cast<SettingsDialog::ButtleResultPosition>(settings.value(QStringLiteral(SETTING_GENERAL_BUTTLE_RESULT_POSITION), 1).toInt()));
dlg.setButtleResultDirection(static_cast<QBoxLayout::Direction>(settings.value(QStringLiteral(SETTING_GENERAL_BUTTLE_RESULT_DIRECTION), 2).toInt()));
dlg.setButtleResultOpacity(settings.value(QStringLiteral(SETTING_GENERAL_VIEW_BUTTLE_RESULT_OPACITY), 0.75).toReal());
dlg.setTimerAutoStart(settings.value(QStringLiteral(SETTING_GENERAL_TIMER_AUTO_START), true).toBool());
settings.beginGroup(QStringLiteral(SETTING_TIMER));
dlg.setTweetFinished(settings.value(QStringLiteral(SETTING_TIMER_TWEETFINISHED),false).toBool());
settings.endGroup();
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());
settings.setValue(SETTING_GENERAL_PROXY_ENABLE, dlg.isProxyEnable());
settings.setValue(SETTING_GENERAL_PROXY_HOST, dlg.proxyHost());
settings.setValue(SETTING_GENERAL_PROXY_PORT, dlg.proxyPort());
settings.setValue(SETTING_GENERAL_USE_COOKIE, dlg.useCookie());
settings.setValue(SETTING_GENERAL_DISABLE_CONTEXT_MENU, dlg.disableContextMenu());
settings.setValue(SETTING_GENERAL_DISABLE_EXIT, dlg.disableExitShortcut());
settings.setValue(SETTING_GENERAL_VIEW_BUTTLE_RESULT, dlg.viewButtleResult());
settings.setValue(SETTING_GENERAL_BUTTLE_RESULT_COMBINED, dlg.operatingCombinedFleet());
settings.setValue(SETTING_GENERAL_BUTTLE_RESULT_POSITION, static_cast<int>(dlg.buttleResultPosition()));
settings.setValue(SETTING_GENERAL_BUTTLE_RESULT_DIRECTION, static_cast<int>(dlg.buttleResultDirection()));
settings.setValue(SETTING_GENERAL_VIEW_BUTTLE_RESULT_OPACITY, dlg.buttleResultOpacity());
settings.setValue(SETTING_GENERAL_TIMER_AUTO_START, dlg.timerAutoStart());
//戦果報告の表示位置などを更新
ui.viewButtleResult->setVisible(ui.viewButtleResult->isVisible() & dlg.viewButtleResult());
ui.viewButtleResult2->setVisible(ui.viewButtleResult2->isVisible() & dlg.viewButtleResult());
setButtleResultPosition();
//タイマーの時間でつぶやく
if(m_timerDialog != NULL){
//ダイアログとの連携の関係で保存はダイアログのクラスでする
m_timerDialog->setTweetFinished(dlg.tweetFinished());
}
//設定反映(必要なの)
//プロキシ
updateProxyConfiguration();
//右クリックメニュー無効
ui.webView->setDisableContextMenu(dlg.disableContextMenu());
//Ctrl+Qを無効化
if(dlg.disableExitShortcut()){
ui.exit->setShortcut(QKeySequence());
}else{
ui.exit->setShortcut(QKeySequence(QStringLiteral("Ctrl+Q")));
}
}
}
//録画の設定ダイアログを開く
void MainWindow::Private::openRecordSettingDialog()
{
RecordingDialog dlg(q);
settings.beginGroup(SETTING_RECORD);
dlg.setFps(settings.value(SETTING_RECORD_FPS, 20).toInt());
dlg.setAudioSource(settings.value(SETTING_RECORD_AUDIO_SOURCE, recordingThread.audioInputNames().at(0)).toString());
dlg.setSavePath(settings.value(SETTING_RECORD_SAVE_PATH, QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)).toString());
dlg.setToolPath(settings.value(SETTING_RECORD_TOOL_PATH, "ffmpeg").toString());
dlg.setTempPath(settings.value(SETTING_RECORD_TEMP_PATH, recordingThread.tempPath()).toString());
dlg.setSoundOffset(settings.value(SETTING_RECORD_SOUND_OFFSET, 0).toInt());
dlg.setDontViewButtleResult(settings.value(SETTING_RECORD_DONT_VIEW_BUTTLE, true).toBool());
dlg.setMuteNotificationSound(settings.value(SETTING_RECORD_MUTE_TIMER_SOUND, true).toBool());
settings.endGroup();
dlg.setDefaultFps(20);
dlg.setDefaultAudioSource(recordingThread.audioInputNames().at(0));
dlg.setDefaultSavePath(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation));
dlg.setDefaultToolPath("ffmpeg");
dlg.setDefaultTempPath(recordingThread.tempPath());
dlg.setDefaultSoundOffset(0);
dlg.setDefaultDontViewButtleResult(true);
dlg.setDefaultMuteNotificationSound(true);
if(dlg.exec()){
settings.beginGroup(SETTING_RECORD);
settings.setValue(SETTING_RECORD_FPS, dlg.fps());
settings.setValue(SETTING_RECORD_AUDIO_SOURCE, dlg.audioSource());
settings.setValue(SETTING_RECORD_SAVE_PATH, dlg.savePath());
settings.setValue(SETTING_RECORD_TOOL_PATH, dlg.toolPath());
settings.setValue(SETTING_RECORD_TEMP_PATH, dlg.tempPath());
settings.setValue(SETTING_RECORD_SOUND_OFFSET, dlg.soundOffset());
settings.setValue(SETTING_RECORD_DONT_VIEW_BUTTLE, dlg.dontViewButtleResult());
settings.setValue(SETTING_RECORD_MUTE_TIMER_SOUND, dlg.muteNotificationSound());
settings.endGroup();
dontViewButtleResult = dlg.dontViewButtleResult();
}
}
//Update proxy setting.
void MainWindow::Private::updateProxyConfiguration()
{
// Update proxy setting.
QNetworkAccessManager * accessmanager = ui.webView->page()->networkAccessManager();
QNetworkProxy * proxy = new QNetworkProxy();
bool enable = settings.value(SETTING_GENERAL_PROXY_ENABLE, false).toBool();
QString host = settings.value(SETTING_GENERAL_PROXY_HOST).toString();
if(host.length() > 0 && enable)
{
proxy->setType(QNetworkProxy::HttpProxy);
proxy->setHostName(host);
proxy->setPort(settings.value(SETTING_GENERAL_PROXY_PORT, 8888).toInt());
accessmanager->setProxy(*proxy);
}
else
{
accessmanager->setProxy(QNetworkProxy::NoProxy);
}
}
//アバウトダイアログを開く
void MainWindow::Private::openAboutDialog()
{
AboutDialog dlg(q);
dlg.setVersion(KANMEMO_VERSION);
dlg.setDevelopers(KANMEMO_DEVELOPERS);
dlg.exec();
}
//編集ダイアログを開く
void MainWindow::Private::openImageEditDialog(const QString &path, const QString &tempPath, const QString &editPath)
{
ImageEditDialog dlg(path, tempPath, editPath, q);
dlg.exec();
if(QFile::exists(dlg.editImagePath()) && dlg.nextOperation() == ImageEditDialog::SaveAndTweet){
//つぶやく
openTweetDialog(dlg.editImagePath());
}
}
//艦隊詳細を作成するダイアログを表示する
void MainWindow::Private::openManualCaptureFleetDetail()
{
//設定確認
checkSavePath();
//メニューを一時停止
ui.capture->setEnabled(false);
ui.actionCaptureAndEdit->setEnabled(false);
ui.captureCatalog->setEnabled(false);
ui.captureFleetDetail->setEnabled(false);
ui.captureFleetList->setEnabled(false);
//設定変更
QStringList fdd_msg_list;
fdd_msg_list << tr("Please to capture with a detailed view of the ship in the organization screen.");
fdd_msg_list << tr("The following buttons appear when you capture.");
fdd_msg_list << tr("Combine the image you have captured on completion.");
m_fleetDetailDialog->setParameters(DETAIL_RECT_CAPTURE, 0.3, 2, 6, fdd_msg_list);
//クリア
m_fleetDetailDialog->clear();
//表示
m_fleetDetailDialog->setWindowTitle(tr("Fleet Detail"));
m_fleetDetailDialog->show();
m_fleetDetailDialog->raise();
m_fleetDetailDialog->activateWindow();
}
//艦隊リストを作成するダイアログを表示する
void MainWindow::Private::openManualCaptureFleetList()
{
//設定確認
checkSavePath();
//メニューを一時停止
ui.capture->setEnabled(false);
ui.actionCaptureAndEdit->setEnabled(false);
ui.captureCatalog->setEnabled(false);
ui.captureFleetDetail->setEnabled(false);
ui.captureFleetList->setEnabled(false);
//設定変更
QStringList fdd_msg_list;
fdd_msg_list << tr("Please be captured by a selection list of warships in the scheduling screen.");
fdd_msg_list << tr("The following buttons appear when you capture.");
fdd_msg_list << tr("Combine the image you have captured on completion.");
m_fleetDetailDialog->setParameters(FLEETLIST_RECT_CAPTURE, 0.3, 4, 20, fdd_msg_list);
//クリア
m_fleetDetailDialog->clear();
//表示
m_fleetDetailDialog->setWindowTitle(tr("Fleet List"));
m_fleetDetailDialog->show();
m_fleetDetailDialog->raise();
m_fleetDetailDialog->activateWindow();
}
//艦隊詳細作成ダイアログ終了時の処理
void MainWindow::Private::finishManualCaptureFleetDetail(FleetDetailDialog::NextOperationType next, QStringList file_list, int item_width, int item_height, int columns)
{
if(next == FleetDetailDialog::Combine){
QString path = combineImage(file_list, item_width, item_height, columns);
if(path.length() > 0)
openTweetDialog(path);
}
//メニューを復活
ui.capture->setEnabled(true);
ui.actionCaptureAndEdit->setEnabled(true);
ui.captureCatalog->setEnabled(true);
ui.captureFleetDetail->setEnabled(true);
ui.captureFleetList->setEnabled(true);
}
//ゲーム画面へクリックイベントを送る
void MainWindow::Private::clickGame(QPoint pos, bool wait_little)
{
int interval = CLICK_EVENT_INTERVAL;
QPointF posf(pos);
QMouseEvent eventPress(QEvent::MouseButtonPress
, posf
, Qt::LeftButton, 0, 0);
QApplication::sendEvent(ui.webView, &eventPress);
QMouseEvent eventRelease(QEvent::MouseButtonRelease
, posf
, Qt::LeftButton, 0, 0);
QApplication::sendEvent(ui.webView, &eventRelease);
if(wait_little)
interval = CLICK_EVENT_INTERVAL_LITTLE;
interval += static_cast<int>(qrand() % CLICK_EVENT_FLUCTUATION);
for(int i = 0; i < interval; i++)
{
QApplication::processEvents();
QThread::usleep(1000);
}
}
//画像を結合する(主に艦隊詳細)
QString MainWindow::Private::combineImage(QStringList file_list, int item_width, int item_height, int columns)
{
if(file_list.length() == 0 || columns < 1)
return QString();
int rows = qCeil(static_cast<qreal>(file_list.length()) / static_cast<qreal>(columns));
int x = 0;
int y = 0;
//画像の数が列数より小さい時は列数を調節する
if(file_list.length() < columns){
columns = file_list.length();
}
//結合画像を作る
QImage resultImage(item_width * columns, item_height * rows, QImage::Format_ARGB32);
QPainter painter(&resultImage);
painter.fillRect(resultImage.rect(), "#ece3d4");
for(int i=0; i<file_list.length(); i++){
QImage item = QImage(file_list[i]);
painter.drawImage(x, y, item);
if((i % columns) == (columns - 1)){
x = 0;
y += item_height;
}else{
x += item_width;
}
}
//パスをつくる
QString format;
if(settings.value(SETTING_GENERAL_SAVE_PNG, false).toBool())
format = QStringLiteral("png");
else
format = QStringLiteral("jpg");
QString path = makeFileName(format);
//保存
resultImage.save(path);