Permalink
Browse files

QActions introducetd to ModeWidget buttons. Shortcuts introduced to B…

…andView modes. Icons enabled in Menus. ResizeEvent behaviour changed
  • Loading branch information...
ajaskier committed Aug 19, 2015
1 parent c9dc3d8 commit 8b78afcbfac41bd0fa7c93decb911735ccdb63a1
View
@@ -17,4 +17,8 @@ arrows - navigating through spectral plot
----BANDVIEW----
'1' - zooming/panning mode
'2' - label mode
'3' - pick mode
'x' - rubber/marker toggle in label mode
'c' - clear seeds / clear label
View
@@ -86,8 +86,6 @@ void BandDock::initUi()
bv->offTop = AutohideWidget::OutOffset;
view->addWidget(AutohideWidget::TOP, mw);
connect(mw, SIGNAL(inputModeChanged(ScaledView::InputMode)),
bv, SLOT(updateInputMode(ScaledView::InputMode)));
connect(bv, SIGNAL(inputModeChanged(ScaledView::InputMode)),
mw, SLOT(updateInputMode(ScaledView::InputMode)));
connect(mw, SIGNAL(cursorSizeChanged(BandView::CursorSize)),
@@ -104,7 +102,58 @@ void BandDock::initUi()
connect(screenshotButton, SIGNAL(released()),
this, SLOT(screenshot()));
initActions();
bv->initUi();
mw->initUi();
}
void BandDock::initActions()
{
QActionGroup *actionGroup = new QActionGroup(this);
actionGroup->setExclusive(true);
zoomAction = new QAction(this);
zoomAction->setText("Zoom");
zoomAction->setShortcut(Qt::Key_1);
zoomAction->setData((int)ScaledView::InputMode::Zoom);
zoomAction->setCheckable(true);
zoomAction->setChecked(true);
zoomAction->setIcon(QIcon(":/basic/zoom"));
zoomAction->setIconVisibleInMenu(true);
actionGroup->addAction(zoomAction);
bv->setZoomAction(zoomAction);
mw->setZoomAction(zoomAction);
this->addAction(zoomAction);
connect(zoomAction, SIGNAL(triggered()),
bv, SLOT(updateInputMode()));
labelAction = new QAction(this);
labelAction->setText("Label");
labelAction->setShortcut(Qt::Key_2);
labelAction->setData((int)ScaledView::InputMode::Label);
labelAction->setCheckable(true);
labelAction->setIcon((QIcon(":/basic/pencil")));
labelAction->setIconVisibleInMenu(true);
actionGroup->addAction(labelAction);
bv->setLabelAction(labelAction);
mw->setLabelAction(labelAction);
this->addAction(labelAction);
connect(labelAction, SIGNAL(triggered()),
bv, SLOT(updateInputMode()));
pickAction = new QAction(this);
pickAction->setText("Pick");
pickAction->setShortcut(Qt::Key_3);
pickAction->setData((int)ScaledView::InputMode::Pick);
pickAction->setCheckable(true);
pickAction->setIcon((QIcon(":/basic/picker")));
pickAction->setIconVisibleInMenu(true);
actionGroup->addAction(pickAction);
bv->setPickAction(pickAction);
mw->setPickAction(pickAction);
this->addAction(pickAction);
connect(pickAction, SIGNAL(triggered()),
bv, SLOT(updateInputMode()));
}
void BandDock::changeBand(representation::t repr, int bandId,
View
@@ -9,6 +9,7 @@
class BandView;
class GraphSegWidget;
class ModeWidget;
class QAction;
class BandDock : public QDockWidget, private Ui::BandDock
{
@@ -76,6 +77,7 @@ protected slots:
bool eventFilter(QObject *obj, QEvent *event);
void initUi();
void initActions();
// local copies
QVector<QColor> labelColors;
@@ -85,6 +87,10 @@ protected slots:
representation::t curRepr;
int curBandId;
QAction* zoomAction = nullptr;
QAction* labelAction = nullptr;
QAction* pickAction = nullptr;
// our band view
BandView *bv;
// our widget for graph segmentation controls
@@ -21,4 +21,5 @@ void ActionButton::updateButtonStatusFromAction()
setCheckable(actionOwner->isCheckable());
setChecked(actionOwner->isChecked());
setEnabled(actionOwner->isEnabled());
setIcon(actionOwner->icon());
}
View
@@ -47,9 +47,10 @@ void BandView::initUi()
this, SLOT(commitLabelChanges()));
}
void BandView::updateInputMode(ScaledView::InputMode mode)
void BandView::updateInputMode()
{
inputMode = mode;
QAction* sender = (QAction*) QObject::sender();
inputMode = (InputMode) sender->data().toInt();
}
void BandView::toggleCursorMode()
@@ -63,12 +64,6 @@ void BandView::updateCursorSize(CursorSize size)
cursorSize = size;
}
void BandView::resizeEvent()
{
ScaledView::resizeEvent();
zoom = 1;
}
void BandView::setPixmap(QPixmap p)
{
ScaledView::setPixmap(p);
@@ -679,44 +674,9 @@ QMenu *BandView::createContextMenu()
QMenu* contextMenu = ScaledView::createContextMenu();
contextMenu->addSeparator();
QActionGroup *actionGroup = new QActionGroup(this);
actionGroup->setExclusive(true);
QAction* tmp;
tmp = contextMenu->addAction("Zoom");
tmp->setData((int)InputMode::Zoom);
tmp->setCheckable(true);
tmp->setChecked(true);
actionGroup->addAction(tmp);
tmp = contextMenu->addAction("Label");
tmp->setData((int)InputMode::Label);
tmp->setCheckable(true);
actionGroup->addAction(tmp);
tmp = contextMenu->addAction("Pick");
tmp->setData((int)InputMode::Pick);
tmp->setCheckable(true);
actionGroup->addAction(tmp);
contextMenu->addAction(zoomAction);
contextMenu->addAction(labelAction);
contextMenu->addAction(pickAction);
return contextMenu;
}
void BandView::showContextMenu(QPoint screenpoint)
{
if (!contextMenu) contextMenu = createContextMenu();
QAction* a = contextMenu->exec(screenpoint);
if (!a)
return;
int choice = a->data().toInt();
InputMode mode = (InputMode)choice;
if (mode == InputMode::Zoom || mode == InputMode::Label
|| mode == InputMode::Pick)
{
emit inputModeChanged(mode);
updateInputMode(mode);
}
}
View
@@ -51,6 +51,10 @@ class BandView : public ScaledView
cv::Mat1s getSeedMap() { return seedMap; }
void setSeedMap(cv::Mat1s seeding);
void setZoomAction(QAction* act) { zoomAction = act; }
void setLabelAction(QAction* act) { labelAction = act; }
void setPickAction(QAction* act) { pickAction = act; }
public slots:
void refresh();
void commitLabels();
@@ -72,7 +76,7 @@ public slots:
void enterEvent();
void leaveEvent();
void updateInputMode(ScaledView::InputMode mode);
void updateInputMode();
void updateCursorSize(BandView::CursorSize size);
void toggleCursorMode();
@@ -105,10 +109,7 @@ public slots:
protected:
void paintEvent(QPainter *painter, const QRectF &rect);
void keyPressEvent(QKeyEvent *);
virtual void resizeEvent();
QMenu* createContextMenu();
void showContextMenu(QPoint screenpoint);
private:
void cursorAction(QGraphicsSceneMouseEvent *ev, bool click = false);
@@ -166,6 +167,10 @@ public slots:
// point sets, stored as polygon for translate(), and hulls for drawing
std::unordered_map<CursorSize, std::pair<QPolygonF, QPolygonF>,
std::hash<int>> cursors;
QAction* zoomAction = nullptr;
QAction* labelAction = nullptr;
QAction* pickAction = nullptr;
};
#endif // BANDVIEW_H
@@ -10,7 +10,6 @@ ModeWidget::ModeWidget(AutohideView *view) :
AutohideWidget()
{
setupUi(this);
initUi();
}
ModeWidget::~ModeWidget()
@@ -32,6 +31,10 @@ void ModeWidget::initUi()
cursorGroup->addButton(bigCurButton);
cursorGroup->addButton(hugeCurButton);
setCursorButtonsVisible(false);
zoomButton->setAction(zoomAction);
labelButton->setAction(labelAction);
pickButton->setAction(pickAction);
}
void ModeWidget::updateInputMode(ScaledView::InputMode m)
@@ -83,21 +86,18 @@ void ModeWidget::updateCursorMode(BandView::CursorMode m)
void ModeWidget::on_zoomButton_released()
{
emit inputModeChanged(IM::Zoom);
setCursorButtonsVisible(false);
adjustSize();
}
void ModeWidget::on_pickButton_released()
{
emit inputModeChanged(IM::Pick);
setCursorButtonsVisible(false);
adjustSize();
}
void ModeWidget::on_labelButton_released()
{
emit inputModeChanged(IM::Label);
setCursorButtonsVisible(true);
adjustSize();
}
View
@@ -17,18 +17,20 @@ class ModeWidget : public AutohideWidget, private Ui::ModeWidget
explicit ModeWidget(AutohideView* view);
~ModeWidget();
protected:
void initUi();
signals:
void inputModeChanged(ScaledView::InputMode m);
void cursorSizeChanged(BandView::CursorSize s);
public slots:
void updateInputMode(ScaledView::InputMode m);
void updateCursorMode(BandView::CursorMode m);
void updateCursorSize(BandView::CursorSize s);
void setZoomAction(QAction* act) { zoomAction = act; }
void setLabelAction(QAction* act) { labelAction = act; }
void setPickAction(QAction* act) { pickAction = act; }
ActionButton* getRubberButton() { return rubberButton; }
private slots:
@@ -44,6 +46,10 @@ private slots:
QButtonGroup *modeGroup;
QButtonGroup *cursorGroup;
QAction* zoomAction = nullptr;
QAction* labelAction = nullptr;
QAction* pickAction = nullptr;
void setCursorButtonsVisible(bool visible);
};
View
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>378</width>
<height>88</height>
<height>91</height>
</rect>
</property>
<property name="sizePolicy">
@@ -50,7 +50,7 @@
<number>9</number>
</property>
<item>
<widget class="QPushButton" name="zoomButton">
<widget class="ActionButton" name="zoomButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -63,10 +63,6 @@
<property name="text">
<string>zoom/pan</string>
</property>
<property name="icon">
<iconset resource="../gerbil.qrc">
<normaloff>:/basic/zoom</normaloff>:/basic/zoom</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
@@ -98,7 +94,7 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="labelButton">
<widget class="ActionButton" name="labelButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -111,10 +107,6 @@
<property name="text">
<string>label</string>
</property>
<property name="icon">
<iconset resource="../gerbil.qrc">
<normaloff>:/basic/pencil</normaloff>:/basic/pencil</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
@@ -143,7 +135,7 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="pickButton">
<widget class="ActionButton" name="pickButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -156,10 +148,6 @@
<property name="text">
<string>pick</string>
</property>
<property name="icon">
<iconset resource="../gerbil.qrc">
<normaloff>:/basic/picker</normaloff>:/basic/picker</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
Oops, something went wrong.

0 comments on commit 8b78afc

Please sign in to comment.