view host/ImageWindow.cpp @ 17:3cbd40805795 tip

Remove obsolete stuff from README
author Chris Cannam
date Tue, 03 Dec 2013 16:33:08 +0000
parents b30fcffc5000
children
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

#include "ImageWindow.h"

#include <QVBoxLayout>
#include <QLabel>
#include <QPixmap>

#include <iostream>

ImageWindow *ImageWindow::m_instance = 0;

ImageWindow::ImageWindow(QWidget *parent) :
    QDialog(parent),
    m_pixmap(0)
{
    QVBoxLayout *layout = new QVBoxLayout;
    setLayout(layout);
    m_label = new QLabel;
    layout->addWidget(m_label);
}

ImageWindow::~ImageWindow()
{
    delete m_pixmap;
}

ImageWindow *
ImageWindow::getInstance()
{
    if (m_instance) return m_instance;
    m_instance = new ImageWindow();
    m_instance->show();
    return m_instance;
}

void
ImageWindow::showImage(QString image)
{
    std::cerr << "ImageWindow::showImage(\"" << image.toStdString() << "\")" << std::endl;

    if (m_imageName == image) return;
    QPixmap *oldPixmap = m_pixmap;
    m_pixmap = new QPixmap(image);
    m_label->setPixmap(*m_pixmap);
    m_label->setFixedSize(m_pixmap->size());
    m_label->show();
    delete oldPixmap;
    m_imageName = image;
}