diff --git a/src/colortools.cpp b/src/colortools.cpp --- a/src/colortools.cpp +++ b/src/colortools.cpp @@ -18,6 +18,15 @@ #include "kdenlive_debug.h" #endif +namespace { + double preventOverflow(double value) + { + return value < 0 ? 0 + : value > 255 ? 255 + : value; + } +} + ColorTools::ColorTools(QObject *parent) : QObject(parent) { @@ -34,7 +43,7 @@ wheel.fill(qRgba(0, 0, 0, 0)); } - double dr, dg, db, dv, dmax; + double dr, dg, db, dv; double ru, rv, rr; const int w = size.width(); const int h = size.height(); @@ -69,14 +78,7 @@ if (modifiedVersion) { // Scale the RGB values down, or up, to max 255 - dmax = fabs(dr); - if (fabs(dg) > dmax) { - dmax = fabs(dg); - } - if (fabs(db) > dmax) { - dmax = fabs(db); - } - dmax = 255 / dmax; + const double dmax = 255 / std::max({fabs(dr), fabs(dg), fabs(db)}); dr *= dmax; dg *= dmax; @@ -87,24 +89,9 @@ // Note that not all possible (y,u,v) values with u,v \in [-1,1] // have a correct RGB representation, therefore some RGB values // may exceed {0,...,255}. - if (dr < 0) { - dr = 0; - } - if (dg < 0) { - dg = 0; - } - if (db < 0) { - db = 0; - } - if (dr > 255) { - dr = 255; - } - if (dg > 255) { - dg = 255; - } - if (db > 255) { - db = 255; - } + dr = preventOverflow(dr); + dg = preventOverflow(dg); + db = preventOverflow(db); wheel.setPixel(u, (h - v - 1), qRgba(dr, dg, db, 255)); } @@ -136,27 +123,9 @@ Y = (double)255 * y / h; // See yuv2rgb, yuvColorWheel - dr = Y + 290.8 * dv; - dg = Y - 100.6 * du - 148 * dv; - db = Y + 517.2 * du; - if (dr < 0) { - dr = 0; - } - if (dg < 0) { - dg = 0; - } - if (db < 0) { - db = 0; - } - if (dr > 255) { - dr = 255; - } - if (dg > 255) { - dg = 255; - } - if (db > 255) { - db = 255; - } + dr = preventOverflow(Y + 290.8 * dv); + dg = preventOverflow(Y - 100.6 * du - 148 * dv); + db = preventOverflow(Y + 517.2 * du); plane.setPixel(uv, (h - y - 1), qRgba(dr, dg, db, 255)); } @@ -287,32 +256,9 @@ } // Calculate the RGB values from YPbPr - dr = Y + 357.5 * dpR; - dg = Y - 87.75 * dpB - 182.1 * dpR; - db = Y + 451.86 * dpB; - - // Avoid overflows (which would generate intersecting patterns). - // Note that not all possible (y,u,v) values with u,v \in [-1,1] - // have a correct RGB representation, therefore some RGB values - // may exceed {0,...,255}. - if (dr < 0) { - dr = 0; - } - if (dg < 0) { - dg = 0; - } - if (db < 0) { - db = 0; - } - if (dr > 255) { - dr = 255; - } - if (dg > 255) { - dg = 255; - } - if (db > 255) { - db = 255; - } + dr = preventOverflow(Y + 357.5 * dpR); + dg = preventOverflow(Y - 87.75 * dpB - 182.1 * dpR); + db = preventOverflow(Y + 451.86 * dpB); wheel.setPixel(b, (h - r - 1), qRgba(dr, dg, db, 255)); } diff --git a/src/hidetitlebars.cpp b/src/hidetitlebars.cpp --- a/src/hidetitlebars.cpp +++ b/src/hidetitlebars.cpp @@ -42,46 +42,42 @@ for (int i = 0; i < docks.count(); ++i) { QDockWidget *dock = docks.at(i); QWidget *bar = dock->titleBarWidget(); - if (show) { - if (dock->isFloating()) { - if (bar) { - dock->setTitleBarWidget(nullptr); - delete bar; - } - continue; - } - // Since Qt 5.6 we only display title bar in non tabbed dockwidgets - QList docked = pCore->window()->tabifiedDockWidgets(dock); - if (docked.isEmpty()) { - if (bar) { - dock->setTitleBarWidget(nullptr); - delete bar; - } - continue; - } else { - bool hasVisibleDockSibling = false; - for (QDockWidget *sub : docked) { - if (sub->toggleViewAction()->isChecked()) { - // we have another docked widget, so tabs are visible and can be used instead of title bars - hasVisibleDockSibling = true; - break; - } - } - if (!hasVisibleDockSibling) { - if (bar) { - dock->setTitleBarWidget(nullptr); - delete bar; - } - continue; - } - } - if (!bar) { - dock->setTitleBarWidget(new QWidget); + + auto handleRemoveBar = [&dock, &bar]() -> void { + if (bar) { + dock->setTitleBarWidget(nullptr); + delete bar; } - } else { + }; + + if (!show) { if (!dock->isFloating() && (bar == nullptr)) { - dock->setTitleBarWidget(new QWidget); + dock->setTitleBarWidget(new QWidget()); } + continue; + } + + if (dock->isFloating()) { + handleRemoveBar(); + continue; + } + // Since Qt 5.6 we only display title bar in non tabbed dockwidgets + QList docked = pCore->window()->tabifiedDockWidgets(dock); + if (docked.isEmpty()) { + handleRemoveBar(); + continue; + } + + const bool hasVisibleDockSibling = std::find_if(std::begin(docked), std::end(docked), + [](QDockWidget *sub) { return sub->toggleViewAction()->isChecked(); }) != std::end(docked);; + + if (!hasVisibleDockSibling) { + handleRemoveBar(); + continue; + } + + if (!bar) { + dock->setTitleBarWidget(new QWidget()); } } KdenliveSettings::setShowtitlebars(show); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -170,8 +170,8 @@ QStringList availableStyles = QStyleFactory::keys(); if (KdenliveSettings::widgetstyle().isEmpty()) { // First run - QStringList incompatibleStyles; - incompatibleStyles << QStringLiteral("GTK+") << QStringLiteral("windowsvista") << QStringLiteral("windowsxp"); + QStringList incompatibleStyles = {QStringLiteral("GTK+"), QStringLiteral("windowsvista"), QStringLiteral("windowsxp")}; + if (incompatibleStyles.contains(desktopStyle, Qt::CaseInsensitive)) { if (availableStyles.contains(QStringLiteral("breeze"), Qt::CaseInsensitive)) { // Auto switch to Breeze theme @@ -432,8 +432,7 @@ setupGUI(KXmlGuiWindow::ToolBar | KXmlGuiWindow::StatusBar | KXmlGuiWindow::Save | KXmlGuiWindow::Create); if (firstRun) { - QScreen *current = QApplication::primaryScreen(); - if (current) { + if (QScreen *current = QApplication::primaryScreen()) { if (current->availableSize().height() < 1000) { resize(current->availableSize()); } else { @@ -1488,15 +1487,17 @@ addAction(QStringLiteral("add_project_note"), i18n("Add Project Note"), pCore->projectManager(), SLOT(slotAddProjectNote()), QIcon::fromTheme(QStringLiteral("bookmark"))); - QHash actions; - actions.insert(QStringLiteral("locate"), locateClip); - actions.insert(QStringLiteral("reload"), reloadClip); - actions.insert(QStringLiteral("duplicate"), duplicateClip); - actions.insert(QStringLiteral("proxy"), proxyClip); - actions.insert(QStringLiteral("properties"), clipProperties); - actions.insert(QStringLiteral("open"), openClip); - actions.insert(QStringLiteral("delete"), deleteClip); - actions.insert(QStringLiteral("folder"), addFolder); + QHash actions({ + { QStringLiteral("locate"), locateClip }, + { QStringLiteral("reload"), reloadClip }, + { QStringLiteral("duplicate"), duplicateClip }, + { QStringLiteral("proxy"), proxyClip }, + { QStringLiteral("properties"), clipProperties }, + { QStringLiteral("open"), openClip }, + { QStringLiteral("delete"), deleteClip }, + { QStringLiteral("folder"), addFolder } + }); + pCore->bin()->setupMenu(addClips, addClip, actions); // Setup effects and transitions actions.