Skip to content
Snippets Groups Projects
Commit abcef651 authored by pospelov's avatar pospelov
Browse files

Prototype of MaterialBrowser

parent 8ed8db82
No related branches found
No related tags found
No related merge requests found
Showing
with 265 additions and 10 deletions
......@@ -50,6 +50,8 @@ public:
static QPixmap getPixmapFormFactor();
static QPixmap getPixmapDefault();
static QColor getRandomColor() { return QColor(qrand() % 256, qrand() % 256, qrand() % 256); }
//! sort graphics item according they y-coordinate
static bool sort_layers(QGraphicsItem* left, QGraphicsItem *right) {
return left->y() < right->y();
......
......@@ -60,7 +60,7 @@ void ISampleRectView::setPortCoordinates()
{
if(!getNumberOfPorts()) return;
// without main label ports will occupy all vertical space
// without main label ports can be placed over all vertical space
int hspace = getRectangle().height();
if( !getLabel().isEmpty() ) hspace -= m_label_vspace;
......@@ -70,6 +70,7 @@ void ISampleRectView::setPortCoordinates()
int ypos = getRectangle().height() - hspace + dy;
if(getNumberOfPorts() == 1) {
// if number of ports is 1, place it in the middle
ypos = getRectangle().height() - hspace + hspace/2;
}
......
#include "MaterialBrowser.h"
MaterialBrowser *MaterialBrowser::m_instance = 0;
MaterialBrowser::MaterialBrowser(QWidget *parent)
{
Q_ASSERT(!m_instance);
m_instance = this;
}
MaterialBrowser::~MaterialBrowser()
{
m_instance = 0;
}
MaterialBrowser *MaterialBrowser::instance()
{
return m_instance;
}
#ifndef MATERIALBROWSER_H
#define MATERIALBROWSER_H
#include <QObject>
//! main class to access materials
class MaterialBrowser : public QObject
{
Q_OBJECT
public:
MaterialBrowser(QWidget *parent = 0);
virtual ~MaterialBrowser();
static MaterialBrowser *instance();
private:
static MaterialBrowser *m_instance;
};
#endif // MATERIALBROWSER_H
#include "MaterialBrowserModel.h"
#include "DesignerHelper.h"
#include "MaterialManager.h"
#include <QColor>
MaterialBrowserModel::MaterialBrowserModel(QObject *parent)
: QAbstractTableModel(parent)
{
std::cout << "MaterialBrowserModel XXX 1.1 " << std::endl;
addMaterial("Air", 1., 0.);
std::cout << "MaterialBrowserModel XXX 1.2 " << std::endl;
addMaterial("Substrate", 1-6e-6, 2e-8);
std::cout << "MaterialBrowserModel XXX 1.3 " << std::endl;
addMaterial("Default", 1., 0.);
std::cout << "MaterialBrowserModel XXX 1.4 " << std::endl;
}
void MaterialBrowserModel::addMaterial(const char *name, double index_real, double index_imag)
{
const IMaterial *m = MaterialManager::getHomogeneousMaterial(name, index_real, index_imag);
m_mat_color[m] = DesignerHelper::getRandomColor();
m_nraw_mat.append(m);
}
int MaterialBrowserModel::rowCount(const QModelIndex & /*parent*/) const
{
return m_nraw_mat.size();
}
int MaterialBrowserModel::columnCount(const QModelIndex & /*parent*/) const
{
return 4;
}
QVariant MaterialBrowserModel::data(const QModelIndex &index, int role) const
{
std::cout << "MaterialBrowserModel::data() -> 1.1" << std::endl;
const HomogeneousMaterial *mat = dynamic_cast<const HomogeneousMaterial *>(m_nraw_mat.at(index.row()));
if( !mat ) {
std::cout << " MaterialBrowserModel::data() -> Panic" << std::endl;
return QVariant();
}
std::cout << "MaterialBrowserModel::data() -> 1.2" << std::endl;
if (role == Qt::DisplayRole)
{
std::cout << "MaterialBrowserModel::data() -> 1.3 " << index.row() << " " << m_nraw_mat.at(index.row()) << std::endl;
const HomogeneousMaterial *mat = dynamic_cast<const HomogeneousMaterial *>(m_nraw_mat.at(index.row()));
if( !mat ) {
std::cout << " MaterialBrowserModel::data() -> Panic" << std::endl;
return QVariant();
}
std::cout << "XXX " << mat << " " << mat->getName() << " " << mat->getRefractiveIndex().real()<< std::endl;
switch(index.column()) {
case 0:
return QString(mat->getName().c_str());
case 1:
return QString::number(mat->getRefractiveIndex().real());
case 2:
return QString::number(mat->getRefractiveIndex().imag());
case 3:
return QString();
default:
return QString("Row%1, Column%2")
.arg(index.row() + 1)
.arg(index.column() +1);
}
} else if (role == Qt::DecorationRole && index.column() == 0) {
return m_mat_color[mat];
}
return QVariant();
}
QVariant MaterialBrowserModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole)
{
if (orientation == Qt::Horizontal) {
switch (section)
{
case 0:
return QString("Name");
case 1:
return QString("Index::real");
case 2:
return QString("Index::imag");
case 3:
return QString("Comment");
}
} else if (orientation == Qt::Vertical) {
return QString("%1").arg(section);
}
}
return QVariant();
}
#ifndef MATERIALBROWSERMODEL_H
#define MATERIALBROWSERMODEL_H
#include <QAbstractTableModel>
#include <QMap>
class IMaterial;
class MaterialBrowserModel : public QAbstractTableModel
{
public:
MaterialBrowserModel(QObject *parent);
int rowCount(const QModelIndex &parent = QModelIndex()) const ;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
private:
// struct MaterialData {
// QColor color;
// };
void addMaterial(const char *name, double index_real, double index_imag);
QMap<const IMaterial *, QColor> m_mat_color;
QVector<const IMaterial *> m_nraw_mat;
};
#endif // MATERIALBROWSERMODEL_H
#include "MaterialBrowserView.h"
#include "MaterialBrowserModel.h"
#include <QTableView>
#include <QVBoxLayout>
#include <QHeaderView>
#include <iostream>
MaterialBrowserView::MaterialBrowserView(QWidget *parent)
: QDialog(parent)
, m_tableView(0)
{
std::cout << "MaterialEditorView::MaterialEditorView() -> " << std::endl;
setMinimumSize(128, 128);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
std::cout << "MaterialEditorView::MaterialEditorView() -> 1.1" << std::endl;
m_tableView = new QTableView(this);
std::cout << "MaterialEditorView::MaterialEditorView() -> 1.2" << std::endl;
m_tableModel = new MaterialBrowserModel(0);
std::cout << "MaterialEditorView::MaterialEditorView() -> 1.3" << std::endl;
m_tableView->setModel( m_tableModel );
std::cout << "MaterialEditorView::MaterialEditorView() -> 1.4" << std::endl;
m_tableView->horizontalHeader()->setStretchLastSection(true);
std::cout << "MaterialEditorView::MaterialEditorView() -> 1.5" << std::endl;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(m_tableView);
layout->setMargin(0);
layout->setSpacing(0);
setLayout(layout);
std::cout << "MaterialEditorView::MaterialEditorView() -> 1.6" << std::endl;
show();
std::cout << "MaterialEditorView::MaterialEditorView() -> 1.7" << std::endl;
}
#ifndef MATERIALBROWSERVIEW_H
#define MATERIALBROWSERVIEW_H
#include <QDialog>
class QTableView;
class MaterialBrowserModel;
class MaterialBrowserView : public QDialog
{
public:
explicit MaterialBrowserView(QWidget *parent = 0);
private:
QTableView *m_tableView;
MaterialBrowserModel *m_tableModel;
};
#endif // MATERIALBROWSERVIEW_H
......@@ -24,7 +24,10 @@ SOURCES += \
Views/Components/SampleDesigner/VariantManager.cpp \
Views/Components/SampleDesigner/SampleTreeInspector.cpp \
Views/Components/SampleDesigner/SampleWidgetBox.cpp \
Views/Components/SampleDesigner/SampleToolBar.cpp
Views/Components/SampleDesigner/SampleToolBar.cpp \
Views/Components/SampleDesigner/MaterialBrowserModel.cpp \
Views/Components/SampleDesigner/MaterialBrowserView.cpp \
Views/Components/SampleDesigner/MaterialBrowser.cpp
HEADERS += \
......@@ -49,7 +52,10 @@ HEADERS += \
Views/Components/SampleDesigner/VariantManager.h \
Views/Components/SampleDesigner/SampleTreeInspector.h \
Views/Components/SampleDesigner/SampleWidgetBox.h \
Views/Components/SampleDesigner/SampleToolBar.h
Views/Components/SampleDesigner/SampleToolBar.h \
Views/Components/SampleDesigner/MaterialBrowserModel.h \
Views/Components/SampleDesigner/MaterialBrowserView.h \
Views/Components/SampleDesigner/MaterialBrowser.h
RESOURCES += Views/Components/SampleDesigner/SampleDesigner.qrc
<RCC>
<qresource prefix="/SampleDesigner">
<file>images/background2.png</file>
<file>images/background3.png</file>
<file>images/background4.png</file>
<file>images/prev.png</file>
<file>images/next.png</file>
</qresource>
</RCC>
......@@ -6,6 +6,7 @@
#include <QStyle>
#include <iostream>
#include "MaterialBrowserView.h"
//! main tool bar on top of SampleView window
SampleToolBar::SampleToolBar(QWidget *parent)
......@@ -25,5 +26,6 @@ SampleToolBar::SampleToolBar(QWidget *parent)
void SampleToolBar::materialEditorCall()
{
std::cout << "SampleView::materialEditorCall() ->" << std::endl;
std::cout << "SampleToolBar::materialEditorCall() ->" << std::endl;
new MaterialBrowserView(parentWidget());
}
......@@ -2,6 +2,7 @@
#include "SampleViewComponents.h"
#include "SampleDesigner.h"
#include "SampleToolBar.h"
#include "MaterialBrowser.h"
#include <QDockWidget>
......@@ -22,11 +23,10 @@
SampleView::SampleView(QWidget *parent)
: Manhattan::FancyMainWindow(parent)
, m_sampleDesigner(0)
, m_sampleDesigner(new SampleDesigner(parent))
, m_toolBar(0)
, m_materialBrowser(new MaterialBrowser(parent))
{
m_sampleDesigner = new SampleDesigner(parent);
setObjectName(QLatin1String("SampleView"));
setCentralWidget(m_sampleDesigner->getCentralWidget());
......@@ -38,8 +38,6 @@ SampleView::SampleView(QWidget *parent)
initSubWindows();
for (int i = 0; i < NumberOfSubWindows; i++) {
QWidget *subWindow = m_subWindows[i];
//subWindow->setWindowTitle(subs[i]->windowTitle());
......@@ -59,6 +57,12 @@ SampleView::SampleView(QWidget *parent)
}
SampleView::~SampleView()
{
delete m_sampleDesigner;
delete m_materialBrowser;
}
void SampleView::materialEditorCall()
{
std::cout << "SampleView::materialEditorCall() ->" << std::endl;
......
......@@ -10,6 +10,8 @@
class SampleDesignerInterface;
class SampleDesigner;
class SampleToolBar;
class MaterialBrowser;
class SampleView : public Manhattan::FancyMainWindow
{
......@@ -27,6 +29,8 @@ public:
};
SampleView(QWidget *parent = 0);
virtual ~SampleView();
public slots:
void resetToDefaultLayout();
......@@ -39,7 +43,7 @@ private:
QWidget *m_subWindows[NumberOfSubWindows];
QDockWidget *m_dockWidgets[NumberOfSubWindows];
SampleToolBar *m_toolBar;
MaterialBrowser *m_materialBrowser;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment