Skip to content

Commit

Permalink
Actions for adding images to the stack tree.
Browse files Browse the repository at this point in the history
The stack tree is a window that contains a tree that represents the
image stack. The top-levels are the images that are part of the stack.
I expect that items under the toplevel will be stack parameters, such
as offsets and dark field images.
  • Loading branch information
steveicarus committed Sep 22, 2010
1 parent aac7dac commit 9993009
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 39 deletions.
63 changes: 42 additions & 21 deletions AstrobenchMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
# include <QFileDialog>
# include <QGraphicsPixmapItem>
# include <QListWidgetItem>
# include <QTreeWidget>
# include <vips/vips>

using namespace vips;

AstrobenchMain::AstrobenchMain(QWidget*parent)
: QMainWindow(parent)
{
Expand All @@ -44,6 +47,10 @@ AstrobenchMain::AstrobenchMain(QWidget*parent)
connect(ui.source_list, SIGNAL(customContextMenuRequested(const QPoint&)),
SLOT(source_item_context_menu_slot_(const QPoint&)));

// Signals from the Stack tab
connect(ui.stack_tree, SIGNAL(customContextMenuRequested(const QPoint&)),
SLOT(stack_tree_context_menu_slot_(const QPoint&)));

// Signals from the Image Display tab
connect(ui.image_zoom_slider, SIGNAL(valueChanged(int)),
SLOT(image_zoom_slider_value_changed_slot_(int)));
Expand Down Expand Up @@ -106,26 +113,21 @@ void AstrobenchMain::display_image(vips::VImage&img)
display_pixmap_->show();
}

using namespace vips;
class SourceImageItem : public QListWidgetItem {

public:
SourceImageItem(const QString&path, VImage*img);
~SourceImageItem();
void AstrobenchMain::stack_image(SourceImageItem*img)
{
QTreeWidgetItem*item = new QTreeWidgetItem;
item->setText(0, img->text());
ui.stack_tree->addTopLevelItem(item);

VImage& image() { return *image_; }
private:
VImage*image_;
};
img->set_stack_item(item);
}

SourceImageItem::SourceImageItem(const QString&path, VImage*img)
: QListWidgetItem(path), image_(img)
void AstrobenchMain::dark_field_image(SourceImageItem*img)
{
}

SourceImageItem::~SourceImageItem()
void AstrobenchMain::close_image(SourceImageItem*img)
{
if (image_) delete image_;
}

void AstrobenchMain::actionOpen_Image_slot_(void)
Expand Down Expand Up @@ -173,23 +175,42 @@ void AstrobenchMain::source_item_context_menu_slot_(const QPoint&pos)
SourceImageItem*item = dynamic_cast<SourceImageItem*> (raw_item);
if (item == 0) return;

QAction show ("Show", 0);
QAction close("Close", 0);
QAction a_show ("Show", 0);
QAction a_stack("Stack", 0);
QAction a_dark ("Dark Field", 0);
QAction a_close("Close", 0);

a_stack.setEnabled( ! item->is_stacked() );
a_dark .setEnabled( ! item->is_stacked() );

QList<QAction*> menu_list;
menu_list .append(&show);
menu_list .append(&close);
menu_list .append(&a_show);
menu_list .append(&a_stack);
menu_list .append(&a_dark);
menu_list .append(&a_close);

QAction*hit = QMenu::exec(menu_list, mapToGlobal(pos), &show);
QAction*hit = QMenu::exec(menu_list, mapToGlobal(pos), &a_show);

if (hit == &show) {
if (hit == &a_show) {
display_image(item->image());

} else if (hit == &close) {
} else if (hit == &a_stack) {
stack_image(item);

} else if (hit == &a_dark) {
dark_field_image(item);

} else if (hit == &a_close) {
close_image(item);
}
}

void AstrobenchMain::stack_tree_context_menu_slot_(const QPoint&pos)
{
QTreeWidgetItem*raw_item = ui.stack_tree->itemAt(pos);
if (raw_item == 0) return;
}

void AstrobenchMain::image_zoom_slider_value_changed_slot_(int value)
{
}
31 changes: 31 additions & 0 deletions AstrobenchMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@

# include <qapplication.h>
# include <QGraphicsScene>
# include <QListWidgetItem>
# include <QTreeWidgetItem>
# include <vips/vips>
# include "ui_astrobench.h"

class SourceImageItem;

class AstrobenchMain : public QMainWindow {

Expand All @@ -33,8 +36,16 @@ class AstrobenchMain : public QMainWindow {
AstrobenchMain(QWidget*parent =0);
~AstrobenchMain();

// Display the VImage in the image display window.
void display_image(vips::VImage&img);

// Add this image to the image stack.
void stack_image(SourceImageItem*img);
// Declare this image as a dark-field image.
void dark_field_image(SourceImageItem*img);
// Remove the image item from any roles and release it.
void close_image(SourceImageItem*img);

private:
// The user interface...
Ui::AstrobenchMainWidget ui;
Expand All @@ -54,8 +65,28 @@ class AstrobenchMain : public QMainWindow {
void source_item_activated_slot_(QListWidgetItem*item);
void source_item_context_menu_slot_(const QPoint&);

// Signals from the Stack tab
void stack_tree_context_menu_slot_(const QPoint&);

// Signals from the Image Display tab
void image_zoom_slider_value_changed_slot_(int value);
};

class SourceImageItem : public QListWidgetItem {

public:
SourceImageItem(const QString&path, vips::VImage*img);
~SourceImageItem();

vips::VImage& image() { return *image_; }

void set_stack_item(QTreeWidgetItem*);
inline bool is_stacked (void) const { return stack_item_ != 0; }

private:
vips::VImage*image_;

QTreeWidgetItem*stack_item_;
};

#endif
40 changes: 40 additions & 0 deletions SourceImageItem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2010 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/

# include "AstrobenchMain.h"
# include <vips/vips>

using namespace vips;

SourceImageItem::SourceImageItem(const QString&path, VImage*img)
: QListWidgetItem(path), image_(img)
{
stack_item_ = 0;
}

SourceImageItem::~SourceImageItem()
{
if (image_) delete image_;
}

void SourceImageItem::set_stack_item(QTreeWidgetItem*item)
{
assert(stack_item_ == 0);
stack_item_ = item;
}
2 changes: 1 addition & 1 deletion astrobench.pro
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ unix {
LIBS +=
}

SOURCES += main.cpp
SOURCES += main.cpp SourceImageItem.cpp

FORMS += astrobench.ui
HEADERS += AstrobenchMain.h
Expand Down
27 changes: 10 additions & 17 deletions astrobench.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,19 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QTableWidget" name="tableWidget">
<property name="rowCount">
<number>0</number>
</property>
<property name="columnCount">
<number>3</number>
<widget class="QTreeWidget" name="stack_tree">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>dX</string>
</property>
</column>
<column>
<property name="text">
<string>dY</string>
<string>Image</string>
</property>
</column>
</widget>
Expand Down

0 comments on commit 9993009

Please sign in to comment.