tahoma2d/toonz/sources/include/toonzqt/selection.h

82 lines
1.9 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TSELECTION_H
#define TSELECTION_H
#include "menubarcommand.h"
#include "tcommon.h"
#undef DVAPI
#undef DVVAR
#ifdef TOONZQT_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
class QMenu;
class QWidget;
//=============================================================================
// TSelection
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TSelection {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
class View {
public:
virtual ~View(){};
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual void onSelectionChanged() = 0;
virtual void enableCommands() {}
};
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TSelection();
virtual ~TSelection();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// override this to define selection related commands
virtual void enableCommands() {
if (m_view) m_view->enableCommands();
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// call selection handler enableCommand()
void enableCommand(CommandId cmdId, CommandHandlerInterface *handler);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// overridden enableCommands() will call enableCommand()
template <class T>
inline void enableCommand(T *target, CommandId cmdId, void (T::*method)()) {
enableCommand(cmdId, new CommandHandlerHelper<T>(target, method));
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
template <class T, typename R>
inline void enableCommand(T *target, CommandId cmdId, void (T::*method)(R),
R value) {
enableCommand(cmdId,
new CommandHandlerHelper2<T, R>(target, method, value));
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void makeCurrent();
void makeNotCurrent();
static TSelection *getCurrent();
static void setCurrent(TSelection *selection);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual bool isEmpty() const = 0;
virtual void selectNone() = 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual bool addMenuActions(QMenu *menu) { return false; }
void addMenuAction(QMenu *menu, CommandId cmdId);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setView(View *view) { m_view = view; }
View *getView() const { return m_view; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void notifyView();
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
View *m_view;
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
#endif // TSELECTION_H