refactor: move msg_box out of engine qtutils into the dialog layer

The engine-side QtUtils no longer references QMessageBox; the two
dialog call sites use the identical olive::msg_box() inline helper.
This commit is contained in:
2026-07-20 01:01:18 +08:00
parent 03d4087124
commit 69cd8d3a75
5 changed files with 71 additions and 36 deletions
-22
View File
@@ -50,28 +50,6 @@ QFrame *QtUtils::create_vertical_line()
return l; return l;
} }
int QtUtils::msg_box(QWidget *parent, QMessageBox::Icon icon,
const QString &title, const QString &message,
QMessageBox::StandardButtons buttons)
{
QMessageBox b(parent);
b.setIcon(icon);
b.setWindowModality(Qt::WindowModal);
b.setWindowTitle(title);
b.setText(message);
uint mask = QMessageBox::FirstButton;
while (mask <= QMessageBox::LastButton) {
uint sb = buttons & mask;
if (sb) {
b.addButton(static_cast<QMessageBox::StandardButton>(sb));
}
mask <<= 1;
}
return b.exec();
}
QDateTime QtUtils::get_creation_date(const QFileInfo &info) QDateTime QtUtils::get_creation_date(const QFileInfo &info)
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
-5
View File
@@ -28,7 +28,6 @@
#include <QFileInfo> #include <QFileInfo>
#include <QFontMetrics> #include <QFontMetrics>
#include <QFrame> #include <QFrame>
#include <QMessageBox>
namespace olive namespace olive
{ {
@@ -48,10 +47,6 @@ public:
static QFrame *create_vertical_line(); static QFrame *create_vertical_line();
static int msg_box(QWidget *parent, QMessageBox::Icon icon,
const QString &title, const QString &message,
QMessageBox::StandardButtons buttons = QMessageBox::Ok);
static QDateTime get_creation_date(const QFileInfo &info); static QDateTime get_creation_date(const QFileInfo &info);
static QString get_formatted_date_time(const QDateTime &dt); static QString get_formatted_date_time(const QDateTime &dt);
+8 -7
View File
@@ -33,6 +33,7 @@
#include "common/digit.h" #include "common/digit.h"
#include "common/qtutils.h" #include "common/qtutils.h"
#include "dialog/msgbox.h"
#include "dialog/task/task.h" #include "dialog/task/task.h"
#include "exportsavepresetdialog.h" #include "exportsavepresetdialog.h"
#include "node/project.h" #include "node/project.h"
@@ -308,7 +309,7 @@ void ExportDialog::start_export()
{ {
if (!video_enabled_->isChecked() && !audio_enabled_->isChecked() && if (!video_enabled_->isChecked() && !audio_enabled_->isChecked() &&
!subtitles_enabled_->isChecked()) { !subtitles_enabled_->isChecked()) {
QtUtils::msg_box( msg_box(
this, QMessageBox::Critical, tr("Invalid parameters"), this, QMessageBox::Critical, tr("Invalid parameters"),
tr("Video, audio, and subtitles are disabled. There's nothing to export.")); tr("Video, audio, and subtitles are disabled. There's nothing to export."));
return; return;
@@ -322,7 +323,7 @@ void ExportDialog::start_export()
// If it doesn't, see if the user wants to append it automatically. If not, we don't abort the export. // If it doesn't, see if the user wants to append it automatically. If not, we don't abort the export.
if (!proposed_filename.endsWith(necessary_ext, Qt::CaseInsensitive)) { if (!proposed_filename.endsWith(necessary_ext, Qt::CaseInsensitive)) {
if (QtUtils::msg_box( if (msg_box(
this, QMessageBox::Warning, tr("Invalid filename"), this, QMessageBox::Warning, tr("Invalid filename"),
tr("The filename must contain the extension \"%1\". Would you like to append it " tr("The filename must contain the extension \"%1\". Would you like to append it "
"automatically?") "automatically?")
@@ -341,7 +342,7 @@ void ExportDialog::start_export()
// If the directory does not exist, try to create it // If the directory does not exist, try to create it
QDir dest_dir(file_info.path()); QDir dest_dir(file_info.path());
if (!FileFunctions::directory_is_valid(dest_dir)) { if (!FileFunctions::directory_is_valid(dest_dir)) {
QtUtils::msg_box( msg_box(
this, QMessageBox::Critical, this, QMessageBox::Critical,
tr("Failed to create output directory"), tr("Failed to create output directory"),
tr("The intended output directory doesn't exist and Oak Video Editor couldn't create it. " tr("The intended output directory doesn't exist and Oak Video Editor couldn't create it. "
@@ -353,7 +354,7 @@ void ExportDialog::start_export()
if (video_tab_->is_image_sequence_set()) { if (video_tab_->is_image_sequence_set()) {
// Ensure filename contains digits // Ensure filename contains digits
if (!Encoder::filename_contains_digit_placeholder(proposed_filename)) { if (!Encoder::filename_contains_digit_placeholder(proposed_filename)) {
QtUtils::msg_box( msg_box(
this, QMessageBox::Critical, tr("Invalid filename"), this, QMessageBox::Critical, tr("Invalid filename"),
tr("Export is set to an image sequence, but the filename does not have a section for digits " tr("Export is set to an image sequence, but the filename does not have a section for digits "
"(formatted as [#####] where the amount of # is the amount of digits).")); "(formatted as [#####] where the amount of # is the amount of digits)."));
@@ -365,7 +366,7 @@ void ExportDialog::start_export()
int current_digit_count = int current_digit_count =
Encoder::get_image_sequence_placeholder_digit_count(proposed_filename); Encoder::get_image_sequence_placeholder_digit_count(proposed_filename);
if (current_digit_count < needed_digit_count) { if (current_digit_count < needed_digit_count) {
QtUtils::msg_box( msg_box(
this, QMessageBox::Critical, tr("Invalid filename"), this, QMessageBox::Critical, tr("Invalid filename"),
tr("Filename doesn't contain enough digits for the amount of frames " tr("Filename doesn't contain enough digits for the amount of frames "
"this export will need (need %1 for %n frame(s)).", "this export will need (need %1 for %n frame(s)).",
@@ -377,7 +378,7 @@ void ExportDialog::start_export()
// Validate if the file exists and whether the user wishes to overwrite it // Validate if the file exists and whether the user wishes to overwrite it
if (file_info.exists()) { if (file_info.exists()) {
if (QtUtils::msg_box( if (msg_box(
this, QMessageBox::Warning, tr("Confirm Overwrite"), this, QMessageBox::Warning, tr("Confirm Overwrite"),
tr("The file \"%1\" already exists. Do you want to overwrite it?") tr("The file \"%1\" already exists. Do you want to overwrite it?")
.arg(proposed_filename), .arg(proposed_filename),
@@ -392,7 +393,7 @@ void ExportDialog::start_export()
video_tab_->get_selected_codec() == ExportCodec::k_codec_h265) && video_tab_->get_selected_codec() == ExportCodec::k_codec_h265) &&
(video_tab_->width_slider()->get_value() % 2 != 0 || (video_tab_->width_slider()->get_value() % 2 != 0 ||
video_tab_->height_slider()->get_value() % 2 != 0)) { video_tab_->height_slider()->get_value() % 2 != 0)) {
QtUtils::msg_box(this, QMessageBox::Critical, tr("Invalid Parameters"), msg_box(this, QMessageBox::Critical, tr("Invalid Parameters"),
tr("Width and height must be multiples of 2.")); tr("Width and height must be multiples of 2."));
return; return;
} }
+60
View File
@@ -0,0 +1,60 @@
/***
Oak - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_MSGBOX_H
#define OAK_MSGBOX_H
#include <QMessageBox>
#include <QWidget>
namespace olive
{
/**
* @brief Shows a simple window-modal message box
*
* Lives in the UI layer: the engine (common/qtutils) must not reference
* QMessageBox. Previously QtUtils::msg_box.
*/
inline int msg_box(QWidget *parent, QMessageBox::Icon icon,
const QString &title, const QString &message,
QMessageBox::StandardButtons buttons = QMessageBox::Ok)
{
QMessageBox b(parent);
b.setIcon(icon);
b.setWindowModality(Qt::WindowModal);
b.setWindowTitle(title);
b.setText(message);
uint mask = QMessageBox::FirstButton;
while (mask <= QMessageBox::LastButton) {
uint sb = buttons & mask;
if (sb) {
b.addButton(static_cast<QMessageBox::StandardButton>(sb));
}
mask <<= 1;
}
return b.exec();
}
}
#endif // OAK_MSGBOX_H
+3 -2
View File
@@ -33,6 +33,7 @@
#include "config/config.h" #include "config/config.h"
#include "core.h" #include "core.h"
#include "common/qtutils.h" #include "common/qtutils.h"
#include "dialog/msgbox.h"
#include "undo/undostack.h" #include "undo/undostack.h"
namespace olive namespace olive
@@ -107,7 +108,7 @@ void SequenceDialog::set_name_is_editable(bool e)
void SequenceDialog::accept() void SequenceDialog::accept()
{ {
if (name_field_->isEnabled() && name_field_->text().isEmpty()) { if (name_field_->isEnabled() && name_field_->text().isEmpty()) {
QtUtils::msg_box(this, QMessageBox::Critical, msg_box(this, QMessageBox::Critical,
tr("Error editing Sequence"), tr("Error editing Sequence"),
tr("Please enter a name for this Sequence.")); tr("Please enter a name for this Sequence."));
return; return;
@@ -178,7 +179,7 @@ void SequenceDialog::accept()
void SequenceDialog::set_as_default_clicked() void SequenceDialog::set_as_default_clicked()
{ {
if (QtUtils::msg_box( if (msg_box(
this, QMessageBox::Question, tr("Confirm Set As Default"), this, QMessageBox::Question, tr("Confirm Set As Default"),
tr("Are you sure you want to set the current parameters as defaults?"), tr("Are you sure you want to set the current parameters as defaults?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {