Skip to content

Commit

Permalink
Added ability to remove windows from lists.
Browse files Browse the repository at this point in the history
- Button for removing selected windows from the active/inactive lists has been added.
- Shortcut for doing the same has also been added, using the DEL key.
- Removed Q_UNUSED from nativeEvent, as the variables that were marked unused were actually being used in the call to QMainWindow::nativeEvent.
- Made destructor of ListWidgetWindowItem call ApplyOriginalState(), so that when ListWidgetWindowItem's are deleted from the active/inactive lists by the aforementioned shortcut and buttons, the original window state will be restored.
- Updated the way in which invalid windows are periodically deleted from the active/inactive lists, ensuring that QListWidget::takeItem is called first before the item instance is deleted, as recommended by Qt.
- Added new function: selectedWindows_Delete() which the aforementioned button and shortcut call to delete selected windows.
- Re-ordered includes in main_window_dialog.hxx, aesthetic change only.
- Changed default window height of MainWindow from 491 to 482.
  • Loading branch information
PsychedelicShayna committed Mar 26, 2022
1 parent 0110bd4 commit d916fab
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 27 deletions.
4 changes: 4 additions & 0 deletions source/list_widget_window_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,7 @@ ListWidgetWindowItem::ListWidgetWindowItem(const HWND& window_handle)
{

}

ListWidgetWindowItem::~ListWidgetWindowItem() {
ApplyOriginalState();
}
1 change: 1 addition & 0 deletions source/list_widget_window_item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class ListWidgetWindowItem : public QListWidgetItem {
void ResetModifications();

ListWidgetWindowItem(const HWND& window_handle);
virtual ~ListWidgetWindowItem() override;
};

#endif // ListWidgetWindowItem_HXX
35 changes: 30 additions & 5 deletions source/main_window_dialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#include "ui_main_window_dialog.h"

bool MainWindow::nativeEvent(const QByteArray& event_type, void* message, qintptr* result) {
Q_UNUSED(event_type)
Q_UNUSED(result)

MSG* msg { reinterpret_cast<MSG*>(message) };

if (msg->message == WM_HOTKEY) {
Expand All @@ -22,15 +19,15 @@ void MainWindow::removeInvalidWindowsFromLists() {
ListWidgetWindowItem* list_widget_window_item { dynamic_cast<ListWidgetWindowItem*>(ui->listWidgetActiveWindows->item(i)) };

if(!list_widget_window_item->IsValidWindow()) {
delete list_widget_window_item;
delete ui->listWidgetActiveWindows->takeItem(ui->listWidgetActiveWindows->row(list_widget_window_item));
}
}

for(qint32 i { 0 }; i < ui->listWidgetInactiveWindows->count(); ++i) {
ListWidgetWindowItem* list_widget_window_item { dynamic_cast<ListWidgetWindowItem*>(ui->listWidgetInactiveWindows->item(i)) };

if(!list_widget_window_item->IsValidWindow()) {
delete list_widget_window_item;
delete ui->listWidgetInactiveWindows->takeItem(ui->listWidgetInactiveWindows->row(list_widget_window_item));
}
}
}
Expand Down Expand Up @@ -95,6 +92,16 @@ void MainWindow::spawnProcessScannerDialog() {
}
}

void MainWindow::selectedWindows_Delete() {
for(QListWidgetItem* list_widget_item : ui->listWidgetInactiveWindows->selectedItems()) {
delete ui->listWidgetInactiveWindows->takeItem(ui->listWidgetInactiveWindows->row(list_widget_item));
}

for(QListWidgetItem* list_widget_item : ui->listWidgetActiveWindows->selectedItems()) {
delete ui->listWidgetActiveWindows->takeItem(ui->listWidgetActiveWindows->row(list_widget_item));
}
}

void MainWindow::startWindowGrabber() {
if(timerWindowGrabber->isActive()) {
windowGrabAttemptCounter = 30;
Expand Down Expand Up @@ -327,6 +334,24 @@ MainWindow::MainWindow(QWidget* parent)

timerRemoveInvalidWindows->start(1000);

QShortcut* inactive_list_widget_del_shortcut { new QShortcut { Qt::Key_Delete, ui->listWidgetInactiveWindows } };
QShortcut* active_list_widget_del_shortcut { new QShortcut { Qt::Key_Delete, ui->listWidgetActiveWindows } };

connect(inactive_list_widget_del_shortcut, SIGNAL(activated()),
this, SLOT(selectedWindows_Delete()));

connect(active_list_widget_del_shortcut, SIGNAL(activated()),
this, SLOT(selectedWindows_Delete()));

connect(inactive_list_widget_del_shortcut, SIGNAL(activatedAmbiguously()),
this, SLOT(selectedWindows_Delete()));

connect(active_list_widget_del_shortcut, SIGNAL(activatedAmbiguously()),
this, SLOT(selectedWindows_Delete()));

connect(ui->pushButtonDeleteSelectedWindows, SIGNAL(clicked()),
this, SLOT(selectedWindows_Delete()));

connect(timerRemoveInvalidWindows, SIGNAL(timeout()),
this, SLOT(removeInvalidWindowsFromLists()));

Expand Down
12 changes: 8 additions & 4 deletions source/main_window_dialog.hxx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#ifndef MAINWINDOW_HXX
#define MAINWINDOW_HXX

#include <QtWidgets/QMainWindow>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QCheckBox>

#include <QtCore/QResource>
#include <QtCore/QFileInfo>
#include <QtCore/QFile>

#include <QtGui/QShortcut>

#include <QtWidgets/QMainWindow>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QCheckBox>

#ifndef WIN32_MEAN_AND_LEAN
#define WIN32_MEAN_AND_LEAN
#endif
Expand Down Expand Up @@ -61,6 +63,8 @@ protected:
quint32 windowGrabAttemptCounter;
Q_SLOT void startWindowGrabber();

Q_SLOT void selectedWindows_Delete();

Q_SLOT void selectedInactiveWindows_Activate();
Q_SLOT void selectedActiveWindows_Deactivate();

Expand Down
47 changes: 29 additions & 18 deletions source/main_window_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>457</width>
<height>491</height>
<height>482</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -212,23 +212,34 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonResetSelectedWindows">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Reset Selected Windows</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayoutListManagementButtons" stretch="1,1">
<item>
<widget class="QPushButton" name="pushButtonResetSelectedWindows">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Reset Selected Windows</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonDeleteSelectedWindows">
<property name="text">
<string>Delete Selected Windows</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down

0 comments on commit d916fab

Please sign in to comment.