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))); }
void ComputationalResultsTableView::contextMenuEvent(QContextMenuEvent *e) { MongoDatabase *db = MongoDatabase::instance(); QModelIndex index = indexAt(e->pos()); if (index.isValid()) { mongo::BSONObj *obj = static_cast<mongo::BSONObj *>(index.internalPointer()); QMenu *menu = new QMenu(this); QAction *action; // add view and save log file actions if (obj && obj->hasField("log_file")) { action = menu->addAction("&View Log File", this, SLOT(showLogFile())); action = menu->addAction("&Save Log File", this, SLOT(showLogFile())); } // add open in editor action action = menu->addAction("&Open in Editor"); MoleculeRef ref = db->findMoleculeFromBSONObj(obj); m_openInEditorHandler->setMolecule(ref); connect(action, SIGNAL(triggered()), m_openInEditorHandler, SLOT(openInEditor())); // add details action if (m_enableShowDetailsAction) { action = menu->addAction("Show Molecule &Details", this, SLOT(showMoleculeDetailsDialog())); } m_row = index.row(); menu->exec(QCursor::pos()); } }
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())); }