first blood
This commit is contained in:
parent
78b528c0af
commit
91d5cabd26
163
AnimationBuilder/Animation.cpp
Normal file
163
AnimationBuilder/Animation.cpp
Normal file
@ -0,0 +1,163 @@
|
||||
#include "Animation.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
TAnimation::TAnimation(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TAnimation::SetMainWindow(MainWindow* window)
|
||||
{
|
||||
Window = window;
|
||||
}
|
||||
|
||||
|
||||
void TAnimation::AddFrame(const TFrame& frame)
|
||||
{
|
||||
FrameList.push_back(frame);
|
||||
}
|
||||
|
||||
|
||||
TFrame& TAnimation::GetFrame(int i)
|
||||
{
|
||||
return FrameList[i];
|
||||
}
|
||||
|
||||
size_t TAnimation::GetFrameCount()
|
||||
{
|
||||
return FrameList.size();
|
||||
}
|
||||
|
||||
int TAnimation::GetMaxWidth()
|
||||
{
|
||||
int r = FrameList[0].Pixmap->width() + FrameList[0].ShiftX;
|
||||
|
||||
for (size_t i = 1; i < FrameList.size(); i++)
|
||||
{
|
||||
if (r < FrameList[i].Pixmap->width() + FrameList[i].ShiftX)
|
||||
{
|
||||
r = FrameList[i].Pixmap->width() + FrameList[i].ShiftX;
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int TAnimation::GetMaxHeight()
|
||||
{
|
||||
int r = FrameList[0].Pixmap->height() + FrameList[0].ShiftY;
|
||||
|
||||
for (size_t i = 1; i < FrameList.size(); i++)
|
||||
{
|
||||
if (r < FrameList[i].Pixmap->height() + FrameList[i].ShiftY)
|
||||
{
|
||||
r = FrameList[i].Pixmap->height() + FrameList[i].ShiftY;
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
void TAnimation::FillSheet(boost::shared_ptr<QPixmap> sheetPixmap, std::vector<TFrameData>& frameDataArr)
|
||||
{
|
||||
int maxFrameWidth = GetMaxWidth();
|
||||
int maxFrameHeight = GetMaxHeight();
|
||||
|
||||
int cursorX = 0;
|
||||
int cursorY = 0;
|
||||
|
||||
|
||||
|
||||
QPainter p;
|
||||
|
||||
|
||||
p.begin(&(*sheetPixmap));
|
||||
|
||||
|
||||
for (size_t i=0; i<FrameList.size(); i++)
|
||||
{
|
||||
int shiftX = FrameList[i].ShiftX;
|
||||
int shiftY = FrameList[i].ShiftY;
|
||||
|
||||
|
||||
TFrameData frameData;
|
||||
|
||||
frameData.TexCoordFromX = static_cast<float>(cursorX) / sheetPixmap->width();
|
||||
frameData.TexCoordFromY = 1.f - static_cast<float>(cursorY + maxFrameHeight) / sheetPixmap->height();
|
||||
|
||||
frameData.TexCoordToX = static_cast<float>(cursorX + maxFrameWidth) / sheetPixmap->width();
|
||||
frameData.TexCoordToY = 1.f - static_cast<float>(cursorY) / sheetPixmap->height();
|
||||
|
||||
frameData.TimeToPlay = FrameList[i].TimeToPlay;
|
||||
|
||||
frameDataArr.push_back(frameData);
|
||||
|
||||
|
||||
|
||||
|
||||
QPixmap& pixmapToDraw = *(FrameList[i].Pixmap);
|
||||
|
||||
p.drawPixmap(cursorX + shiftX, cursorY + shiftY, pixmapToDraw);
|
||||
|
||||
cursorX += maxFrameWidth;
|
||||
|
||||
if (cursorX + maxFrameWidth >= sheetPixmap->width())
|
||||
{
|
||||
cursorX = 0;
|
||||
cursorY += maxFrameHeight;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
p.end();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TAnimation::LoadFrame()
|
||||
{
|
||||
QFileDialog dialog(Window);
|
||||
|
||||
dialog.setFileMode(QFileDialog::ExistingFiles);
|
||||
|
||||
dialog.setNameFilter("PNG images (*.png)");
|
||||
|
||||
if (dialog.exec())
|
||||
{
|
||||
|
||||
QStringList fileNames = dialog.selectedFiles();
|
||||
|
||||
for (int i = 0; i < fileNames.count(); i++)
|
||||
{
|
||||
boost::shared_ptr<QPixmap> pixmap(new QPixmap(fileNames[i], "PNG"));
|
||||
|
||||
QFileInfo q;
|
||||
q.setFile(fileNames[i]);
|
||||
|
||||
QString fn = q.fileName();
|
||||
|
||||
std::string fileName = fn.toUtf8().constData();
|
||||
|
||||
AddFrame(TFrame(pixmap, 0, fileName));
|
||||
|
||||
Window->LoadFrame(fileName);
|
||||
}
|
||||
|
||||
//FontFileName = (dialog.selectedFiles())[0];
|
||||
//emit SetFontNameTextSignal(FontFileName);
|
||||
|
||||
//LoadFontFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
111
AnimationBuilder/Animation.h
Normal file
111
AnimationBuilder/Animation.h
Normal file
@ -0,0 +1,111 @@
|
||||
#ifndef ANIMATION_H
|
||||
#define ANIMATION_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QGraphicsScene>
|
||||
#include <QPicture>
|
||||
#include <QPainter>
|
||||
#include <QMainWindow>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include "boost/shared_ptr.hpp"
|
||||
|
||||
|
||||
struct TFrame
|
||||
{
|
||||
boost::shared_ptr<QPixmap> Pixmap;
|
||||
size_t TimeToPlay;
|
||||
std::string FrameName;
|
||||
int ShiftX;
|
||||
int ShiftY;
|
||||
|
||||
TFrame(boost::shared_ptr<QPixmap> pixmap, size_t timeToPlay, const std::string& frameName)
|
||||
: Pixmap(pixmap)
|
||||
, TimeToPlay(timeToPlay)
|
||||
, FrameName(frameName)
|
||||
, ShiftX(0)
|
||||
, ShiftY(0)
|
||||
{
|
||||
}
|
||||
|
||||
TFrame(const TFrame& frame)
|
||||
{
|
||||
Pixmap = frame.Pixmap;
|
||||
TimeToPlay = frame.TimeToPlay;
|
||||
FrameName = frame.FrameName;
|
||||
ShiftX = frame.ShiftX;
|
||||
ShiftY = frame.ShiftY;
|
||||
}
|
||||
|
||||
TFrame& operator=(const TFrame& frame)
|
||||
{
|
||||
if (&frame == this)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
Pixmap = frame.Pixmap;
|
||||
TimeToPlay = frame.TimeToPlay;
|
||||
FrameName = frame.FrameName;
|
||||
ShiftX = frame.ShiftX;
|
||||
ShiftY = frame.ShiftY;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct TFrameData
|
||||
{
|
||||
float TexCoordFromX;
|
||||
float TexCoordFromY;
|
||||
float TexCoordToX;
|
||||
float TexCoordToY;
|
||||
size_t TimeToPlay;
|
||||
};
|
||||
|
||||
class MainWindow;
|
||||
|
||||
|
||||
|
||||
|
||||
class TAnimation : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
|
||||
std::vector<TFrame> FrameList;
|
||||
|
||||
MainWindow* Window;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
explicit TAnimation(QObject *parent = 0);
|
||||
|
||||
void SetMainWindow(MainWindow* window);
|
||||
|
||||
void AddFrame(const TFrame& frame);
|
||||
|
||||
TFrame& GetFrame(int i);
|
||||
size_t GetFrameCount();
|
||||
|
||||
int GetMaxWidth();
|
||||
int GetMaxHeight();
|
||||
|
||||
void FillSheet(boost::shared_ptr<QPixmap> sheetPixmap, std::vector<TFrameData>& frameDataArr);
|
||||
|
||||
|
||||
public slots:
|
||||
void LoadFrame();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // ANIMATION_H
|
23
AnimationBuilder/AnimationBuilder.pro
Normal file
23
AnimationBuilder/AnimationBuilder.pro
Normal file
@ -0,0 +1,23 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-04-19T21:10:48
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
TARGET = AnimationBuilder
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
Animation.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
Animation.h
|
||||
|
||||
INCLUDEPATH += $$(LibsPath)/boost_1_47_0
|
||||
DEPENDPATH += $$(LibsPath)/boost_1_47_0
|
||||
|
||||
FORMS += mainwindow.ui
|
19
AnimationBuilder/main.cpp
Normal file
19
AnimationBuilder/main.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
TAnimation Animation;
|
||||
|
||||
MainWindow w;
|
||||
|
||||
w.SetAnimation(&Animation);
|
||||
Animation.SetMainWindow(&w);
|
||||
|
||||
w.show();
|
||||
|
||||
|
||||
return a.exec();
|
||||
}
|
294
AnimationBuilder/mainwindow.cpp
Normal file
294
AnimationBuilder/mainwindow.cpp
Normal file
@ -0,0 +1,294 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
//Animation.SetMainWindow(this);
|
||||
|
||||
frameImageDefaultPosX = ui->FrameImage->pos().x();
|
||||
frameImageDefaultPosY = ui->FrameImage->pos().y();
|
||||
|
||||
//int sheetDefaultWidth = (ui->SheetWidth->text()).toInt();
|
||||
//int sheetDefaultHeight = (ui->SheetHeight->text()).toInt();
|
||||
|
||||
SheetPixmap = boost::shared_ptr<QPixmap>(new QPixmap(4, 4));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
int MainWindow::GetSelectedFrame()
|
||||
{
|
||||
QListWidgetItem * item = *(ui->FrameList->selectedItems().begin());
|
||||
|
||||
int it=0;
|
||||
|
||||
for (int i=0; i<ui->FrameList->count(); i++)
|
||||
{
|
||||
if (ui->FrameList->item(i) == item)
|
||||
{
|
||||
it = i;
|
||||
}
|
||||
}
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
void MainWindow::SetAnimation(TAnimation* animation)
|
||||
{
|
||||
Animation = animation;
|
||||
|
||||
QObject::connect(ui->LoadFrameButton, SIGNAL(pressed()), Animation, SLOT(LoadFrame()));
|
||||
QObject::connect(ui->FrameList, SIGNAL(itemSelectionChanged()), this, SLOT(ItemClicked()));
|
||||
QObject::connect(ui->ShiftX_spinBox, SIGNAL(valueChanged(int)), this, SLOT(ShiftXChanged(int)));
|
||||
QObject::connect(ui->ShiftY_spinBox, SIGNAL(valueChanged(int)), this, SLOT(ShiftYChanged(int)));
|
||||
QObject::connect(ui->TimeFrameEdit, SIGNAL(textChanged(const QString&)), this, SLOT(TimeFrameChanged(const QString&)));
|
||||
QObject::connect(ui->GenerateTimeButton, SIGNAL(pressed()), this, SLOT(GenerateTimeFrameBy12Fps()));
|
||||
QObject::connect(ui->GenerateSheetButton, SIGNAL(pressed()), this, SLOT(GenerateSheet()));
|
||||
QObject::connect(ui->SaveSheetButton, SIGNAL(pressed()), this, SLOT(SaveSheet()));
|
||||
QObject::connect(ui->SaveAnimParamsButton, SIGNAL(pressed()), this, SLOT(SaveAnimationParams()));
|
||||
QObject::connect(ui->AnimateCheckBox, SIGNAL(stateChanged(int)), this, SLOT(AnimateCheckBoxStateChanged(int)));
|
||||
QObject::connect(&AnimTimer, SIGNAL(timeout()), this, SLOT(TimerTimeout()));
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::ItemClicked()
|
||||
{
|
||||
SelectFrame(GetSelectedFrame());
|
||||
}
|
||||
|
||||
void MainWindow::ShiftXChanged(int val)
|
||||
{
|
||||
int i = GetSelectedFrame();
|
||||
|
||||
Animation->GetFrame(i).ShiftX = val;
|
||||
|
||||
ItemClicked();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::ShiftYChanged(int val)
|
||||
{
|
||||
int i = GetSelectedFrame();
|
||||
|
||||
Animation->GetFrame(i).ShiftY = val;
|
||||
|
||||
ItemClicked();
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::TimeFrameChanged(const QString& str)
|
||||
{
|
||||
bool ok;
|
||||
|
||||
int timeFrame = str.toInt(&ok);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
int i = GetSelectedFrame();
|
||||
|
||||
Animation->GetFrame(i).TimeToPlay = timeFrame;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::GenerateTimeFrameBy12Fps()
|
||||
{
|
||||
float timeStep = 1000.f / 12.f;
|
||||
|
||||
int frameCount = ui->FrameList->count();
|
||||
|
||||
for (int i=0; i<frameCount; i++)
|
||||
{
|
||||
int totalTime = static_cast<int>(timeStep * (i + 1));
|
||||
|
||||
Animation->GetFrame(i).TimeToPlay = totalTime;
|
||||
|
||||
}
|
||||
|
||||
|
||||
ItemClicked();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::GenerateSheet()
|
||||
{
|
||||
int sheetWidth = (ui->SheetWidth->text()).toInt();
|
||||
int sheetHeight = (ui->SheetHeight->text()).toInt();
|
||||
|
||||
std::vector<TFrameData> frameDataArr;
|
||||
|
||||
SheetPixmap = boost::shared_ptr<QPixmap>(new QPixmap(sheetWidth, sheetHeight));
|
||||
|
||||
QColor transparentColor(0,0,0,0);
|
||||
|
||||
SheetPixmap->fill(transparentColor);
|
||||
|
||||
Animation->FillSheet(SheetPixmap, frameDataArr);
|
||||
|
||||
ui->PixmapSheet->setPixmap(*SheetPixmap);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ui->OutputXmlFile->clear();
|
||||
|
||||
AnimationParamsText = "<Animation>\n\t<Frames>\n";
|
||||
|
||||
for (size_t i = 0; i < frameDataArr.size(); i++)
|
||||
{
|
||||
AnimationParamsText += QString("\t\t<Frame><TexCoordFrom x='%1' y='%2'/><TexCoordTo x='%3' y='%4'/><TimePassed>%5</TimePassed></Frame>\n")
|
||||
.arg(QString::number(frameDataArr[i].TexCoordFromX))
|
||||
.arg(QString::number(frameDataArr[i].TexCoordFromY))
|
||||
.arg(QString::number(frameDataArr[i].TexCoordToX))
|
||||
.arg(QString::number(frameDataArr[i].TexCoordToY))
|
||||
.arg(QString::number(frameDataArr[i].TimeToPlay));
|
||||
}
|
||||
|
||||
AnimationParamsText += "\t</Frames>\n</Animation>";
|
||||
ui->OutputXmlFile->appendPlainText(AnimationParamsText);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::SaveSheet()
|
||||
{
|
||||
QFileDialog dialog(this);
|
||||
|
||||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
|
||||
dialog.setNameFilter("PNG images (*.png)");
|
||||
|
||||
dialog.setDefaultSuffix("png");
|
||||
|
||||
if (dialog.exec())
|
||||
{
|
||||
QString fileName = *(dialog.selectedFiles().begin());
|
||||
|
||||
SheetPixmap->save(fileName, "PNG");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainWindow::SaveAnimationParams()
|
||||
{
|
||||
QFileDialog dialog(this);
|
||||
|
||||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
|
||||
dialog.setNameFilter("XML files (*.xml)");
|
||||
|
||||
dialog.setDefaultSuffix("xml");
|
||||
|
||||
if (dialog.exec())
|
||||
{
|
||||
QString fileName = *(dialog.selectedFiles().begin());
|
||||
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
QTextStream outStream(&file);
|
||||
outStream << AnimationParamsText;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::AnimateCheckBoxStateChanged(int state)
|
||||
{
|
||||
if (state == Qt::Checked)
|
||||
{
|
||||
currentFrameOnTimer = 0;
|
||||
|
||||
|
||||
|
||||
AnimTimer.setInterval(Animation->GetFrame(currentFrameOnTimer).TimeToPlay);
|
||||
AnimTimer.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
AnimTimer.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::TimerTimeout()
|
||||
{
|
||||
|
||||
|
||||
int prevFrameTime = Animation->GetFrame(currentFrameOnTimer).TimeToPlay;
|
||||
|
||||
currentFrameOnTimer++;
|
||||
|
||||
if (currentFrameOnTimer >= Animation->GetFrameCount())
|
||||
{
|
||||
currentFrameOnTimer = 0;
|
||||
}
|
||||
|
||||
TFrame& frame = Animation->GetFrame(currentFrameOnTimer);
|
||||
|
||||
int timeToPlay = frame.TimeToPlay - prevFrameTime;
|
||||
|
||||
if (timeToPlay < 0)
|
||||
{
|
||||
timeToPlay = 0;
|
||||
}
|
||||
|
||||
|
||||
int newPosX = frameImageDefaultPosX + frame.ShiftX;
|
||||
int newPosY = frameImageDefaultPosY + frame.ShiftY;
|
||||
|
||||
ui->FrameImage->move(newPosX, newPosY);
|
||||
ui->FrameImage->setPixmap(*(frame.Pixmap));
|
||||
|
||||
AnimTimer.setInterval(timeToPlay);
|
||||
AnimTimer.start();
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::SelectFrame(int i)
|
||||
{
|
||||
TFrame& frame = Animation->GetFrame(i);
|
||||
|
||||
ui->FrameImage->setPixmap(*(frame.Pixmap));
|
||||
|
||||
int newPosX = frameImageDefaultPosX + frame.ShiftX;
|
||||
int newPosY = frameImageDefaultPosY + frame.ShiftY;
|
||||
|
||||
ui->FrameImage->move(newPosX, newPosY);
|
||||
|
||||
ui->ShiftX_spinBox->setValue(frame.ShiftX);
|
||||
ui->ShiftY_spinBox->setValue(frame.ShiftY);
|
||||
|
||||
ui->TimeFrameEdit->setText(QString::number(frame.TimeToPlay));
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::LoadFrame(const std::string& text)
|
||||
{
|
||||
ui->FrameList->addItem(QString(text.c_str()));
|
||||
|
||||
}
|
66
AnimationBuilder/mainwindow.h
Normal file
66
AnimationBuilder/mainwindow.h
Normal file
@ -0,0 +1,66 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QListWidget>
|
||||
#include <QTextStream>
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
#include "Animation.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
void SetAnimation(TAnimation* animation);
|
||||
|
||||
|
||||
|
||||
public slots:
|
||||
void SelectFrame(int i);
|
||||
void LoadFrame(const std::string& text);
|
||||
void ItemClicked();
|
||||
|
||||
void ShiftXChanged(int val);
|
||||
void ShiftYChanged(int val);
|
||||
void TimeFrameChanged(const QString& str);
|
||||
|
||||
void GenerateTimeFrameBy12Fps();
|
||||
void GenerateSheet();
|
||||
|
||||
void SaveSheet();
|
||||
void SaveAnimationParams();
|
||||
|
||||
void AnimateCheckBoxStateChanged(int state);
|
||||
void TimerTimeout();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
TAnimation* Animation;
|
||||
|
||||
int frameImageDefaultPosX;
|
||||
int frameImageDefaultPosY;
|
||||
|
||||
boost::shared_ptr<QPixmap> SheetPixmap;
|
||||
QString AnimationParamsText;
|
||||
|
||||
QTimer AnimTimer;
|
||||
int currentFrameOnTimer;
|
||||
|
||||
int GetSelectedFrame();
|
||||
|
||||
//void SetTimerToNextFrame();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
390
AnimationBuilder/mainwindow.ui
Normal file
390
AnimationBuilder/mainwindow.ui
Normal file
@ -0,0 +1,390 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>700</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>631</width>
|
||||
<height>442</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>700</width>
|
||||
<height>600</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>AnimationBuilder</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<widget class="QPushButton" name="LoadFrameButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>30</y>
|
||||
<width>111</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add frames...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>170</x>
|
||||
<y>60</y>
|
||||
<width>171</width>
|
||||
<height>161</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<widget class="QLabel" name="FrameImage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>151</width>
|
||||
<height>141</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QListWidget" name="FrameList">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>60</y>
|
||||
<width>151</width>
|
||||
<height>191</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QSpinBox" name="ShiftX_spinBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>490</x>
|
||||
<y>60</y>
|
||||
<width>42</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QSpinBox" name="ShiftY_spinBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>490</x>
|
||||
<y>90</y>
|
||||
<width>42</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>410</x>
|
||||
<y>60</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>shift on X:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>410</x>
|
||||
<y>90</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>shift on Y:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="TimeFrameEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>490</x>
|
||||
<y>120</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>410</x>
|
||||
<y>120</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>time to play:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="SheetWidth">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>260</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>512</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="SheetHeight">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>290</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>256</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>260</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sheet width:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>290</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sheet height:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="GenerateSheetButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>320</y>
|
||||
<width>131</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Generate sheet</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="GenerateTimeButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>420</x>
|
||||
<y>150</y>
|
||||
<width>141</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Generate by 12 fps</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="PixmapSheet">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>180</x>
|
||||
<y>250</y>
|
||||
<width>512</width>
|
||||
<height>256</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>180</x>
|
||||
<y>250</y>
|
||||
<width>511</width>
|
||||
<height>261</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPlainTextEdit" name="OutputXmlFile">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>350</y>
|
||||
<width>141</width>
|
||||
<height>121</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QPlainTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="SaveSheetButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>480</y>
|
||||
<width>131</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save sheet...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="SaveAnimParamsButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>510</y>
|
||||
<width>131</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save anim params...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="AnimateCheckBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>170</x>
|
||||
<y>230</y>
|
||||
<width>70</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Animate</string>
|
||||
</property>
|
||||
</widget>
|
||||
<zorder>frame_2</zorder>
|
||||
<zorder>LoadFrameButton</zorder>
|
||||
<zorder>frame</zorder>
|
||||
<zorder>FrameList</zorder>
|
||||
<zorder>ShiftX_spinBox</zorder>
|
||||
<zorder>ShiftY_spinBox</zorder>
|
||||
<zorder>label</zorder>
|
||||
<zorder>label_2</zorder>
|
||||
<zorder>TimeFrameEdit</zorder>
|
||||
<zorder>label_3</zorder>
|
||||
<zorder>SheetWidth</zorder>
|
||||
<zorder>SheetHeight</zorder>
|
||||
<zorder>label_4</zorder>
|
||||
<zorder>label_5</zorder>
|
||||
<zorder>GenerateSheetButton</zorder>
|
||||
<zorder>GenerateTimeButton</zorder>
|
||||
<zorder>PixmapSheet</zorder>
|
||||
<zorder>OutputXmlFile</zorder>
|
||||
<zorder>SaveSheetButton</zorder>
|
||||
<zorder>SaveAnimParamsButton</zorder>
|
||||
<zorder>AnimateCheckBox</zorder>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>700</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
18
Bn1An1Converter/Bn1An1Converter.pro
Normal file
18
Bn1An1Converter/Bn1An1Converter.pro
Normal file
@ -0,0 +1,18 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-06-01T11:21:21
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
TARGET = Bn1An1Converter
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp
|
||||
|
||||
HEADERS += mainwindow.h
|
||||
|
||||
FORMS += mainwindow.ui
|
11
Bn1An1Converter/main.cpp
Normal file
11
Bn1An1Converter/main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
387
Bn1An1Converter/mainwindow.cpp
Normal file
387
Bn1An1Converter/mainwindow.cpp
Normal file
@ -0,0 +1,387 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTextStream>
|
||||
|
||||
|
||||
struct TBoneStruct
|
||||
{
|
||||
float v[3];
|
||||
float q[4];
|
||||
float len;
|
||||
|
||||
QString parentBoneName;
|
||||
};
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
QObject::connect(ui->ConvertAn1, SIGNAL(clicked()), this, SLOT(CallConvertAn1()));
|
||||
QObject::connect(ui->ConvertBn1, SIGNAL(clicked()), this, SLOT(CallConvertBn1()));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::CallConvertAn1()
|
||||
{
|
||||
QFileDialog dialog(this);
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
dialog.setAcceptMode(QFileDialog::AcceptOpen);
|
||||
|
||||
if (dialog.exec())
|
||||
{
|
||||
QMessageBox msgBox1;
|
||||
msgBox1.setText("Begin");
|
||||
msgBox1.exec();
|
||||
|
||||
QFile file(dialog.selectedFiles()[0]);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Fail");
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QFileDialog dialogSave(this);
|
||||
dialogSave.setFileMode(QFileDialog::AnyFile);
|
||||
dialogSave.setAcceptMode(QFileDialog::AcceptSave);
|
||||
|
||||
if (!dialogSave.exec())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray saveArr;
|
||||
|
||||
|
||||
QFile saveFile(dialogSave.selectedFiles()[0]);
|
||||
if (!saveFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Fail");
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QTextStream in(&file);
|
||||
QString line;
|
||||
|
||||
//======= Go file parsing
|
||||
|
||||
saveArr.push_back('A');
|
||||
saveArr.push_back('N');
|
||||
saveArr.push_back((char)0);
|
||||
saveArr.push_back((char)1);
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
int frameCount = line.remove("Frames ").toInt();
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
int boneCount = line.remove("Bones ").toInt();
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&boneCount, 4);
|
||||
saveArr.insert(saveArr.size(), (char*)&frameCount, 4);
|
||||
|
||||
QStringList splited;
|
||||
|
||||
float v[3];
|
||||
float q[4];
|
||||
|
||||
float len;
|
||||
|
||||
for (int i=0; i<frameCount; i++)
|
||||
{
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
for (int j=0; j<boneCount; j++)
|
||||
{
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
v[0] = splited.at(0).toFloat()*0.1;
|
||||
v[1] = splited.at(2).toFloat()*0.1;
|
||||
v[2] = -splited.at(1).toFloat()*0.1;
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
q[0] = splited.at(0).toFloat();
|
||||
q[1] = splited.at(2).toFloat();
|
||||
q[2] = -splited.at(1).toFloat();
|
||||
q[3] = splited.at(3).toFloat();
|
||||
|
||||
line = in.readLine();
|
||||
len = line.toFloat()*0.1;
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)v, 12);
|
||||
saveArr.insert(saveArr.size(), (char*)q, 16);
|
||||
saveArr.insert(saveArr.size(), (char*)&len, 4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
saveFile.write(saveArr);
|
||||
|
||||
//======= End file parsing
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("End");
|
||||
msgBox.exec();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::CallConvertBn1()
|
||||
{
|
||||
QFileDialog dialog(this);
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
dialog.setAcceptMode(QFileDialog::AcceptOpen);
|
||||
|
||||
if (dialog.exec())
|
||||
{
|
||||
QMessageBox msgBox1;
|
||||
msgBox1.setText("Begin");
|
||||
msgBox1.exec();
|
||||
|
||||
QFile file(dialog.selectedFiles()[0]);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Fail");
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QFileDialog dialogSave(this);
|
||||
dialogSave.setFileMode(QFileDialog::AnyFile);
|
||||
dialogSave.setAcceptMode(QFileDialog::AcceptSave);
|
||||
|
||||
if (!dialogSave.exec())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray saveArr;
|
||||
|
||||
|
||||
QFile saveFile(dialogSave.selectedFiles()[0]);
|
||||
if (!saveFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Fail");
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
saveArr.push_back('B');
|
||||
saveArr.push_back('N');
|
||||
saveArr.push_back((char)0);
|
||||
saveArr.push_back((char)2);
|
||||
|
||||
|
||||
QTextStream in(&file);
|
||||
QString line;
|
||||
|
||||
int boneCount;
|
||||
|
||||
QString boneName;
|
||||
QString parentBoneName;
|
||||
|
||||
float v[3];
|
||||
float q[4];
|
||||
|
||||
float len;
|
||||
|
||||
QStringList splited;
|
||||
|
||||
std::map<QString, int> boneNameMap;
|
||||
|
||||
//======= Go file parsing
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
boneCount = line.remove("Bones ").toInt();
|
||||
|
||||
std::vector<TBoneStruct> boneStructMap;
|
||||
|
||||
for (int i=0; i<boneCount; i++)
|
||||
{
|
||||
|
||||
TBoneStruct b;
|
||||
|
||||
line = in.readLine();
|
||||
boneName = line;
|
||||
|
||||
boneNameMap[boneName] = i;
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
b.v[0] = splited.at(0).toFloat()*0.1;
|
||||
b.v[1] = splited.at(2).toFloat()*0.1;
|
||||
b.v[2] = -splited.at(1).toFloat()*0.1;
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
b.q[0] = splited.at(0).toFloat();
|
||||
b.q[1] = splited.at(2).toFloat();
|
||||
b.q[2] = -splited.at(1).toFloat();
|
||||
b.q[3] = splited.at(3).toFloat();
|
||||
|
||||
line = in.readLine();
|
||||
b.len = line.toFloat()*0.1;
|
||||
|
||||
line = in.readLine();
|
||||
b.parentBoneName = line;
|
||||
|
||||
boneStructMap.push_back(b);
|
||||
|
||||
/*
|
||||
saveArr.insert(saveArr.size(), (char*)v, 12);
|
||||
saveArr.insert(saveArr.size(), (char*)q, 16);
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&len, 4);
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&len, 4);*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
int vertexCount = line.remove("Vertices ").toInt();
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&boneCount, 4);
|
||||
saveArr.insert(saveArr.size(), (char*)&vertexCount, 4);
|
||||
|
||||
for (int i=0; i<boneCount; i++)
|
||||
{
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)boneStructMap[i].v, 12);
|
||||
saveArr.insert(saveArr.size(), (char*)boneStructMap[i].q, 16);
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&boneStructMap[i].len, 4);
|
||||
|
||||
int parentBoneIndex;
|
||||
if (boneNameMap.count(boneStructMap[i].parentBoneName) == 0)
|
||||
{
|
||||
parentBoneIndex = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
parentBoneIndex = boneNameMap[boneStructMap[i].parentBoneName];
|
||||
}
|
||||
saveArr.insert(saveArr.size(), (char*)&parentBoneIndex, 4);
|
||||
}
|
||||
|
||||
int wcount;
|
||||
float weight;
|
||||
|
||||
for (int i=0; i<vertexCount; i++)
|
||||
{
|
||||
line = in.readLine();
|
||||
wcount = line.remove("WCount ").toInt();
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&wcount, 4);
|
||||
|
||||
|
||||
for (int j=0; j<wcount; j++)
|
||||
{
|
||||
line = in.readLine();
|
||||
int lastSpacebarPos = line.lastIndexOf(" ");
|
||||
line[lastSpacebarPos] = '|';
|
||||
splited = line.split("|", QString::SkipEmptyParts);
|
||||
boneName = splited.at(0);
|
||||
weight = splited.at(1).toFloat();
|
||||
|
||||
int boneIndex = boneNameMap[boneName];
|
||||
|
||||
saveArr.insert(saveArr.size(), (char*)&boneIndex, 4);
|
||||
saveArr.insert(saveArr.size(), (char*)&weight, 4);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
line = in.readLine();
|
||||
|
||||
int frameCount = line.remove("Frames ").toInt();
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
int boneCount = line.remove("Bones ").toInt();
|
||||
|
||||
QStringList splited;
|
||||
|
||||
float v[3];
|
||||
float q[4];
|
||||
|
||||
float len;
|
||||
|
||||
for (int i=0; i<frameCount; i++)
|
||||
{
|
||||
|
||||
line = in.readLine();
|
||||
|
||||
for (int j=0; j<boneCount; j++)
|
||||
{
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
v[0] = splited.at(0).toFloat();
|
||||
v[1] = splited.at(1).toFloat();
|
||||
v[2] = splited.at(2).toFloat();
|
||||
|
||||
line = in.readLine();
|
||||
splited = line.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
q[0] = splited.at(0).toFloat();
|
||||
q[1] = splited.at(1).toFloat();
|
||||
q[2] = splited.at(2).toFloat();
|
||||
q[3] = splited.at(3).toFloat();
|
||||
|
||||
line = in.readLine();
|
||||
len = line.toFloat();
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
saveFile.write(saveArr);
|
||||
|
||||
//======= End file parsing
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("End");
|
||||
msgBox.exec();
|
||||
|
||||
|
||||
}
|
||||
}
|
26
Bn1An1Converter/mainwindow.h
Normal file
26
Bn1An1Converter/mainwindow.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
void CallConvertAn1();
|
||||
void CallConvertBn1();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
67
Bn1An1Converter/mainwindow.ui
Normal file
67
Bn1An1Converter/mainwindow.ui
Normal file
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<widget class="QPushButton" name="ConvertAn1">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>20</y>
|
||||
<width>121</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Convert An1</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="ConvertBn1">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>60</y>
|
||||
<width>121</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Convert Bn1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
BIN
FreeTypeWorker-win/release/FreeTypeWorker.exe
Normal file
BIN
FreeTypeWorker-win/release/FreeTypeWorker.exe
Normal file
Binary file not shown.
BIN
FreeTypeWorker-win/release/QtCore4.dll
Normal file
BIN
FreeTypeWorker-win/release/QtCore4.dll
Normal file
Binary file not shown.
BIN
FreeTypeWorker-win/release/QtGui4.dll
Normal file
BIN
FreeTypeWorker-win/release/QtGui4.dll
Normal file
Binary file not shown.
BIN
FreeTypeWorker-win/release/msvcp100.dll
Normal file
BIN
FreeTypeWorker-win/release/msvcp100.dll
Normal file
Binary file not shown.
BIN
FreeTypeWorker-win/release/msvcr100.dll
Normal file
BIN
FreeTypeWorker-win/release/msvcr100.dll
Normal file
Binary file not shown.
30
FreeTypeWorker/FreeTypeWorker.pro
Normal file
30
FreeTypeWorker/FreeTypeWorker.pro
Normal file
@ -0,0 +1,30 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-01-08T09:45:02
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
TARGET = FreeTypeWorker
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
freetypemodel.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
freetypemodel.h
|
||||
|
||||
FORMS += mainwindow.ui
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$(LibsPath)/freetype-2.4.7/objs/win32/vc2010/ -lfreetype247MT
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$(LibsPath)/freetype-2.4.7/objs/win32/vc2010/ -lfreetype247MT_D
|
||||
|
||||
INCLUDEPATH += $$(LibsPath)/freetype-2.4.7/include
|
||||
DEPENDPATH += $$(LibsPath)/freetype-2.4.7/include
|
||||
|
||||
|
||||
win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$(LibsPath)/freetype-2.4.7/objs/win32/vc2010/freetype247MT.lib
|
||||
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$(LibsPath)/freetype-2.4.7/objs/win32/vc2010/freetype247MT_D.lib
|
318
FreeTypeWorker/freetypemodel.cpp
Normal file
318
FreeTypeWorker/freetypemodel.cpp
Normal file
@ -0,0 +1,318 @@
|
||||
#include "freetypemodel.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
|
||||
TFreeTypeModel::TFreeTypeModel(QObject *parent) :
|
||||
QObject(parent)
|
||||
, FontFileName("")
|
||||
{
|
||||
fontColor = Qt::white;
|
||||
backgroundColor = Qt::transparent;
|
||||
|
||||
fontInited = false;
|
||||
|
||||
}
|
||||
|
||||
TFreeTypeModel::~TFreeTypeModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TFreeTypeModel::SetMainWindow(MainWindow* aMainWindow)
|
||||
{
|
||||
mainWindow = aMainWindow;
|
||||
}
|
||||
|
||||
|
||||
void TFreeTypeModel::ClearFontParamText()
|
||||
{
|
||||
fontParamText.clear();
|
||||
}
|
||||
|
||||
QColor TFreeTypeModel::GetBackgroundColor()
|
||||
{
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
QColor TFreeTypeModel::GetFontColor()
|
||||
{
|
||||
return fontColor;
|
||||
}
|
||||
|
||||
void TFreeTypeModel::RenderFontSlot()
|
||||
{
|
||||
ProcessFont();
|
||||
}
|
||||
|
||||
void TFreeTypeModel::LoadFont()
|
||||
{
|
||||
|
||||
QFileDialog dialog(mainWindow);
|
||||
|
||||
dialog.setNameFilter(tr("TTF (*.ttf)"));
|
||||
|
||||
dialog.setFileMode(QFileDialog::ExistingFile);
|
||||
|
||||
if (dialog.exec())
|
||||
{
|
||||
FontFileName = (dialog.selectedFiles())[0];
|
||||
|
||||
QFileInfo fileInfo(FontFileName);
|
||||
|
||||
emit SetFontNameTextSignal(fileInfo.fileName());
|
||||
//emit SetFontNameTextSignal(FontFileName);
|
||||
|
||||
LoadFontFile();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void TFreeTypeModel::SaveFont()
|
||||
{
|
||||
QFileDialog dialog(mainWindow);
|
||||
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
|
||||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
if (dialog.exec())
|
||||
{
|
||||
QString str = (dialog.selectedFiles())[0];
|
||||
mainWindow->Pixmap->save(str + ".png", "PNG");
|
||||
mainWindow->SaveOutputEdit(fontParamText, str + ".txt");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void TFreeTypeModel::SelectBackgroundColorPressed()
|
||||
{
|
||||
QColorDialog dialog(mainWindow);
|
||||
|
||||
dialog.setOption(QColorDialog::ShowAlphaChannel);
|
||||
|
||||
if (dialog.exec())
|
||||
{
|
||||
backgroundColor = dialog.currentColor();
|
||||
mainWindow->RefreshColorMarkers();
|
||||
}
|
||||
}
|
||||
|
||||
void TFreeTypeModel::SelectFontColorPressed()
|
||||
{
|
||||
QColorDialog dialog(mainWindow);
|
||||
|
||||
dialog.setOption(QColorDialog::ShowAlphaChannel);
|
||||
|
||||
if (dialog.exec())
|
||||
{
|
||||
fontColor = dialog.currentColor();
|
||||
mainWindow->RefreshColorMarkers();
|
||||
}
|
||||
}
|
||||
|
||||
void TFreeTypeModel::LoadFontFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (fontInited)
|
||||
{
|
||||
DestroyFontFile();
|
||||
}
|
||||
|
||||
int error = FT_Init_FreeType(&FreeTypeLibrary);
|
||||
|
||||
if (error)
|
||||
{
|
||||
throw QString("FT_Init_FreeType failed");
|
||||
}
|
||||
|
||||
emit SetLoadResultTextSignal("Successful");
|
||||
|
||||
mainWindow->UnlockDrawButton();
|
||||
|
||||
fontInited = true;
|
||||
}
|
||||
catch(QString errorString)
|
||||
{
|
||||
emit SetLoadResultTextSignal(errorString);
|
||||
}
|
||||
}
|
||||
|
||||
void TFreeTypeModel::DestroyFontFile()
|
||||
{
|
||||
FT_Done_FreeType(FreeTypeLibrary);
|
||||
}
|
||||
|
||||
|
||||
void TFreeTypeModel::ProcessAndDrawSymbol(unsigned long charcode, QImage& img, int& shiftX, int& shiftY)
|
||||
{
|
||||
|
||||
FT_Face face;
|
||||
|
||||
int error = FT_New_Face(FreeTypeLibrary, FontFileName.toAscii(), 0, &face);
|
||||
|
||||
if (error == FT_Err_Unknown_File_Format)
|
||||
{
|
||||
throw QString("FT_New_Face failed: FT_Err_Unknown_File_Format");
|
||||
}
|
||||
else if (error)
|
||||
{
|
||||
throw QString("FT_New_Face failed: other error");
|
||||
}
|
||||
|
||||
//Not in use
|
||||
//int intervalX = mainWindow->GetIntervalX();
|
||||
//int intervalY = mainWindow->GetIntervalY();
|
||||
|
||||
int faceWidth = mainWindow->GetFaceWidth();
|
||||
int faceHeight = mainWindow->GetFaceHeight();
|
||||
|
||||
if (FT_Set_Pixel_Sizes(face, faceWidth, faceHeight))
|
||||
{
|
||||
throw QString("FT_Set_Pixel_Sizes failed");
|
||||
}
|
||||
|
||||
unsigned int glyph_index = FT_Get_Char_Index( face, charcode );
|
||||
|
||||
if (FT_Load_Glyph(face, glyph_index, FT_LOAD_RENDER))
|
||||
{
|
||||
throw QString("FT_Load_Glyph failed");
|
||||
}
|
||||
|
||||
FT_Glyph_Metrics metrics = face->glyph->metrics;
|
||||
|
||||
int internalShiftY = mainWindow->GetFaceHeight() - metrics.horiBearingY / 64;
|
||||
int internalShiftX = metrics.horiBearingX / 64;
|
||||
|
||||
int bitmapWidth = face->glyph->bitmap.width;
|
||||
int bitmapHeight = face->glyph->bitmap.rows;
|
||||
|
||||
int oldShiftX = shiftX;
|
||||
int oldShiftY = shiftY;
|
||||
|
||||
int advance = face->glyph->advance.x / 64;
|
||||
|
||||
ProcessSymbol(face, charcode, shiftX, shiftY);
|
||||
|
||||
for (int i=0; i<bitmapWidth; i++)
|
||||
{
|
||||
for (int j=0; j<bitmapHeight; j++)
|
||||
{
|
||||
unsigned char c = face->glyph->bitmap.buffer[(i+j*face->glyph->bitmap.width)];
|
||||
QColor finalColor;
|
||||
|
||||
|
||||
finalColor.setRed(backgroundColor.red()*(1.f - c/255.f) + (fontColor.red()) * (c/255.f));
|
||||
finalColor.setGreen(backgroundColor.green()*(1.f - c/255.f) + (fontColor.green()) * (c/255.f));
|
||||
finalColor.setBlue(backgroundColor.blue()*(1.f - c/255.f) + (fontColor.blue()) * (c/255.f));
|
||||
finalColor.setAlpha(backgroundColor.alpha()*(1.f - c/255.f) + (fontColor.alpha()) * (c/255.f));
|
||||
|
||||
img.setPixel(i+oldShiftX,
|
||||
j+oldShiftY+internalShiftY,
|
||||
finalColor.rgba());
|
||||
}
|
||||
}
|
||||
|
||||
float areaWidth = mainWindow->GetAreaWidth();
|
||||
float areaHeight = mainWindow->GetAreaHeight();
|
||||
|
||||
QString qstr = QString::number(charcode) + " "
|
||||
+ QString::number(oldShiftX / areaWidth) + " "
|
||||
+ QString::number(oldShiftY / areaHeight) + " "
|
||||
+ QString::number(internalShiftX / areaWidth) + " "
|
||||
+ QString::number(internalShiftY / areaHeight) + " "
|
||||
+ QString::number(bitmapWidth / areaWidth) + " "
|
||||
+ QString::number(bitmapHeight / areaHeight) + " "
|
||||
+ QString::number(advance / areaWidth);
|
||||
|
||||
|
||||
fontParamText.push_back(qstr);
|
||||
|
||||
FT_Done_Face(face);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TFreeTypeModel::ProcessSymbol(FT_Face& face, unsigned long charcode, int& shiftX, int& shiftY)
|
||||
{
|
||||
|
||||
int intervalX = mainWindow->GetIntervalX();
|
||||
int intervalY = mainWindow->GetIntervalY();
|
||||
|
||||
int faceWidth = mainWindow->GetFaceWidth();
|
||||
int faceHeight = mainWindow->GetFaceHeight();
|
||||
|
||||
int error = FT_Set_Pixel_Sizes(face, faceWidth, faceHeight);
|
||||
|
||||
if (error)
|
||||
{
|
||||
throw QString("FT_Set_Pixel_Sizes failed");
|
||||
}
|
||||
|
||||
unsigned int glyph_index = FT_Get_Char_Index(face, charcode);
|
||||
|
||||
|
||||
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_RENDER);
|
||||
|
||||
|
||||
if (error)
|
||||
{
|
||||
throw QString("FT_Set_Pixel_Sizes failed");
|
||||
}
|
||||
|
||||
int bitmapWidth = face->glyph->bitmap.width;
|
||||
|
||||
if (shiftX + 2*(bitmapWidth + intervalX)+intervalX >= mainWindow->GetAreaWidth())
|
||||
{
|
||||
shiftX = intervalX;
|
||||
shiftY += mainWindow->GetFaceHeight() + intervalY;
|
||||
}
|
||||
else
|
||||
{
|
||||
shiftX += bitmapWidth + intervalX;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TFreeTypeModel::ProcessFont()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
mainWindow->RefreshSheetHeightWidth();
|
||||
|
||||
QImage img(mainWindow->GetAreaWidth(), mainWindow->GetAreaHeight(), QImage::Format_ARGB32);
|
||||
|
||||
img.fill(backgroundColor.rgba());
|
||||
|
||||
int intervalX = mainWindow->GetIntervalX();
|
||||
int intervalY = mainWindow->GetIntervalY();
|
||||
|
||||
int shiftX = intervalX;
|
||||
int shiftY = intervalY;
|
||||
|
||||
QString str = mainWindow->GetSymbolList();
|
||||
|
||||
|
||||
ClearFontParamText();
|
||||
|
||||
|
||||
for (int i=0; i<str.count(); i++)
|
||||
{
|
||||
unsigned long ch = str[i].unicode();
|
||||
ProcessAndDrawSymbol(ch, img, shiftX, shiftY);
|
||||
}
|
||||
|
||||
//mainWindow->Pixmap->convertFromImage(img, Qt::DiffuseAlphaDither);
|
||||
mainWindow->Pixmap->convertFromImage(img/*, Qt::DiffuseAlphaDither*/);
|
||||
|
||||
emit InvalidateSignal();
|
||||
emit SetLoadResultTextSignal("Successful");
|
||||
|
||||
mainWindow->UnlockSaveButton();
|
||||
}
|
||||
catch(QString errorString)
|
||||
{
|
||||
emit SetLoadResultTextSignal(errorString);
|
||||
}
|
||||
}
|
65
FreeTypeWorker/freetypemodel.h
Normal file
65
FreeTypeWorker/freetypemodel.h
Normal file
@ -0,0 +1,65 @@
|
||||
#ifndef FREETYPEMODEL_H
|
||||
#define FREETYPEMODEL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtGui>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_GLYPH_H
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class TFreeTypeModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QString FontFileName;
|
||||
|
||||
MainWindow* mainWindow;
|
||||
|
||||
FT_Library FreeTypeLibrary;
|
||||
|
||||
std::vector<QString> fontParamText;
|
||||
|
||||
QColor backgroundColor;
|
||||
QColor fontColor;
|
||||
|
||||
bool fontInited;
|
||||
|
||||
void LoadFontFile();
|
||||
void DestroyFontFile();
|
||||
|
||||
void ProcessSymbol(FT_Face& face, unsigned long charcode, int& shiftX, int& shiftY);
|
||||
void ProcessAndDrawSymbol(unsigned long charcode, QImage& img, int& shiftX, int& shiftY);
|
||||
|
||||
void ProcessFont();
|
||||
|
||||
public:
|
||||
explicit TFreeTypeModel(QObject *parent = 0);
|
||||
|
||||
~TFreeTypeModel();
|
||||
|
||||
void SetMainWindow(MainWindow* aMainWindow);
|
||||
|
||||
void ClearFontParamText();
|
||||
|
||||
QColor GetBackgroundColor();
|
||||
QColor GetFontColor();
|
||||
|
||||
signals:
|
||||
void SetFontNameTextSignal(QString text);
|
||||
void SetLoadResultTextSignal(QString text);
|
||||
void InvalidateSignal();
|
||||
//void AddRowToOutputTextSignal(QString text);
|
||||
|
||||
public slots:
|
||||
void LoadFont();
|
||||
void RenderFontSlot();
|
||||
void SaveFont();
|
||||
|
||||
void SelectBackgroundColorPressed();
|
||||
void SelectFontColorPressed();
|
||||
};
|
||||
|
||||
#endif // FREETYPEMODEL_H
|
22
FreeTypeWorker/main.cpp
Normal file
22
FreeTypeWorker/main.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include "mainwindow.h"
|
||||
#include "freetypemodel.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
TFreeTypeModel FreeTypeModel;
|
||||
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
w.SetFreeTypeModel(&FreeTypeModel);
|
||||
FreeTypeModel.SetMainWindow(&w);
|
||||
|
||||
QObject::connect(&FreeTypeModel, SIGNAL(SetFontNameTextSignal(QString)), &w, SLOT(SetFontNameTextSlot(QString)));
|
||||
QObject::connect(&FreeTypeModel, SIGNAL(SetLoadResultTextSignal(QString)), &w, SLOT(SetLoadResultTextSlot(QString)));
|
||||
QObject::connect(&FreeTypeModel, SIGNAL(InvalidateSignal()), &w, SLOT(InvalidatePixmap()));
|
||||
|
||||
|
||||
return a.exec();
|
||||
}
|
148
FreeTypeWorker/mainwindow.cpp
Normal file
148
FreeTypeWorker/mainwindow.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
Pixmap = new QPixmap(128, 128);
|
||||
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete Pixmap;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::SetFreeTypeModel(TFreeTypeModel* freeTypeModel)
|
||||
{
|
||||
FreeTypeModel = freeTypeModel;
|
||||
|
||||
//Set signals
|
||||
QObject::connect(ui->LoadFontButton, SIGNAL(pressed()), FreeTypeModel, SLOT(LoadFont()));
|
||||
QObject::connect(ui->RenderImageButton, SIGNAL(pressed()), FreeTypeModel, SLOT(RenderFontSlot()));
|
||||
QObject::connect(ui->SaveButton, SIGNAL(pressed()), FreeTypeModel, SLOT(SaveFont()));
|
||||
|
||||
QObject::connect(ui->selectBackgroundColor, SIGNAL(pressed()), FreeTypeModel, SLOT(SelectBackgroundColorPressed()));
|
||||
|
||||
QObject::connect(ui->selectFontColor, SIGNAL(pressed()), FreeTypeModel, SLOT(SelectFontColorPressed()));
|
||||
|
||||
|
||||
RefreshColorMarkers();
|
||||
}
|
||||
|
||||
void MainWindow::SetFontNameTextSlot(QString text)
|
||||
{
|
||||
ui->FontFileNameLabel->setText("File name: "+text);
|
||||
}
|
||||
|
||||
void MainWindow::SetLoadResultTextSlot(QString text)
|
||||
{
|
||||
ui->LoadLibResultLabel->setText("Loading result: "+text);
|
||||
}
|
||||
|
||||
void MainWindow::InvalidatePixmap()
|
||||
{
|
||||
ui->Image->setPixmap(*Pixmap);
|
||||
}
|
||||
|
||||
int MainWindow::GetFaceWidth()
|
||||
{
|
||||
return ui->faceWidthEdit->text().toInt();
|
||||
}
|
||||
|
||||
int MainWindow::GetFaceHeight()
|
||||
{
|
||||
return ui->faceHeightEdit->text().toInt();
|
||||
}
|
||||
|
||||
int MainWindow::GetAreaWidth()
|
||||
{
|
||||
return ui->Image->width();
|
||||
}
|
||||
|
||||
int MainWindow::GetAreaHeight()
|
||||
{
|
||||
return ui->Image->height();
|
||||
}
|
||||
|
||||
int MainWindow::GetIntervalX()
|
||||
{
|
||||
return ui->IntervalXEdit->text().toInt();
|
||||
}
|
||||
|
||||
int MainWindow::GetIntervalY()
|
||||
{
|
||||
return ui->IntervalYEdit->text().toInt();
|
||||
}
|
||||
|
||||
QString MainWindow::GetSymbolList()
|
||||
{
|
||||
return ui->CharList->toPlainText();
|
||||
}
|
||||
|
||||
void MainWindow::RefreshSheetHeightWidth()
|
||||
{
|
||||
int width = (ui->SheetWidthEdit->text()).toInt();
|
||||
int height = (ui->SheetHeightEdit->text()).toInt();
|
||||
|
||||
QRect r(ui->frame->geometry());
|
||||
r.setWidth(width);
|
||||
r.setHeight(height);
|
||||
ui->frame->setGeometry(r);
|
||||
|
||||
r = QRect(ui->Image->geometry());
|
||||
r.setWidth(width);
|
||||
r.setHeight(height);
|
||||
ui->Image->setGeometry(r);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::SaveOutputEdit(std::vector<QString>& fontParamText, QString filename)
|
||||
{
|
||||
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return;
|
||||
|
||||
QTextStream out(&file);
|
||||
for (std::vector<QString>::iterator i = fontParamText.begin(); i != fontParamText.end(); i++)
|
||||
{
|
||||
out << *i<<"\n";
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::UnlockDrawButton()
|
||||
{
|
||||
ui->RenderImageButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::UnlockSaveButton()
|
||||
{
|
||||
ui->SaveButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::RefreshColorMarkers()
|
||||
{
|
||||
QPixmap* colorPixmap = new QPixmap(21,21);
|
||||
|
||||
colorPixmap->fill(FreeTypeModel->GetBackgroundColor());
|
||||
ui->backgroundColorMarker->setPixmap(*colorPixmap);
|
||||
|
||||
colorPixmap->fill(FreeTypeModel->GetFontColor());
|
||||
ui->fontColorMarker->setPixmap(*colorPixmap);
|
||||
|
||||
delete colorPixmap;
|
||||
|
||||
|
||||
//Pixmap also:
|
||||
Pixmap->fill(FreeTypeModel->GetBackgroundColor());
|
||||
|
||||
}
|
||||
|
55
FreeTypeWorker/mainwindow.h
Normal file
55
FreeTypeWorker/mainwindow.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QGraphicsScene>
|
||||
#include "freetypemodel.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QPixmap* Pixmap;
|
||||
|
||||
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
void SetFreeTypeModel(TFreeTypeModel* freeTypeModel);
|
||||
|
||||
int GetFaceWidth();
|
||||
int GetFaceHeight();
|
||||
|
||||
int GetAreaWidth();
|
||||
int GetAreaHeight();
|
||||
|
||||
int GetIntervalX();
|
||||
int GetIntervalY();
|
||||
|
||||
QString GetSymbolList();
|
||||
|
||||
void RefreshSheetHeightWidth();
|
||||
|
||||
void SaveOutputEdit(std::vector<QString>& fontParamText, QString filename);
|
||||
|
||||
void UnlockDrawButton();
|
||||
void UnlockSaveButton();
|
||||
|
||||
void RefreshColorMarkers();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
TFreeTypeModel* FreeTypeModel;
|
||||
|
||||
public slots:
|
||||
void SetFontNameTextSlot(QString text);
|
||||
void SetLoadResultTextSlot(QString text);
|
||||
void InvalidatePixmap();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
471
FreeTypeWorker/mainwindow.ui
Normal file
471
FreeTypeWorker/mainwindow.ui
Normal file
@ -0,0 +1,471 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>540</width>
|
||||
<height>540</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>540</width>
|
||||
<height>540</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>540</width>
|
||||
<height>540</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>FreeTypeWorker</string>
|
||||
</property>
|
||||
<property name="locale">
|
||||
<locale language="English" country="UnitedStates"/>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<widget class="QPushButton" name="LoadFontButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>171</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>1. Load font...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="formLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>40</y>
|
||||
<width>171</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="FontFileNameLabel">
|
||||
<property name="text">
|
||||
<string>File name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="LoadLibResultLabel">
|
||||
<property name="text">
|
||||
<string>Loading result:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="CharList">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>190</x>
|
||||
<y>40</y>
|
||||
<width>341</width>
|
||||
<height>71</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;"> 1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,:;@#$%^&amp;*!?()[]{}&lt;&gt;_-+=|\/~`&quot;'</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>190</x>
|
||||
<y>20</y>
|
||||
<width>101</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Symbols to draw:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="faceWidthEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>120</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>32</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="faceHeightEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>430</x>
|
||||
<y>120</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>32</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>190</x>
|
||||
<y>120</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Face width:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="RenderImageButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>130</y>
|
||||
<width>171</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>2. Draw</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>190</x>
|
||||
<y>150</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>X spacing:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="IntervalXEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>150</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>5</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="IntervalYEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>430</x>
|
||||
<y>150</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>5</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>230</y>
|
||||
<width>512</width>
|
||||
<height>256</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<widget class="QLabel" name="Image">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>512</width>
|
||||
<height>256</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="midLineWidth">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="SaveButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>160</y>
|
||||
<width>171</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>3. Save...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="SheetHeightEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>430</x>
|
||||
<y>180</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>256</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>180</x>
|
||||
<y>180</y>
|
||||
<width>81</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sheet width:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="SheetWidthEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>180</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>512</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>340</x>
|
||||
<y>180</y>
|
||||
<width>81</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sheet height:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>350</x>
|
||||
<y>150</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Y spacing:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>350</x>
|
||||
<y>120</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Face height:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="selectBackgroundColor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>214</x>
|
||||
<y>200</y>
|
||||
<width>121</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Background color...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="selectFontColor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>380</x>
|
||||
<y>200</y>
|
||||
<width>121</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Font color...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="backgroundColorMarker">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>340</x>
|
||||
<y>200</y>
|
||||
<width>21</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="fontColorMarker">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>510</x>
|
||||
<y>200</y>
|
||||
<width>21</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<zorder>frame</zorder>
|
||||
<zorder>LoadFontButton</zorder>
|
||||
<zorder>formLayoutWidget</zorder>
|
||||
<zorder>CharList</zorder>
|
||||
<zorder>label_7</zorder>
|
||||
<zorder>faceWidthEdit</zorder>
|
||||
<zorder>faceHeightEdit</zorder>
|
||||
<zorder>label_8</zorder>
|
||||
<zorder>RenderImageButton</zorder>
|
||||
<zorder>label_10</zorder>
|
||||
<zorder>IntervalXEdit</zorder>
|
||||
<zorder>IntervalYEdit</zorder>
|
||||
<zorder>SaveButton</zorder>
|
||||
<zorder>SheetHeightEdit</zorder>
|
||||
<zorder>label_12</zorder>
|
||||
<zorder>SheetWidthEdit</zorder>
|
||||
<zorder>label_13</zorder>
|
||||
<zorder>label_11</zorder>
|
||||
<zorder>label_9</zorder>
|
||||
<zorder>selectBackgroundColor</zorder>
|
||||
<zorder>selectFontColor</zorder>
|
||||
<zorder>backgroundColorMarker</zorder>
|
||||
<zorder>fontColorMarker</zorder>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>540</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
47
K-observer_client_qt/CustomButton.h
Normal file
47
K-observer_client_qt/CustomButton.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef CUSTOMBUTTON_H
|
||||
#define CUSTOMBUTTON_H
|
||||
|
||||
#include <QtGui/QtGui>
|
||||
|
||||
#include "observerclientmodel.h"
|
||||
|
||||
class TCustomButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
explicit TCustomButton(QWidget *parent=0)
|
||||
: QPushButton(parent)
|
||||
{
|
||||
}
|
||||
|
||||
explicit TCustomButton(const QString &text, QWidget *parent=0)
|
||||
: QPushButton(text, parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//TObserverClientModel* ObserverClientModel;
|
||||
|
||||
boost::function<void()> PressedHandler;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void mouseReleaseEvent ( QMouseEvent * e )
|
||||
{
|
||||
QAbstractButton::mouseReleaseEvent(e);
|
||||
/*
|
||||
if (ObserverClientModel != NULL)
|
||||
{
|
||||
ObserverClientModel->OnConnectButtonPressed();
|
||||
}*/
|
||||
|
||||
PressedHandler();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // CUSTOMBUTTON_H
|
42
K-observer_client_qt/K-observer_client.pro
Normal file
42
K-observer_client_qt/K-observer_client.pro
Normal file
@ -0,0 +1,42 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-08-22T11:32:24
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
QT += webkit
|
||||
|
||||
CONFIG += no_keywords
|
||||
|
||||
TARGET = K-observer_client
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
../../k_observer/common/UserInfo.cpp \
|
||||
../../k_observer/common/misc.cpp \
|
||||
../../k_observer/common/MessageSender.cpp \
|
||||
observerclientmodel.cpp \
|
||||
../../k_observer/common/ClientSocket.cpp \
|
||||
customtimer.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
../../k_observer/common/UserInfo.h \
|
||||
../../k_observer/common/misc.h \
|
||||
../../k_observer/common/MessageSender.h \
|
||||
observerclientmodel.h \
|
||||
../../k_observer/common/ClientSocket.h \
|
||||
CustomButton.h \
|
||||
customtimer.h
|
||||
|
||||
INCLUDEPATH += C:/Workplace/libs/boost_1_47_0/
|
||||
INCLUDEPATH += ../../k_observer/common/
|
||||
|
||||
LIBS += -LC:/Workplace/libs/boost_1_47_0/boost_windows/libs_engine/debug/
|
||||
LIBS += -LC:/Workplace/libs/boost_1_47_0/boost_windows/libs_engine/release/
|
||||
|
||||
|
||||
|
||||
FORMS += mainwindow.ui
|
BIN
K-observer_client_qt/Release/release/K-observer_client.exe
Normal file
BIN
K-observer_client_qt/Release/release/K-observer_client.exe
Normal file
Binary file not shown.
BIN
K-observer_client_qt/Release/release/QtCore4.dll
Normal file
BIN
K-observer_client_qt/Release/release/QtCore4.dll
Normal file
Binary file not shown.
BIN
K-observer_client_qt/Release/release/QtGui4.dll
Normal file
BIN
K-observer_client_qt/Release/release/QtGui4.dll
Normal file
Binary file not shown.
BIN
K-observer_client_qt/Release/release/QtNetwork4.dll
Normal file
BIN
K-observer_client_qt/Release/release/QtNetwork4.dll
Normal file
Binary file not shown.
BIN
K-observer_client_qt/Release/release/QtWebKit4.dll
Normal file
BIN
K-observer_client_qt/Release/release/QtWebKit4.dll
Normal file
Binary file not shown.
15
K-observer_client_qt/customtimer.cpp
Normal file
15
K-observer_client_qt/customtimer.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "customtimer.h"
|
||||
|
||||
#include "observerclientmodel.h"
|
||||
|
||||
CustomTimer::CustomTimer(QObject *parent)
|
||||
: QTimer(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CustomTimer::timerEvent ( QTimerEvent * e )
|
||||
{
|
||||
|
||||
TimerSignal();
|
||||
}
|
20
K-observer_client_qt/customtimer.h
Normal file
20
K-observer_client_qt/customtimer.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef CUSTOMTIMER_H
|
||||
#define CUSTOMTIMER_H
|
||||
|
||||
#include <QTimer>
|
||||
#include <QTimerEvent>
|
||||
#include "UserInfo.h"
|
||||
class CustomTimer : public QTimer
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CustomTimer(QObject *parent = 0);
|
||||
|
||||
boost::signal<void()> TimerSignal;
|
||||
|
||||
protected:
|
||||
virtual void timerEvent ( QTimerEvent * e );
|
||||
|
||||
};
|
||||
|
||||
#endif // CUSTOMTIMER_H
|
31
K-observer_client_qt/main.cpp
Normal file
31
K-observer_client_qt/main.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "observerclientmodel.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
TObserverClientModel observerClient;
|
||||
|
||||
w.ObserverClientModel = &observerClient;
|
||||
observerClient.MainWindowPtr = &w;
|
||||
|
||||
w.OpenMap();
|
||||
|
||||
w.GetUi()->ConnectButton->PressedHandler = boost::bind(&TObserverClientModel::OnConnectButtonPressed, &observerClient);
|
||||
w.GetUi()->UpdateDataButton->PressedHandler = boost::bind(&TObserverClientModel::OnUpdateInfoButtonPressed, &observerClient);
|
||||
|
||||
|
||||
w.GetUi()->DisconnectButton->PressedHandler = boost::bind(&TObserverClientModel::Finish, &observerClient);
|
||||
|
||||
w.GetUi()->MapTypeButton->PressedHandler = boost::bind(&TObserverClientModel::OnChangeMapTypeButtonPressed, &observerClient);
|
||||
|
||||
w.GetUi()->ChatSendButton->PressedHandler = boost::bind(&TObserverClientModel::OnChatSendClick, &observerClient);
|
||||
|
||||
|
||||
return a.exec();
|
||||
}
|
32
K-observer_client_qt/mainwindow.cpp
Normal file
32
K-observer_client_qt/mainwindow.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QtWebKit>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
//ObserverClientModel->Finish();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::OpenMap()
|
||||
{
|
||||
QUrl url("C:/Workplace/Projects/Qt/K-observer_client/script.html");
|
||||
//QUrl url("../K-observer_client/script.html");
|
||||
//QUrl url("script.html");
|
||||
|
||||
|
||||
ui->webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
|
||||
ui->webView->load(url);
|
||||
|
||||
ui->webView->page()->setContentEditable(true);
|
||||
|
||||
//ui->webView->page()->mainFrame()->evaluateJavaScript("this.AddMarker(37.443195, 55.888869);");
|
||||
}
|
35
K-observer_client_qt/mainwindow.h
Normal file
35
K-observer_client_qt/mainwindow.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class TObserverClientModel;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
|
||||
|
||||
Ui::MainWindow* GetUi()
|
||||
{
|
||||
return ui;
|
||||
}
|
||||
|
||||
void OpenMap();
|
||||
|
||||
TObserverClientModel* ObserverClientModel;
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
462
K-observer_client_qt/mainwindow.ui
Normal file
462
K-observer_client_qt/mainwindow.ui
Normal file
@ -0,0 +1,462 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>646</width>
|
||||
<height>543</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<widget class="TCustomButton" name="ConnectButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>30</y>
|
||||
<width>91</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Подключиться</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="AddressField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>111</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>127.0.0.1</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="LastNameField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>110</y>
|
||||
<width>113</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Иванов</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>90</y>
|
||||
<width>46</width>
|
||||
<height>13</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Фамилия:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>140</y>
|
||||
<width>46</width>
|
||||
<height>13</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Имя:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="FirstNameField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>160</y>
|
||||
<width>113</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Иван</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>190</y>
|
||||
<width>71</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Отчество:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="MiddleNameField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>210</y>
|
||||
<width>113</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Иванович</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>240</y>
|
||||
<width>121</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Контактный телефон:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="PhoneNumberField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>260</y>
|
||||
<width>113</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>1111</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QSpinBox" name="UikSpinBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>310</y>
|
||||
<width>111</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>290</y>
|
||||
<width>121</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Номер УИК:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="StatusComboBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>360</y>
|
||||
<width>131</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Наблюдатель</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Мобильная группа</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>340</y>
|
||||
<width>121</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Статус:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="TCustomButton" name="UpdateDataButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>390</y>
|
||||
<width>131</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Обновить информацию</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWebView" name="webView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>220</x>
|
||||
<y>10</y>
|
||||
<width>401</width>
|
||||
<height>251</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="url">
|
||||
<url>
|
||||
<string>about:blank</string>
|
||||
</url>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QDoubleSpinBox" name="PosXSpinBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>262</x>
|
||||
<y>270</y>
|
||||
<width>81</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.001000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>37.443195000000003</double>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QDoubleSpinBox" name="PosYSpinBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>372</x>
|
||||
<y>270</y>
|
||||
<width>81</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>55.888869000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>242</x>
|
||||
<y>270</y>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>X:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>352</x>
|
||||
<y>270</y>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Y:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="MapStateComboBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>462</x>
|
||||
<y>270</y>
|
||||
<width>151</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Состояние норм</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Состояние тревога</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="AlarmButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>432</x>
|
||||
<y>310</y>
|
||||
<width>181</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Послать сигнал тревоги</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="PortField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>130</x>
|
||||
<y>10</y>
|
||||
<width>61</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>1984</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="TCustomButton" name="DisconnectButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>30</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="TCustomButton" name="MapTypeButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>332</x>
|
||||
<y>300</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Выбрать</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="MapTypeComboBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>230</x>
|
||||
<y>300</y>
|
||||
<width>91</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Общая карта</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Карта тревоги</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="ChatList">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>230</x>
|
||||
<y>340</y>
|
||||
<width>381</width>
|
||||
<height>111</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="ChatTextLine">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>230</x>
|
||||
<y>460</y>
|
||||
<width>301</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="TCustomButton" name="ChatSendButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>540</x>
|
||||
<y>460</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Отправить</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>646</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QWebView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>QtWebKit/QWebView</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>TCustomButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>custombutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
328
K-observer_client_qt/observerclientmodel.cpp
Normal file
328
K-observer_client_qt/observerclientmodel.cpp
Normal file
@ -0,0 +1,328 @@
|
||||
#include "observerclientmodel.h"
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QWebFrame>
|
||||
|
||||
QString
|
||||
ws2qs(const std::wstring& str)
|
||||
{
|
||||
return (QString((const QChar*)str.c_str(), str.length()));
|
||||
}
|
||||
|
||||
// Convert a QString to a wstring
|
||||
std::wstring
|
||||
qs2ws(const QString& str)
|
||||
{
|
||||
return (std::wstring((wchar_t*)str.unicode(), str.length()));
|
||||
}
|
||||
|
||||
|
||||
TObserverClientModel::TObserverClientModel(QObject *parent)
|
||||
: QObject(parent)
|
||||
, MapType(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TObserverClientModel::Start(std::string address, std::string port)
|
||||
{
|
||||
ClientSocket = boost::shared_ptr<TClientSocket>(new TClientSocket(IoService));
|
||||
|
||||
ClientSocket->Open(address, port);
|
||||
|
||||
RestartHeartbeatTimer();
|
||||
RestartMapHeartbeatTimer();
|
||||
|
||||
IoServiceThread = boost::thread(boost::bind(&boost::asio::io_service::run, &IoService));
|
||||
|
||||
ClientSocket->ReceiveMapSignal.connect(boost::bind(&TObserverClientModel::OnReceiveMapUpdate, this, _1));
|
||||
|
||||
ClientSocket->ReceiveAlarmMapSignal.connect(boost::bind(&TObserverClientModel::OnReceiveAlarmMapUpdate, this, _1));
|
||||
|
||||
|
||||
ClientSocket->ReceiveCloseSignal.connect(boost::bind(&TObserverClientModel::OnSocketClosed, this));
|
||||
|
||||
ClientSocket->ReceiveMessageSignal.connect(boost::bind(&TObserverClientModel::OnReceiveChatMessage, this, _1, _2));
|
||||
|
||||
|
||||
|
||||
Timer.TimerSignal.connect(boost::bind(&TObserverClientModel::OnUpdateMapTimer, this));
|
||||
|
||||
Timer.start(1000);
|
||||
}
|
||||
|
||||
void TObserverClientModel::RestartHeartbeatTimer()
|
||||
{
|
||||
HeartbeatTimer = boost::shared_ptr<boost::asio::deadline_timer>(new boost::asio::deadline_timer(IoService, boost::posix_time::seconds(3)));
|
||||
|
||||
HeartbeatTimer->async_wait(boost::bind(&TObserverClientModel::OnHeartbeat, this, boost::asio::placeholders::error));
|
||||
|
||||
}
|
||||
|
||||
void TObserverClientModel::RestartMapHeartbeatTimer()
|
||||
{
|
||||
MapHeartbeatTimer = boost::shared_ptr<boost::asio::deadline_timer>(new boost::asio::deadline_timer(IoService, boost::posix_time::seconds(3)));
|
||||
|
||||
MapHeartbeatTimer->async_wait(boost::bind(&TObserverClientModel::OnMapHeartbeat, this, boost::asio::placeholders::error));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TObserverClientModel::Finish()
|
||||
{
|
||||
Timer.stop();
|
||||
HeartbeatTimer->cancel();
|
||||
MapHeartbeatTimer->cancel();
|
||||
//HeartbeatTimer = boost::shared_ptr<boost::asio::deadline_timer>();
|
||||
//MapHeartbeatTimer = boost::shared_ptr<boost::asio::deadline_timer>();
|
||||
|
||||
ClientSocket->CloseImmediate();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnSocketClosed()
|
||||
{
|
||||
ClientSocket = boost::shared_ptr<TClientSocket>();
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnUpdateMapTimer()
|
||||
{
|
||||
UpdatingMapMutex.lock();
|
||||
|
||||
MainWindowPtr->GetUi()->webView->page()->mainFrame()->evaluateJavaScript("Clear();");
|
||||
|
||||
|
||||
if (MapType == 0)
|
||||
{
|
||||
|
||||
|
||||
for (std::vector<TUserInfo>::iterator i = UserInfoArr.begin(); i != UserInfoArr.end(); ++i)
|
||||
{
|
||||
QString posX = QString::number( i->PosX );
|
||||
QString posY = QString::number( i->PosY );
|
||||
QString mapState = QString::number(i->MapState);
|
||||
|
||||
if (i->PosX != 0.f && i->PosY != 0.f)
|
||||
{
|
||||
MainWindowPtr->GetUi()->webView->page()->mainFrame()->evaluateJavaScript("AddMarker("+posX+", "+posY+", "+ mapState + ");");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (std::vector<TUserInfo>::iterator i = AlarmUserInfoArr.begin(); i != AlarmUserInfoArr.end(); ++i)
|
||||
{
|
||||
QString posX = QString::number( i->PosX );
|
||||
QString posY = QString::number( i->PosY );
|
||||
QString mapState = QString::number(i->MapState);
|
||||
|
||||
|
||||
|
||||
std::wstring Uik = L"ÓÈÊ ¹";
|
||||
std::wstring StateHeader = L"Ñîñòîÿíèå: ";
|
||||
|
||||
QString text = ws2qs(Uik);
|
||||
text = text + QString::number(i->Uik)+"\\n";
|
||||
text = text +QString::fromUtf8(i->LastName.c_str());
|
||||
text = text +"\\n" + QString::fromUtf8(i->FirstName.c_str());
|
||||
text = text + "\\n"+QString::fromUtf8(i->MiddleName.c_str());
|
||||
text = text + "\\n"+QString::fromUtf8(i->PhoneNumber.c_str());
|
||||
text = text + "\\n";
|
||||
text = text +ws2qs(StateHeader);
|
||||
|
||||
std::wstring State;
|
||||
|
||||
if (i->MapState == 2)
|
||||
{
|
||||
State = L"Òðåâîãà";
|
||||
}
|
||||
else if (i->MapState == 2)
|
||||
{
|
||||
State = L"Óäàëåíèå ñ ÓÈÊ";
|
||||
}
|
||||
else if (i->MapState == 3)
|
||||
{
|
||||
State = L"Âáðîñ";
|
||||
}
|
||||
else if (i->MapState == 4)
|
||||
{
|
||||
State = L"Êàðóñåëü";
|
||||
}
|
||||
else if (i->MapState == 5)
|
||||
{
|
||||
State = L"Íàïàäåíèå";
|
||||
}
|
||||
|
||||
text += ws2qs(State);
|
||||
|
||||
if (i->PosX != 0.f && i->PosY != 0.f)
|
||||
{
|
||||
MainWindowPtr->GetUi()->webView->page()->mainFrame()->evaluateJavaScript("AddMarkerWithPopup("+posX+", "+posY+", "+ mapState + ", \"" +text+ "\");");
|
||||
|
||||
//MainWindowPtr->GetUi()->webView->page()->mainFrame()->evaluateJavaScript("AddMarker("+posX+", "+posY+", "+ mapState + ");");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer.start(1000);
|
||||
|
||||
UpdatingMapMutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void TObserverClientModel::OnConnectButtonPressed()
|
||||
{
|
||||
std::string address(MainWindowPtr->GetUi()->AddressField->text().toAscii());
|
||||
std::string port(MainWindowPtr->GetUi()->PortField->text().toAscii());
|
||||
|
||||
Start(address, port);
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnUpdateInfoButtonPressed()
|
||||
{
|
||||
|
||||
std::string lastName(MainWindowPtr->GetUi()->LastNameField->text().toUtf8());
|
||||
std::string firstName(MainWindowPtr->GetUi()->FirstNameField->text().toUtf8());
|
||||
std::string middleName(MainWindowPtr->GetUi()->MiddleNameField->text().toUtf8());
|
||||
|
||||
std::string phoneNumber(MainWindowPtr->GetUi()->PhoneNumberField->text().toUtf8());
|
||||
|
||||
int uik = MainWindowPtr->GetUi()->UikSpinBox->value();
|
||||
|
||||
int status = MainWindowPtr->GetUi()->StatusComboBox->currentIndex();
|
||||
|
||||
float posX = MainWindowPtr->GetUi()->PosXSpinBox->value();
|
||||
float posY = MainWindowPtr->GetUi()->PosYSpinBox->value();
|
||||
|
||||
int mapState = MainWindowPtr->GetUi()->MapStateComboBox->currentIndex();
|
||||
if (status == 1)
|
||||
{
|
||||
mapState = 0;
|
||||
}
|
||||
|
||||
ClientSocket->UserInfo.LastName = lastName;
|
||||
ClientSocket->UserInfo.FirstName = firstName;
|
||||
ClientSocket->UserInfo.MiddleName = middleName;
|
||||
ClientSocket->UserInfo.PhoneNumber = phoneNumber;
|
||||
ClientSocket->UserInfo.Uik = uik;
|
||||
ClientSocket->UserInfo.Status = status;
|
||||
ClientSocket->UserInfo.MapState = mapState;
|
||||
|
||||
ClientSocket->UserInfo.PosX = posX;
|
||||
ClientSocket->UserInfo.PosY = posY;
|
||||
|
||||
ClientSocket->SendUserinfoUpdateThreaded();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TObserverClientModel::OnHeartbeat(const boost::system::error_code& e)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float posX = MainWindowPtr->GetUi()->PosXSpinBox->value();
|
||||
float posY = MainWindowPtr->GetUi()->PosYSpinBox->value();
|
||||
|
||||
int uik = MainWindowPtr->GetUi()->UikSpinBox->value();
|
||||
int status = MainWindowPtr->GetUi()->StatusComboBox->currentIndex();
|
||||
int mapState = MainWindowPtr->GetUi()->MapStateComboBox->currentIndex() + 1;
|
||||
if (status == 1)
|
||||
{
|
||||
mapState = 0;
|
||||
}
|
||||
|
||||
ClientSocket->UserInfo.Uik = uik;
|
||||
ClientSocket->UserInfo.MapState = mapState;
|
||||
|
||||
ClientSocket->UserInfo.PosX = posX;
|
||||
ClientSocket->UserInfo.PosY = posY;
|
||||
|
||||
ClientSocket->SendHeartbeatThreaded();
|
||||
|
||||
RestartHeartbeatTimer();
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnMapHeartbeat(const boost::system::error_code& e)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MapType == 0)
|
||||
{
|
||||
ClientSocket->SendMapQueryThreaded();
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientSocket->SendAlarmMapQueryThreaded();
|
||||
}
|
||||
|
||||
RestartMapHeartbeatTimer();
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnReceiveMapUpdate(std::vector<TUserInfo> userInfoArr)
|
||||
{
|
||||
|
||||
UpdatingMapMutex.lock();
|
||||
|
||||
UserInfoArr = userInfoArr;
|
||||
|
||||
UpdatingMapMutex.unlock();
|
||||
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnReceiveAlarmMapUpdate(std::vector<TUserInfo> userInfoArr)
|
||||
{
|
||||
UpdatingMapMutex.lock();
|
||||
|
||||
AlarmUserInfoArr = userInfoArr;
|
||||
|
||||
UpdatingMapMutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void TObserverClientModel::OnChangeMapTypeButtonPressed()
|
||||
{
|
||||
MapType = MainWindowPtr->GetUi()->MapTypeComboBox->currentIndex();
|
||||
|
||||
if (MapType == 0)
|
||||
{
|
||||
ClientSocket->SendMapQueryThreaded();
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientSocket->SendAlarmMapQueryThreaded();
|
||||
}
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnChatSendClick()
|
||||
{
|
||||
QString msg = MainWindowPtr->GetUi()->ChatTextLine->text();
|
||||
|
||||
ClientSocket->SendMessageThreaded(std::string(msg.toUtf8()));
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnReceiveChatMessage(TUserInfo userInfo, std::string msg)
|
||||
{
|
||||
QString qmsg;
|
||||
|
||||
qmsg += QString::fromUtf8(userInfo.LastName.c_str()) + " ";
|
||||
qmsg += QString::fromUtf8(userInfo.FirstName.c_str()) + " ";
|
||||
qmsg += QString::fromUtf8(userInfo.MiddleName.c_str()) + " ";
|
||||
qmsg += QString::fromUtf8(userInfo.PhoneNumber.c_str()) + " ";
|
||||
qmsg += QString(ws2qs(L"ÓÈÊ ¹")) + QString::number(userInfo.Uik) + ": ";
|
||||
|
||||
|
||||
qmsg += QString::fromUtf8(msg.c_str()) + "\n";
|
||||
|
||||
|
||||
MainWindowPtr->GetUi()->ChatList->insertPlainText(qmsg);
|
||||
|
||||
|
||||
}
|
74
K-observer_client_qt/observerclientmodel.h
Normal file
74
K-observer_client_qt/observerclientmodel.h
Normal file
@ -0,0 +1,74 @@
|
||||
#ifndef OBSERVERCLIENTMODEL_H
|
||||
#define OBSERVERCLIENTMODEL_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "UserInfo.h"
|
||||
#include "misc.h"
|
||||
#include "ClientSocket.h"
|
||||
#include "customtimer.h"
|
||||
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class TObserverClientModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TObserverClientModel(QObject *parent = 0);
|
||||
|
||||
MainWindow* MainWindowPtr;
|
||||
|
||||
boost::shared_ptr<TClientSocket> ClientSocket;
|
||||
|
||||
boost::asio::io_service IoService;
|
||||
|
||||
boost::thread IoServiceThread;
|
||||
|
||||
boost::mutex UpdatingMapMutex;
|
||||
|
||||
std::vector<TUserInfo> UserInfoArr;
|
||||
std::vector<TUserInfo> AlarmUserInfoArr;
|
||||
|
||||
CustomTimer Timer;
|
||||
|
||||
int MapType;
|
||||
|
||||
void Start(std::string address, std::string port);
|
||||
void Finish();
|
||||
|
||||
void OnSocketClosed();
|
||||
|
||||
void RestartHeartbeatTimer();
|
||||
void RestartMapHeartbeatTimer();
|
||||
|
||||
void OnConnectButtonPressed();
|
||||
|
||||
|
||||
|
||||
void OnUpdateInfoButtonPressed();
|
||||
|
||||
void OnChangeMapTypeButtonPressed();
|
||||
|
||||
void OnHeartbeat(const boost::system::error_code& e);
|
||||
void OnMapHeartbeat(const boost::system::error_code& e);
|
||||
|
||||
void OnUpdateMapTimer();
|
||||
void OnReceiveMapUpdate(std::vector<TUserInfo> userInfoArr);
|
||||
void OnReceiveAlarmMapUpdate(std::vector<TUserInfo> userInfoArr);
|
||||
|
||||
void OnChatSendClick();
|
||||
|
||||
void OnReceiveChatMessage(TUserInfo userInfo, std::string msg);
|
||||
|
||||
|
||||
boost::shared_ptr<boost::asio::deadline_timer> HeartbeatTimer;
|
||||
boost::shared_ptr<boost::asio::deadline_timer> MapHeartbeatTimer;
|
||||
|
||||
//signals:
|
||||
|
||||
//public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // OBSERVERCLIENTMODEL_H
|
91
K-observer_client_qt/script.html
Normal file
91
K-observer_client_qt/script.html
Normal file
@ -0,0 +1,91 @@
|
||||
<!DOCTYPE HTML>
|
||||
<title>OpenLayers Simplest Example</title>
|
||||
<div id="demoMap" style="height:220px"></div>
|
||||
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
|
||||
<script>
|
||||
|
||||
|
||||
|
||||
map = new OpenLayers.Map("demoMap");
|
||||
var mapnik = new OpenLayers.Layer.OSM();
|
||||
var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
|
||||
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
|
||||
var position = new OpenLayers.LonLat(37.443195, 55.888869).transform( fromProjection, toProjection);;
|
||||
var zoom = 12;
|
||||
|
||||
map.addLayer(mapnik);
|
||||
map.setCenter(position, zoom);
|
||||
|
||||
var markers = new OpenLayers.Layer.Markers( "Markers" );
|
||||
map.addLayer(markers);
|
||||
|
||||
function AddMarker(x, y, state)
|
||||
{
|
||||
if (state == 0)
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker_mobile.png";
|
||||
}
|
||||
else if (state == 1)
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker_alarm.png";
|
||||
}
|
||||
|
||||
var size = new OpenLayers.Size(21,25);
|
||||
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
|
||||
var icon = new OpenLayers.Icon(marker_addr, size, offset);
|
||||
|
||||
var lon_Lat = new OpenLayers.LonLat(x, y).transform(fromProjection, toProjection);
|
||||
markers.addMarker(new OpenLayers.Marker(lon_Lat, icon));
|
||||
}
|
||||
|
||||
function Clear()
|
||||
{
|
||||
markers.clearMarkers();
|
||||
}
|
||||
|
||||
//AddMarker(37.443195, 55.888869);
|
||||
|
||||
|
||||
function AddMarkerWithPopup(x, y, state, text)
|
||||
{
|
||||
|
||||
if (state == 0)
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker_mobile.png";
|
||||
}
|
||||
else if (state == 1)
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker_alarm.png";
|
||||
}
|
||||
|
||||
var size = new OpenLayers.Size(21,25);
|
||||
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
|
||||
var icon = new OpenLayers.Icon(marker_addr, size, offset);
|
||||
|
||||
var lon_Lat = new OpenLayers.LonLat(x, y).transform(fromProjection, toProjection);
|
||||
|
||||
var marker = new OpenLayers.Marker(lon_Lat, icon);
|
||||
|
||||
marker.events.register('mousedown', marker, function(evt) { alert(text); OpenLayers.Event.stop(evt); });
|
||||
|
||||
markers.addMarker(marker);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user