8
8
// to the system's file path format before opening.
9
9
void MiniThingQt::OpenFilePath (const QString& filePath)
10
10
{
11
- QProcess process;
12
- QString adjustedPath = filePath;
13
- adjustedPath.replace (" /" , " \\ " );
11
+ QString adjustedPath = filePath.replace (" /" , " \\ " );
14
12
QString command = QString (" explorer.exe /select,\" %1\" " ).arg (adjustedPath);
15
- process. startDetached (command);
13
+ QProcess:: startDetached (command);
16
14
}
17
15
16
+
18
17
// Attempts to open a file at the specified path. Returns true if the file is successfully opened,
19
18
// and false with an error message if the file cannot be opened.
20
19
bool MiniThingQt::OpenFile (const QString& filePath)
@@ -32,84 +31,81 @@ MiniThingQt::MiniThingQt(QWidget* parent) : QMainWindow(parent)
32
31
m_ui.setupUi (this );
33
32
m_usnSet.clear ();
34
33
35
- // Setup logo icon
34
+ // Setup UI components
35
+ setupUIComponents ();
36
+ }
37
+
38
+ void MiniThingQt::setupUIComponents ()
39
+ {
40
+ // Setup logo and other UI elements
36
41
QIcon logo (" Logo.ico" );
37
42
this ->setWindowIcon (logo);
38
-
39
- // Setup background image
40
- // QPixmap backgroundImg = QPixmap("./Background.png").scaled(this->size());
41
43
QPalette palette;
42
- // palette.setBrush(QPalette::Window, QBrush(backgroundImg));
43
44
palette.setColor (QPalette::Window, QColor (255 , 255 , 255 ));
44
45
this ->setPalette (palette);
45
46
46
- // Setup status bar
47
+ // Status Bar setup
47
48
m_statusBar = new QLabel;
48
49
statusBar ()->addWidget (m_statusBar);
49
- statusBar ()->setStyleSheet (" QLabel{ color: black }" );
50
+ statusBar ()->setStyleSheet (" QLabel { color: black }" );
50
51
52
+ // Setup actions, menus, and other signal-slot connections
53
+ setupActionsAndMenus ();
51
54
m_pMiniThingCore = new MiniThingCore ();
52
55
m_pMiniThingQtWorkThread = new MiniThingQtWorkThread (m_pMiniThingCore, statusBar ());
53
56
54
57
// Connect UpdateStatusBar(), so we could update status bar in diff thread
55
58
connect (m_pMiniThingQtWorkThread, &MiniThingQtWorkThread::UpdateStatusBar, this , &MiniThingQt::UpdateStatusBar);
56
-
57
59
m_pMiniThingQtWorkThread->start ();
58
60
59
- // Monitor enter press in line edit
61
+ // Setup table view
62
+ m_ui.tableView ->setSelectionBehavior (QAbstractItemView::SelectionBehavior::SelectRows);
63
+ m_ui.tableView ->setEditTriggers (QAbstractItemView::NoEditTriggers);
64
+ m_ui.tableView ->verticalHeader ()->setVisible (true );
65
+ // Uncomment the next lines if you need to set specific resize modes for headers
66
+ // m_ui.tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
67
+ // m_ui.tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
68
+ // m_ui.tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
69
+ m_ui.tableView ->setContextMenuPolicy (Qt::CustomContextMenu);
70
+
71
+ // Connect line edit returnPressed signal to EnterPressDown slot
60
72
connect (m_ui.lineEdit , SIGNAL (returnPressed ()), this , SLOT (EnterPressDown ()));
61
73
62
- // Connect MiniThing github link button
74
+ // Connect push button clicked signal to ButtonSearchClicked slot
63
75
connect (m_ui.pushButton , SIGNAL (clicked ()), this , SLOT (ButtonSearchClicked ()));
64
76
65
- // Setup right key
66
- m_rightKeyMenu = new QMenu (m_ui.tableView );
67
- m_rightKeyActionOpen = new QAction ();
68
- m_rightKeyActionOpenPath = new QAction ();
69
-
70
- m_rightKeyActionOpen->setText (QString (" Open file (ctrl+o)" ));
71
- m_rightKeyActionOpenPath->setText (QString (" Open file path (ctrl+p)" ));
77
+ // Setup table and update view
78
+ UpdateTableView ();
79
+ }
72
80
81
+ oid MiniThingQt::setupActionsAndMenus ()
82
+ {
83
+ // Setup right-click menu
84
+ m_rightKeyMenu = new QMenu (m_ui.tableView );
85
+ m_rightKeyActionOpen = new QAction (tr (" Open file (ctrl+o)" ), this );
86
+ m_rightKeyActionOpenPath = new QAction (tr (" Open file path (ctrl+p)" ), this );
73
87
m_rightKeyMenu->addAction (m_rightKeyActionOpen);
74
88
m_rightKeyMenu->addAction (m_rightKeyActionOpenPath);
75
89
connect (m_ui.tableView , SIGNAL (customContextMenuRequested (QPoint)), this , SLOT (RightKeyMenu (QPoint)));
76
90
77
- // Registe all shortcut keys
78
- m_shortKeySearch = new QAction (this );
79
- m_shortKeySearch->setShortcut (tr (" ctrl+f" ));
80
- this ->addAction (m_shortKeySearch);
81
- connect (m_shortKeySearch, SIGNAL (triggered ()), this , SLOT (ShortKeySearch ()));
91
+ // Setup shortcut keys
92
+ m_shortKeySearch = new QAction (tr (" Search (ctrl+f)" ), this );
93
+ m_shortKeyOpen = new QAction (tr (" Open (ctrl+o)" ), this );
94
+ m_shortKeyOpenPath = new QAction (tr (" Open Path (ctrl+p)" ), this );
95
+ m_shortKeyDelete = new QAction (tr (" Delete (ctrl+d)" ), this );
96
+ m_shortKeyCopy = new QAction (tr (" Copy (ctrl+c)" ), this );
82
97
83
- m_shortKeyOpen = new QAction (this );
84
- m_shortKeyOpen->setShortcut (tr (" ctrl+o" ));
85
- this ->addAction (m_shortKeyOpen);
86
- connect (m_shortKeyOpen, SIGNAL (triggered ()), this , SLOT (ShortKeyOpen ()));
98
+ addAction (m_shortKeySearch);
99
+ addAction (m_shortKeyOpen);
100
+ addAction (m_shortKeyOpenPath);
101
+ addAction (m_shortKeyDelete);
102
+ addAction (m_shortKeyCopy);
87
103
88
- m_shortKeyOpenPath = new QAction (this );
89
- m_shortKeyOpenPath->setShortcut (tr (" ctrl+p" ));
90
- this ->addAction (m_shortKeyOpenPath);
104
+ connect (m_shortKeySearch, SIGNAL (triggered ()), this , SLOT (ShortKeySearch ()));
105
+ connect (m_shortKeyOpen, SIGNAL (triggered ()), this , SLOT (ShortKeyOpen ()));
91
106
connect (m_shortKeyOpenPath, SIGNAL (triggered ()), this , SLOT (ShortKeyOpenPath ()));
92
-
93
- m_shortKeyDelete = new QAction (this );
94
- m_shortKeyDelete->setShortcut (tr (" ctrl+d" ));
95
- this ->addAction (m_shortKeyDelete);
96
107
connect (m_shortKeyDelete, SIGNAL (triggered ()), this , SLOT (ShortKeyDelete ()));
97
-
98
- m_shortKeyCopy = new QAction (this );
99
- m_shortKeyCopy->setShortcut (tr (" ctrl+c" ));
100
- this ->addAction (m_shortKeyCopy);
101
108
connect (m_shortKeyCopy, SIGNAL (triggered ()), this , SLOT (ShortKeyCopy ()));
102
-
103
- // Setup table view
104
- m_ui.tableView ->setSelectionBehavior (QAbstractItemView::SelectionBehavior::SelectRows);
105
- m_ui.tableView ->setEditTriggers (QAbstractItemView::NoEditTriggers);
106
- m_ui.tableView ->verticalHeader ()->setVisible (true );
107
- // ui.tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
108
- // ui.tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
109
- // ui.tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
110
- m_ui.tableView ->setContextMenuPolicy (Qt::CustomContextMenu);
111
-
112
- UpdateTableView ();
113
109
}
114
110
115
111
MiniThingQt::~MiniThingQt ()
@@ -358,4 +354,4 @@ void MiniThingQt::RightKeyMenu(QPoint pos)
358
354
this ->SetStatusBar (tr (" File opened" ));
359
355
}
360
356
}
361
- }
357
+ }
0 commit comments