Exemple #1
0
OptionWidget::OptionWidget(const QString &title, QWidget *mainWidget, QWidget *parent) : QFrame(parent), mainWidget(mainWidget), isFolded(true) {

    setFrameStyle(QFrame::StyledPanel | QFrame::Raised);

    setMinimumWidth(300);

    moveButton    = new BorderlessToolButton("images/Move.png", this);
    moveButton->setDragging(true);
    connect(moveButton, SIGNAL(dragEvent(QMouseEvent*)), this, SLOT(dragEvent(QMouseEvent*)));

    foldInButton  = new BorderlessToolButton("images/ArrowUp.png", this);
    connect(foldInButton, SIGNAL(clicked()), this, SLOT(toggleFolding()));
    foldOutButton = new BorderlessToolButton("images/ArrowDown.png", this);
    connect(foldOutButton, SIGNAL(clicked()), this, SLOT(toggleFolding()));
    
    closeButton   = new BorderlessToolButton("images/Close.png", this);
    connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));

    QHBoxLayout *controlsLayout = new QHBoxLayout;
    controlsLayout->setMargin(0);
    controlsLayout->setAlignment(Qt::AlignRight | Qt::AlignTop);
    controlsLayout->addWidget(moveButton);
    controlsLayout->addWidget(foldInButton);
    controlsLayout->addWidget(foldOutButton);
    controlsLayout->addWidget(closeButton);

    QWidget *controlsWidget = new QWidget;
    controlsWidget->setLayout(controlsLayout);
    controlsWidget->adjustSize();
    controlsWidget->update();

    QHBoxLayout *titleLayout = new QHBoxLayout;
    titleLayout->setMargin(0);
    titleLayout->addWidget(new QLabel(title));
    titleLayout->addWidget(controlsWidget);

    QWidget *titleWidget = new QWidget;
    titleWidget->setLayout(titleLayout);
    titleWidget->adjustSize();
    titleWidget->update();
    
    separatorLine = new QFrame;
    separatorLine->setFrameShape(QFrame::HLine);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(titleWidget);
    layout->addWidget(separatorLine);
    layout->addWidget(mainWidget);

    toggleFolding();

    layout->update();
    setLayout(layout);
};
void MainWindow::createActions() {
  newAct = new QAction(QIcon(":/images/filenew.png"), tr("&New"), this);
  newAct->setShortcut(tr("Ctrl+N"));
  newAct->setStatusTip(tr("Create a new file"));
  connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));

  closeAct = new QAction(QIcon(":/images/fileclose.png"), tr("&Close"), this);
#ifndef Q_WS_MAC
  closeAct->setShortcut(tr("Ctrl+F4"));
#else
  closeAct->setShortcut(tr("Ctrl+W"));
#endif
  closeAct->setStatusTip(tr("Close the current file"));
  connect(closeAct, SIGNAL(triggered()), this, SLOT(closeFile()));

  openAct = new QAction(QIcon(":/images/fileopen.png"), tr("&Open..."), this);
  openAct->setShortcut(tr("Ctrl+O"));
  openAct->setStatusTip(tr("Open an existing file"));
  connect(openAct, SIGNAL(triggered()), this, SLOT(open()));

  saveAct = new QAction(QIcon(":/images/filesave.png"), tr("&Save"), this);
  saveAct->setShortcut(tr("Ctrl+S"));
  saveAct->setStatusTip(tr("Save the document to disk"));
  connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));

  saveAsAct = new QAction(QIcon(":/images/filesaveas.png"), tr("Save &As..."), this);
  saveAsAct->setStatusTip(tr("Save the document under a new name"));
  connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));

  exitAct = new QAction(QIcon(":/images/fileexit.png"), tr("E&xit"), this);
  exitAct->setShortcut(tr("Ctrl+Q"));
  exitAct->setStatusTip(tr("Exit QSciTE"));
  connect(exitAct, SIGNAL(triggered()), launcher, SLOT(quitApplication()));

  undoAct = new QAction(QIcon(":/images/undo.png"), tr("Undo"), this);
  undoAct->setShortcut(tr("Ctrl+Z"));
  undoAct->setStatusTip(tr("Undo the last action performed."));
  connect(undoAct, SIGNAL(triggered()), this, SLOT(undo()));

  redoAct = new QAction(QIcon(":/images/redo.png"), tr("Redo"), this);
  redoAct->setShortcut(tr("Ctrl+Shift+Z"));
  redoAct->setStatusTip(tr("Redo an action previously undone."));
  connect(redoAct, SIGNAL(triggered()), this, SLOT(redo()));

  cutAct = new QAction(QIcon(":/images/editcut.png"), tr("Cu&t"), this);
  cutAct->setShortcut(tr("Ctrl+X"));
  cutAct->setStatusTip(tr("Cut the current selection's contents to the "
                          "clipboard"));
  connect(cutAct, SIGNAL(triggered()), this, SLOT(editCut()));

  copyAct = new QAction(QIcon(":/images/editcopy.png"), tr("&Copy"), this);
  copyAct->setShortcut(tr("Ctrl+C"));
  copyAct->setStatusTip(tr("Copy the current selection's contents to the "
                           "clipboard"));
  connect(copyAct, SIGNAL(triggered()), this, SLOT(editCopy()));

  pasteAct = new QAction(QIcon(":/images/editpaste.png"), tr("&Paste"), this);
  pasteAct->setShortcut(tr("Ctrl+V"));
  pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
                            "selection"));
  connect(pasteAct, SIGNAL(triggered()), this, SLOT(editPaste()));

  prefsAct = new QAction(QIcon(":/images/configure.png"), tr("P&references"), this);
  // TODO: set shortcut, tip, etc.
  connect(prefsAct, SIGNAL(triggered()), this, SLOT(globalPrefs()));

  fontAct = new QAction(QIcon(":/images/font.png"), tr("&Font"), this);
  //fontAct->setShortcut(tr(""))
  fontAct->setStatusTip(tr("Set the display font."));

  connect(fontAct, SIGNAL(triggered()), this, SLOT(fontDialog()));

  terminalAct = new QAction(QIcon(":/images/terminal.png"), tr("Terminal"), this);
  terminalAct->setStatusTip(tr("Show/hide terminal"));
  connect(terminalAct, SIGNAL(triggered()), this, SLOT(toggleTerminal()));

  textDisplayAct = new QAction(QIcon(":/images/font.png"), tr("Text &Display..."), this);
  connect(textDisplayAct, SIGNAL(triggered()), this, SLOT(textDisplay()));

  aboutAct = new QAction(tr("&About QSciTE"), this);
  aboutAct->setStatusTip(tr("Show QSciTE's About box"));
  connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));

  aboutQtAct = new QAction(tr("About &Qt"), this);
  aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
  connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));

  nextAct = new QAction(QIcon(":/images/nextTab.png"), tr("Forward"), this);
  nextAct->setStatusTip(tr("Change to the next open document"));
  nextAct->setShortcut(tr("Alt+Right"));
  connect(nextAct, SIGNAL(triggered()), this, SLOT(nextDoc()));

  prevAct = new QAction(QIcon(":/images/prevTab.png"), tr("Back"), this);
  prevAct->setStatusTip(tr("Change to the previous open document"));
  prevAct->setShortcut(tr("Alt+Left"));
  connect(prevAct, SIGNAL(triggered()), this, SLOT(prevDoc()));

  cutAct->setEnabled(false);
  copyAct->setEnabled(false);

  convertEndings = new QAction(tr("&Convert Line End Characters"), this);
  connect(convertEndings, SIGNAL(triggered()), this, SLOT(convertEols()));
  lineEndCr = new QAction(tr("&CR (old Macintosh)"), this);
  lineEndCr->setCheckable(true);
  connect(lineEndCr, SIGNAL(triggered()), this, SLOT(setEolCr()));
  lineEndLf = new QAction(tr("&LF (Unix)"), this);
  lineEndLf->setCheckable(true);
  connect(lineEndLf, SIGNAL(triggered()), this, SLOT(setEolLf()));
  lineEndCrLf = new QAction(tr("CR &+ LF (Windows)"), this);
  lineEndCrLf->setCheckable(true);
  connect(lineEndCrLf, SIGNAL(triggered()), this, SLOT(setEolCrLf()));

  lineEnds = new QActionGroup(this);
  lineEnds->addAction(lineEndCr);
  lineEnds->addAction(lineEndLf);
  lineEnds->addAction(lineEndCrLf);
  lineEndLf->setChecked(true);

  showLineEndsAct = new QAction(tr("&Show End of Line"), this);
  showLineEndsAct->setCheckable(true);
  connect(showLineEndsAct, SIGNAL(toggled(bool)), this, SLOT(setEolVisibility(bool)));

  convertIndentAct = new QAction(tr("Convert &Indentation..."), this);
  connect(convertIndentAct, SIGNAL(triggered()), this, SLOT(convertIndentation()));

  codeFoldingAct = new QAction(tr("Use Code Folding"), this);
  codeFoldingAct->setCheckable(true);
  connect(codeFoldingAct, SIGNAL(triggered()), this, SLOT(toggleFolding()));

  findTextAct = new QAction(tr("&Find..."), this);
  findTextAct->setShortcut(tr("Ctrl+F"));
  connect(findTextAct, SIGNAL(triggered()), this, SLOT(showFindDialog()));
  
  replaceTextAct = new QAction(tr("Replace..."), this);
  replaceTextAct->setShortcut(tr("Ctrl+H"));
  connect(replaceTextAct, SIGNAL(triggered()), this, SLOT(showReplaceDialog()));

  //ScriptConsole
  scriptConsoleAct = new QAction(tr("Script Console"), this);
  connect(scriptConsoleAct, SIGNAL(triggered()), this, SLOT(showScriptConsole()));

  newWindowAct = new QAction(QIcon(":/images/newwindow.png"), tr("&New Window"), this);
  connect(newWindowAct, SIGNAL(triggered()), this, SLOT(newWindow()));

  lexers = new QActionGroup(this);
  for (int i = 0; !supportedLexers[i].isEmpty(); ++i) {
    QAction * tmp = new QAction(tr(supportedLexers[i].toStdString().c_str()), this);
    tmp->setCheckable(true);
    connect(tmp, SIGNAL(triggered()), this, SLOT(lexerMenuChanged()));
    lexers->addAction(tmp);
  }
  
}