Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TSELECTION_H
Toshihiro Shimizu 890ddd
#define TSELECTION_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "menubarcommand.h"
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TOONZQT_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class QMenu;
Toshihiro Shimizu 890ddd
class QWidget;
Toshihiro Shimizu 890ddd
shun-iwasawa afe084
#include <qmap></qmap>
shun-iwasawa afe084
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TSelection
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TSelection {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  class View {
Shinya Kitaoka 120a6e
  public:
Shinya Kitaoka 120a6e
    virtual ~View(){};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    virtual void onSelectionChanged() = 0;
Shinya Kitaoka 120a6e
    virtual void enableCommands() {}
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TSelection();
Shinya Kitaoka 120a6e
  virtual ~TSelection();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // override this to define selection related commands
Shinya Kitaoka 120a6e
  virtual void enableCommands() {
Shinya Kitaoka 120a6e
    if (m_view) m_view->enableCommands();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // call selection handler enableCommand()
Shinya Kitaoka 120a6e
  void enableCommand(CommandId cmdId, CommandHandlerInterface *handler);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // overridden enableCommands() will call enableCommand()
Shinya Kitaoka 120a6e
  template <class t=""></class>
Shinya Kitaoka 120a6e
  inline void enableCommand(T *target, CommandId cmdId, void (T::*method)()) {
Shinya Kitaoka 120a6e
    enableCommand(cmdId, new CommandHandlerHelper<t>(target, method));</t>
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  template <class r="" t,="" typename=""></class>
Shinya Kitaoka 120a6e
  inline void enableCommand(T *target, CommandId cmdId, void (T::*method)(R),
Shinya Kitaoka 120a6e
                            R value) {
Shinya Kitaoka 120a6e
    enableCommand(cmdId,
Shinya Kitaoka 120a6e
                  new CommandHandlerHelper2<t, r="">(target, method, value));</t,>
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void makeCurrent();
Shinya Kitaoka 120a6e
  void makeNotCurrent();
Shinya Kitaoka 120a6e
  static TSelection *getCurrent();
Shinya Kitaoka 120a6e
  static void setCurrent(TSelection *selection);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual bool isEmpty() const = 0;
Shinya Kitaoka 120a6e
  virtual void selectNone()    = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual bool addMenuActions(QMenu *menu) { return false; }
Shinya Kitaoka 120a6e
  void addMenuAction(QMenu *menu, CommandId cmdId);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setView(View *view) { m_view = view; }
Shinya Kitaoka 120a6e
  View *getView() const { return m_view; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void notifyView();
Toshihiro Shimizu 890ddd
shun-iwasawa afe084
  // specify alternative command name when the selection is current.
shun-iwasawa afe084
  // the commands must be "Edit" category.
shun-iwasawa afe084
  const QMap<commandid, qstring=""> &alternativeCommandNames() {</commandid,>
shun-iwasawa afe084
    return m_alternativeCommandNames;
shun-iwasawa afe084
  }
shun-iwasawa afe084
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  View *m_view;
shun-iwasawa afe084
shun-iwasawa afe084
protected:
shun-iwasawa afe084
  QMap<commandid, qstring=""> m_alternativeCommandNames;</commandid,>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // TSELECTION_H