-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
185 lines (158 loc) · 8.11 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "settingswindow.h"
#include "editsermon.h"
#include "findsermon.h"
#include "publishsermon.h"
#include "databasesupport.h"
#define ABOUTTEXT \
"<i><b>Message Librarian</b> © 2016 - 2019 by Stanley B. Gehman.</i><p>"\
"This software is intended to assist the organizational efforts of those "\
"responsible to maintain audio sermon libraries. It is free of charge; however, "\
"if you wish to contribute to the project either through code or by donations, "\
"we do welcome your input. Due to the nature of free software, we do not provide "\
"any warranty, expressed or implied.<p>Tech support may be somewhat limited, but "\
"we encourage you to report bugs and request new features. For more details, "\
"please see the README.md file included with the "\
"<a href="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/Stanley-G/message-librarian">source code on GitHub</a>. "\
"We look forward to hearing from you.<p>Contact: <b>Stanley Gehman</b> Email: "\
"<b><u>[email protected]</u></b> Phone: <b>(217) 254 - 4403</b>"\
#define NOTIMPLEMENTEDTEXT \
"We're sorry, this feature is not available in this release. "\
"Please stay tuned for available updates!"\
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
globalSettings = new QSettings("TrueLife Tracks", "Message Librarian", this);
findwin = NULL;
InitTableModelAndView();
}
void MainWindow::InitTableModelAndView()
{
sermonTableModel = new QSqlTableModel(this, QSqlDatabase::database());
sermonTableModel->setTable(DatabaseSupport::GetCompatibleDBTableName());
sermonTableModel->setSort(Sermon_Date, Qt::AscendingOrder);
sermonTableModel->select();
sortFilterSermonModel = new SermonSortFilterProxyModel(); //Invokes our custom sermon search-and-sort engine
sortFilterSermonModel->setSourceModel(sermonTableModel);
sermonTableModel->setHeaderData(Sermon_ID, Qt::Horizontal, "Audio Binding");
sermonTableModel->setHeaderData(Sermon_Title, Qt::Horizontal, "Title");
sermonTableModel->setHeaderData(Sermon_Speaker, Qt::Horizontal, "Speaker");
sermonTableModel->setHeaderData(Sermon_Location, Qt::Horizontal, "Location");
sermonTableModel->setHeaderData(Sermon_Date, Qt::Horizontal, "Date");
sermonTableModel->setHeaderData(Sermon_Description, Qt::Horizontal, "Description");
sermonTableModel->setHeaderData(Sermon_Transcription, Qt::Horizontal, "Transcription");
ui->mainSermonTableView->setModel(sortFilterSermonModel);
ui->mainSermonTableView->setSortingEnabled(true); //Turn sort-by-header-click on.
ui->mainSermonTableView->horizontalHeader()->setSortIndicator(Sermon_Date, Qt::AscendingOrder); //Specifies the default sort order and column for the table view.
ui->mainSermonTableView->horizontalHeader()->moveSection(Sermon_ID, Sermon_Description); //Awsome code!! moves columns around in the table view without changing the order in the sql table itself!
ui->mainSermonTableView->horizontalHeader()->setSectionResizeMode(Sermon_Title, QHeaderView::Stretch);
ui->mainSermonTableView->resizeColumnsToContents();
ui->mainSermonTableView->setColumnWidth(Sermon_ID, 130);
ui->mainSermonTableView->setColumnWidth(Sermon_Transcription, 130);
ui->mainSermonTableView->setItemDelegateForColumn(Sermon_ID, new StatusIndicatorDelegate); //Invokes our custom state indicator icons for certain data types in our table.
ui->mainSermonTableView->setItemDelegateForColumn(Sermon_Transcription, new StatusIndicatorDelegate); //Same here.
ui->mainSermonTableView->selectRow(globalSettings->value("metadata/lastActiveSermon", "0").toInt());
on_mainSermonTableView_clicked(sermonTableModel->index(globalSettings->value("metadata/lastActiveSermon", "0").toInt(), 1)); //It is not necessary to know which column, as that is specified later.
setCentralWidget(ui->mainSermonTableView);
}
MainWindow::~MainWindow()
{
delete ui;
delete globalSettings;
delete sermonTableModel;
}
void MainWindow::closeEvent(QCloseEvent *event)
{
//Save current sermon selection from main table.
globalSettings->setValue("metadata/lastActiveSermon", ui->mainSermonTableView->currentIndex().row());
event->accept();
}
//This is a public setter
void MainWindow::SetCurrentModelIndex(QPersistentModelIndex *index)
{
currentModelIndex = index;
ui->mainSermonTableView->selectRow(currentModelIndex->row());
on_mainSermonTableView_clicked(static_cast <QModelIndex> (*index)); //impressive cast operation!
}
void MainWindow::on_actionAbout_triggered()
{
QMessageBox::about(this, "Audio Sermon Organizer", ABOUTTEXT);
}
void MainWindow::on_actionExit_triggered()
{
// This code runs AFTER the main window is destroyed. All saving of data must be done in the reimplemented 'closeEvent'!
QCoreApplication::quit();
}
void MainWindow::on_actionEdit_triggered()
{
//Here we set the ID of the currently selected sermon in MainWindow
currentModelIndex = new QPersistentModelIndex(ui->mainSermonTableView->currentIndex());
ui->mainSermonTableView->selectionModel()->reset(); //Added this to force custom delegates to repaint when they lose focus.
EditSermon newwin(globalSettings, sermonTableModel, this, "", currentModelIndex);
newwin.exec();
}
void MainWindow::on_actionPreferences_triggered()
{
SettingsWindow swin(globalSettings, this);
swin.exec();
}
void MainWindow::on_actionAbout_Qt_triggered()
{
QMessageBox::aboutQt(this);
}
void MainWindow::on_actionNew_triggered()
{
ui->mainSermonTableView->selectionModel()->reset(); //Added this to force custom delegates to repaint when they lose focus.
EditSermon newwin(globalSettings, sermonTableModel, this, "$#_Create_New"); //Invoke Edit Sermon ui with new blank sermon entry at the end.
newwin.exec();
}
void MainWindow::on_actionOpen_triggered()
{
QMessageBox::critical(this, "Not Implemented Yet", NOTIMPLEMENTEDTEXT);
}
void MainWindow::on_actionSearch_triggered()
{
if (findwin == NULL) { //This test avoids stacking multiple copies of the dialog on top of each other
findwin = new FindSermon(sortFilterSermonModel, this);
}
ui->mainSermonTableView->selectionModel()->reset(); //Added this to force custom delegates to repaint when they lose focus.
findwin->show();
findwin->raise();
findwin->activateWindow();
}
void MainWindow::on_actionPublish_triggered()
{
/* Development direction:
* Have a warning dialog pop up if no audio is bound to the entry. Give option to edit sermon where they could add files.
* If audio is available, display a dialog listing the files, with total playback time (to ensure that they will fit on CD.)
* - OR - do we want to do this check before we get this far, i.e. by disabling this action in MenuBar, etc. <- Chosen solution, for the time being
*/
// Deprecate unfinished feature for alpha release to VIPs.
/* ui->mainSermonTableView->selectionModel()->reset(); //Added this to force custom delegates to repaint when they lose focus.
* PublishSermon pubwin(globalSettings, sermonTableModel, currentModelIndex, this);
* pubwin.exec();
*/
QMessageBox::critical(this, "Not Implemented Yet", NOTIMPLEMENTEDTEXT);
}
void MainWindow::on_mainSermonTableView_doubleClicked(const QModelIndex &index)
{
//This will eventually OPEN the sermon, not EDIT it.
currentModelIndex = new QPersistentModelIndex(index);
ui->mainSermonTableView->selectionModel()->reset(); //Added this to force custom delegates to repaint when they lose focus.
EditSermon newwin(globalSettings, sermonTableModel, this, "", currentModelIndex); //Invoke Edit Sermon ui with current selected row from MainWindow as the current Sermon.
newwin.exec();
}
void MainWindow::on_mainSermonTableView_clicked(const QModelIndex &index)
{
/*
* enable/disable certain actions based on available data.
*/
// Disable Publishing if no audio is available.
if (sermonTableModel->record(index.row()).field(Sermon_ID).isNull())
ui->actionPublish->setEnabled(false);
else
ui->actionPublish->setEnabled(true);
}