| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| PalettesScanPopup::PalettesScanPopup() |
| : Dialog(0, true, true, "PalettesScan"), m_folderPath(TFilePath()), m_timerId(0) |
| { |
| setWindowTitle(tr("Search for Palettes")); |
| setFixedWidth(250); |
| |
| m_field = new DVGui::FileField(); |
| addWidget(m_field); |
| |
| m_label = new QLabel(); |
| m_label->setFixedWidth(200); |
| addWidget(m_label); |
| |
| QPushButton *okBtn = new QPushButton(tr("Ok"), this); |
| okBtn->setDefault(true); |
| QPushButton *cancelBtn = new QPushButton(tr("Cancel"), this); |
| connect(okBtn, SIGNAL(clicked()), this, SLOT(onOkBtnClicked())); |
| connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject())); |
| addButtonBarWidget(okBtn, cancelBtn); |
| } |
| |
| |
| |
| |
| void PalettesScanPopup::setCurrentFolder(TFilePath path) |
| { |
| m_folderPath = path; |
| } |
| |
| |
| |
| |
| TFilePath PalettesScanPopup::getCurrentFolder() |
| { |
| return m_folderPath; |
| } |
| |
| |
| |
| |
| |
| void PalettesScanPopup::onOkBtnClicked() |
| { |
| m_timerId = startTimer(3); |
| TFilePathSet fps; |
| std::wstring s = m_field->getPath().toStdWString(); |
| int i = 0, len = s.length(); |
| while (i < len) { |
| while (i < len && (s[i] == ' ' || s[i] == '\t')) |
| i++; |
| if (i >= len) |
| break; |
| int j = i; |
| while (j < len && s[j] != ',') |
| j++; |
| int k = j; |
| while (k > i && (s[k - 1] == ' ' || s[k - 1] == '\t')) |
| k--; |
| std::wstring token = s.substr(i, k - i); |
| fps.push_back(TFilePath(token)); |
| i = j + 1; |
| } |
| push(fps); |
| } |
| |
| |
| |
| |
| void PalettesScanPopup::setLabel(const TFilePath &fp) |
| { |
| QString elideStr = elideText(toQString(fp), m_label->font(), m_label->width()); |
| m_label->setText(elideStr); |
| } |
| |
| |
| |
| |
| |
| void PalettesScanPopup::timerEvent(QTimerEvent *event) |
| { |
| bool ret = step(); |
| if (!ret) { |
| killTimer(m_timerId); |
| clearStack(); |
| QDialog::accept(); |
| } |
| } |
| |
| |
| |
| |
| void PalettesScanPopup::push(const TFilePath &fp) |
| { |
| setLabel(fp); |
| Directory *dir = new Directory(); |
| m_stack.push_back(dir); |
| dir->m_path = fp; |
| dir->m_files = TSystem::readDirectory(fp); |
| dir->m_it = dir->m_files.begin(); |
| } |
| |
| |
| |
| |
| |
| void PalettesScanPopup::push(const TFilePathSet &fs) |
| { |
| m_label->setText(tr("<files>")); |
| Directory *dir = new Directory(); |
| m_stack.push_back(dir); |
| dir->m_path = TFilePath(); |
| dir->m_files = fs; |
| dir->m_it = dir->m_files.begin(); |
| } |
| |
| |
| |
| |
| void PalettesScanPopup::pop() |
| { |
| if (m_stack.empty()) |
| return; |
| Directory *dir = m_stack.back(); |
| delete dir; |
| m_stack.pop_back(); |
| if (!m_stack.empty()) { |
| dir = m_stack.back(); |
| setLabel(dir->m_path); |
| } else |
| m_label->setText(tr("")); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| bool PalettesScanPopup::step() |
| { |
| if (m_stack.empty()) |
| return false; |
| Directory *dir = m_stack.back(); |
| if (dir->m_it == dir->m_files.end()) |
| pop(); |
| else { |
| TFilePath fp = *(dir->m_it)++; |
| if (TFileStatus(fp).isDirectory()) |
| push(fp); |
| else { |
| setLabel(fp); |
| std::string ext = fp.getType(); |
| if (ext == "plt" || ext == "tpl" || ext == "pli") |
| onPlt(fp); |
| } |
| } |
| return true; |
| } |
| |
| |
| |
| |
| void PalettesScanPopup::clearStack() |
| { |
| for (int i = 0; i < (int)m_stack.size(); i++) |
| delete m_stack[i]; |
| m_stack.clear(); |
| m_label->setText(tr("")); |
| } |
| |
| |
| |
| |
| void PalettesScanPopup::onPlt(const TFilePath &fp) |
| { |
| TFilePath root(m_field->getPath().toStdString()); |
| assert(root.isAncestorOf(fp)); |
| TFilePath q = fp.getParentDir() - root; |
| StudioPalette::instance()->importPalette(m_folderPath + q, fp); |
| } |
| |