tahoma2d/toonz/sources/toonzfarm/tfarmclient/filebrowserpopup.cpp

174 lines
4.7 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "filebrowserpopup.h"
#include "filebrowser.h"
#include "tlevel_io.h"
#include "tw/button.h"
#include "tw/textfield.h"
#include "tw/label.h"
#include "tw/colors.h"
#include "tw/mainshell.h"
#include "tw/message.h"
using namespace TwConsts;
//==============================================================================
2016-06-15 18:43:10 +12:00
class FileBrowserPopup::Data {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Data() : m_okAction(0) {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
FileBrowserPopup *m_popup;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
FileBrowser *m_fileBrowser;
TButton *m_okButton;
TButton *m_cancelButton;
TLabel *m_fileLabel;
TTextField *m_file;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TFilePath m_currentFile;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TGenericFileBrowserPopupAction *m_okAction;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void initPopup(const vector<string> &fileTypes);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void onOk();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void onFileSelChange(const TFilePath &fp) {
m_currentFile = fp;
m_file->setText(fp.withoutParentDir().getWideString());
}
2016-03-19 06:57:51 +13:00
};
// , m_importTrayH(120)
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FileBrowserPopup::Data::initPopup(const vector<string> &fileTypes) {
m_fileBrowser = new FileBrowser(m_popup, "fileBrowser", fileTypes);
m_fileBrowser->setBackgroundColor(Gray240);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_fileBrowser->setFileSelChangeAction(
new FileBrowserAction<FileBrowserPopup::Data>(
this, &FileBrowserPopup::Data::onFileSelChange));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_okButton = new TButton(m_popup, "Ok");
m_cancelButton = new TButton(m_popup, "Cancel");
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
tconnect<TPopup>(*(m_cancelButton), m_popup, &TPopup::close);
tconnect<FileBrowserPopup::Data>(*(m_okButton), this,
&FileBrowserPopup::Data::onOk);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_fileLabel = new TLabel(m_popup, "File");
m_file = new TTextField(m_popup);
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FileBrowserPopup::Data::onOk() {
assert(m_okAction);
string file = toString(m_file->getText());
if (file != "") {
try {
m_okAction->sendCommand(m_fileBrowser->getCurrentDir() + file);
m_popup->close();
} catch (TException &e) {
TMessage::error(toString(e.getMessage()));
}
}
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
FileBrowserPopup::FileBrowserPopup(TWidget *parent)
2016-06-15 18:43:10 +12:00
: TPopup(parent, "fileBrowserPopup"), m_data(new Data()) {
m_data->m_popup = this;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_isMenu = false;
setSize(640, 400);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
vector<string> fileTypes;
TImageReader::getSupportedFormats(fileTypes);
TLevelReader::getSupportedFormats(fileTypes);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_data->initPopup(fileTypes);
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
FileBrowserPopup::FileBrowserPopup(TWidget *parent,
const vector<string> &fileTypes)
: TPopup(parent, "fileBrowserPopup"), m_data(new Data()) {
m_data->m_popup = this;
m_isMenu = false;
setSize(640, 400);
m_data->initPopup(fileTypes);
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
FileBrowserPopup::~FileBrowserPopup() { delete m_data; }
2016-03-19 06:57:51 +13:00
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TDimension FileBrowserPopup::getPreferredSize() const {
return TDimension(640, 400);
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FileBrowserPopup::configureNotify(const TDimension &d) {
int y = 4;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_data->m_fileLabel->setGeometry(10 /*100*/, y, 60 /*150*/, y + 20);
m_data->m_file->setGeometry(65 /*155*/, y, d.lx - 220, y + 20);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_data->m_okButton->setGeometry(d.lx - 200, y, d.lx - 150, y + 20);
m_data->m_cancelButton->setGeometry(d.lx - 130, y, d.lx - 80, y + 20);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
y += 20 + 4;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int x = 200;
// m_importTray->setGeometry(x,y,d.lx-1,y+m_importTrayH-4);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// y = y + (m_importTrayH + 8);
m_data->m_fileBrowser->setGeometry(0, y, d.lx - 1, d.ly - 10);
invalidate();
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FileBrowserPopup::popup(const TPoint &p) {
m_data->m_currentFile = TFilePath();
TPopup::popup(p);
setCaption("File Browser");
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FileBrowserPopup::draw() {
int y = 10 + 20 + 4 /*+ m_importTrayH*/;
setColor(Gray150);
draw3DRect(TRect(TPoint(0, y), TDimension(getSize().lx - 1, 6)));
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FileBrowserPopup::setOkAction(TGenericFileBrowserPopupAction *action) {
m_data->m_okAction = action;
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FileBrowserPopup::setCurrentDir(const TFilePath &dirPath) {
m_data->m_fileBrowser->setCurrentDir(dirPath);
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FileBrowserPopup::setFilter(const vector<string> &fileTypes) {
m_data->m_fileBrowser->setFilter(fileTypes);
2016-03-19 06:57:51 +13:00
}