Commit 8e2dcd46 authored by Julius Künzel's avatar Julius Künzel 💬
Browse files

[Guides] Add new MarkerCategoryChooser widget

We can use this similar to TimecodeDisplay in all the different places
where we want the user to select a marker/guides category.

This deduplicates code and leads to a more consistent user experience
parent ce0b48e6
......@@ -5,6 +5,7 @@ set(kdenlive_SRCS
widgets/doublewidget.cpp
widgets/dragvalue.cpp
widgets/geometrywidget.cpp
widgets/markercategorychooser.cpp
widgets/positionwidget.cpp
widgets/progressbutton.cpp
widgets/timecodedisplay.cpp
......@@ -32,12 +33,19 @@ if (BUILD_DESIGNERPLUGIN)
GROUP "Kdenlive Widgets"
)
ecm_qtdesignerplugin_widget(MarkerCategoryChooser
INCLUDE_FILE widgets/markercategorychooser.h
TOOLTIP "A QComboBox that can be used to select a marker category (Kdenlive)"
GROUP "Kdenlive Widgets"
)
ecm_add_qtdesignerplugin(kdenlivewidgets
NAME KdenliveWidgets
WIDGETS
TimecodeDisplay
ColorPickerWidget
ChooseColorWidget
MarkerCategoryChooser
LINK_LIBRARIES
kdenliveLib
INSTALL_DESTINATION "${KDE_INSTALL_QTPLUGINDIR}/designer"
......
#include "markercategorychooser.h"
#include "../bin/model/markerlistmodel.hpp"
#include <KLocalizedString>
MarkerCategoryChooser::MarkerCategoryChooser(QWidget *parent)
: QComboBox(parent)
, m_markerListModel(nullptr)
, m_allowAll(true)
, m_onlyUsed(false)
{
refresh();
connect(this, &MarkerCategoryChooser::changed, this, &MarkerCategoryChooser::refresh);
}
void MarkerCategoryChooser::refresh()
{
QList<CommentedTime> markers;
clear();
if (m_markerListModel) {
markers = m_markerListModel->getAllMarkers();
}
if (!m_markerListModel || (m_onlyUsed && markers.isEmpty())) {
setEnabled(false);
setPlaceholderText(i18n("Nothing to select"));
return;
}
setPlaceholderText(QString());
setEnabled(true);
if (m_allowAll) {
addItem(i18n("All Categories"), -1);
}
// Set up guide categories
static std::array<QColor, 9> markerTypes = m_markerListModel->markerTypes;
QPixmap pixmap(32, 32);
for (uint i = 0; i < markerTypes.size(); ++i) {
if (m_onlyUsed && m_markerListModel->getAllMarkers(i).isEmpty()) {
continue;
}
pixmap.fill(markerTypes[size_t(i)]);
QIcon colorIcon(pixmap);
addItem(colorIcon, i18n("Category %1", i), i);
}
}
void MarkerCategoryChooser::setCurrentCategory(int category)
{
setCurrentIndex(findData(category));
}
int MarkerCategoryChooser::currentCategory()
{
return currentData().toInt();
}
void MarkerCategoryChooser::setMarkerModel(const MarkerListModel *model)
{
m_markerListModel = model;
emit changed();
}
void MarkerCategoryChooser::setAllowAll(bool allowAll)
{
m_allowAll = allowAll;
emit changed();
}
void MarkerCategoryChooser::setOnlyUsed(bool onlyUsed)
{
m_onlyUsed = onlyUsed;
emit changed();
}
#ifndef MARKERCATEGORYCHOOSER_H
#define MARKERCATEGORYCHOOSER_H
#include <QComboBox>
#include <QWidget>
class MarkerListModel;
class MarkerCategoryChooser : public QComboBox
{
Q_OBJECT
Q_PROPERTY(bool allowAll READ allowAll WRITE setAllowAll NOTIFY changed)
Q_PROPERTY(bool onlyUsed READ onlyUsed WRITE setOnlyUsed NOTIFY changed)
public:
MarkerCategoryChooser(QWidget *parent = nullptr);
void setCurrentCategory(int category);
int currentCategory();
void setMarkerModel(const MarkerListModel *model);
void setAllowAll(bool allowAll);
void setOnlyUsed(bool onlyUsed);
private:
const MarkerListModel *m_markerListModel;
bool m_allowAll;
bool m_onlyUsed;
void refresh();
bool allowAll() { return m_allowAll; };
bool onlyUsed() { return m_onlyUsed; };
signals:
void changed();
};
#endif // MARKERCATEGORYCHOOSER_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment