ExamplesPreview::ExamplesPreview(int engine, QWidget *parent) : QScrollArea(parent) { setWindowFlags(windowFlags() | Qt::ToolTip); setAutoFillBackground(true); setFrameStyle(QFrame::Box | QFrame::Plain); setFixedSize(300, 300); setWidgetResizable(true); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); QWidget *widget = new QWidget(this); widget->setFixedWidth(280); QVBoxLayout *l = new QVBoxLayout(widget); l->setSpacing(0); QPalette p(palette()); p.setColor(QPalette::Window, QColor("#c0daff")); setPalette(p); static const QStringList filters[ENGINE_MAX] = { (QStringList() << "*.js"), (QStringList() << "*.py") }; QDir dir(":/examples"); QStringList files = dir.entryList(filters[engine], QDir::NoFilter, QDir::Name); QFile f; for(int i = 0; i < files.size(); ++i) { f.setFileName(":/examples/" + files[i]); if(!f.open(QIODevice::ReadOnly)) continue; ExamplePreviewItem *prev = new ExamplePreviewItem(files[i], f.readLine(), this); connect(prev, SIGNAL(openInEditor(QString)), SIGNAL(openInEditor(QString))); connect(prev, SIGNAL(openPreview(QString)), SIGNAL(openPreview(QString))); l->addWidget(prev); l->addWidget(getSeparator()); f.close(); } setWidget(widget); connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), SLOT(focusChanged(QWidget*, QWidget*))); }
void ScriptEditor::exampleBtn() { if(m_examples) { delete m_examples.data(); return; } m_examples = new ExamplesPreview(m_language, this); m_examples->move(m_exampleBtn->mapToGlobal(QPoint(0, 0)) + QPoint(0, m_exampleBtn->height())); m_examples->show(); m_examples->setFocus(); connect(m_examples.data(), SIGNAL(destroyed()), SLOT(examplePreviewDestroyed())); connect(m_examples.data(), SIGNAL(openInEditor(QString)), SLOT(loadExample(QString))); connect(m_examples.data(), SIGNAL(openPreview(QString)), SIGNAL(openPreview(QString))); }
ExamplePreviewItem::ExamplePreviewItem(const QString& name, QString line, QWidget *parent) : QFrame(parent) { setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); QFont f; QVBoxLayout *l = new QVBoxLayout(this); QLabel *nameLabel = new QLabel(name.left(name.lastIndexOf('.')), this); f.setBold(true); f.setPointSize(12); nameLabel->setFont(f); line.chop(1); QLabel *lineLabel = new QLabel(line, this); f.setPointSize(9); f.setBold(false); lineLabel->setFont(f); lineLabel->setStyleSheet("color: green;"); lineLabel->setWordWrap(true); QHBoxLayout *linkLayout = new QHBoxLayout; QLabel *linkToEditor = new QLabel(tr("<a href=\"%1\">Load to editor</a>").arg(name), this); QLabel *linkPreview = new QLabel(tr("<a href=\"%1\">Show preview</a>").arg(name), this); linkLayout->addStretch(); linkLayout->addWidget(linkToEditor); linkLayout->addWidget(linkPreview); l->addWidget(nameLabel); l->addWidget(lineLabel); l->addLayout(linkLayout); connect(linkToEditor, SIGNAL(linkActivated(QString)), SIGNAL(openInEditor(QString))); connect(linkPreview, SIGNAL(linkActivated(QString)), SIGNAL(openPreview(QString))); connect(linkToEditor, SIGNAL(linkActivated(QString)), parent, SLOT(deleteLater())); connect(linkPreview, SIGNAL(linkActivated(QString)), parent, SLOT(deleteLater())); }
void FileSharingWidget::mouseReleaseEvent(QMouseEvent *event) { event->ignore(); Ui::HistoryControlPage* page = Utils::InterConnector::instance().getHistoryPage(ContactUin_); if (page && page->touchScrollInProgress()) { return; } const auto isLeftClick = (event->button() == Qt::LeftButton); if (!isLeftClick) { return; } const auto mousePos = event->pos(); const auto clickedOnButton = (isControlButtonVisible() && isOverControlButton(mousePos)); const auto isDownloadButtonClicked = (clickedOnButton && isState(State::PlainFile_MetainfoLoaded)); if (isDownloadButtonClicked) { startDownloadingPlainFile(); return; } const auto isDownloading = (isState(State::PlainFile_Downloading) || isState(State::ImageFile_Downloading)); const auto isStopDownloadButtonClicked = (clickedOnButton && isDownloading); if (isStopDownloadButtonClicked) { stopDownloading(); return; } const auto isUploading = (isState(State::PlainFile_Uploading) || isState(State::ImageFile_Uploading)); const auto isStopUploadButtonClicked = (clickedOnButton && isUploading); if (isStopUploadButtonClicked) { stopUploading(); return; } const auto isOpenDownloadsDirButtonClicked = (isOpenDownloadsDirButtonVisible() && isOverOpenDownloadsDirButton(mousePos)); if (isOpenDownloadsDirButtonClicked) { openDownloadsDir(); return; } const auto fullImageReady = ( isState(State::ImageFile_Downloaded) || isState(State::ImageFile_Uploaded) ); if (fullImageReady && isOverPreview(mousePos)) { if (platform::is_apple()) { openPreviewMac(event->globalX(), event->globalY()); } else { openPreview(); } return; } if (canStartImageDownloading(mousePos)) { setState(State::ImageFile_Downloading); startDownloadingFullImage(); } }
void FileSharingWidget::setState(const State state) { assert(state > State::Min); assert(state < State::Max); assert(Private_.State_ > State::Min); assert(Private_.State_ < State::Max); const auto oldState = Private_.State_; Private_.State_ = state; emit stateChanged(); if ((state == State::PlainFile_Initial) || (state == State::PlainFile_MetainfoLoaded)) { setBlockSizePolicy(); } switch (oldState) { case State::Initial: assert(isState(State::PlainFile_Initial) || isState(State::ImageFile_Initial)); break; case State::PlainFile_Initial: break; case State::PlainFile_CheckingLocalCopy: assert((state == State::PlainFile_MetainfoLoaded) || (state == State::PlainFile_Downloaded)); break; case State::PlainFile_MetainfoLoaded: assert(state == State::PlainFile_Downloading); break; case State::PlainFile_Downloading: assert((state == State::PlainFile_MetainfoLoaded) || (state == State::PlainFile_Downloaded)); break; case State::PlainFile_Uploading: assert(isState(State::PlainFile_Uploaded) || isState(State::PlainFile_UploadError) || isState(State::PlainFile_MetainfoLoaded) || isState(State::Deleted)); break; case State::ImageFile_Initial: { assert(isState(State::ImageFile_MetainfoLoaded) || isState(State::ImageFile_Uploading) || isState(State::ImageFile_Uploaded) || isState(State::ImageFile_Downloading)); } break; case State::ImageFile_MetainfoLoaded: assert(isState(State::PlainFile_MetainfoLoaded) || isState(State::ImageFile_Downloading)); break; case State::ImageFile_Downloading: { const auto isImageDownloaded = isState(State::ImageFile_Downloaded); const auto isImageMetainfoLoaded = isState(State::ImageFile_MetainfoLoaded); if (!isImageDownloaded && !isImageMetainfoLoaded) { assert(false); } if (isImageDownloaded) { if (platform::is_apple()) { openPreviewMac(-1, -1); } else { openPreview(); } } } break; case State::ImageFile_Uploading: assert(isState(State::ImageFile_Uploaded) || isState(State::Deleted)); break; case State::PlainFile_Downloaded: break; default: assert(!"unexpected internal state"); break; } }