Example #1
0
void QvisColorGridWidget::mousePressEvent(QMouseEvent* e)
{
  if (e->button() == Qt::RightButton)
  {
    int index = getColorIndex(e->x(), e->y());

    // If a valid color index was returned, select the color.
    if (index != -1)
    {
      // Set the selected color.
      setSelectedColorIndex(index);

      // Emit a signal that allows us to activate a menu.
      int row, column;
      QPoint center(e->x(), e->y());
      getRowColumnFromIndex(currentSelectedColor, row, column);
      emit activateMenu(selectedColor(), row, column, mapToGlobal(center));
    }
  }
}
Example #2
0
BaseWindow::BaseWindow(QWidget *parent)
    : QWidget(parent), ui(new Ui::BaseWindow)
{
    this->setAttribute(Qt::WA_QuitOnClose, false);
    serverCounter = 1;
    ui->setupUi(this);

    QApplication *app = (QApplication*)QApplication::instance();
    this->setWindowTitle(QString("%1 %2 (v%3)").arg(app->organizationName(), app->applicationName(), app->applicationVersion()));

    // Icon
    QIcon ico(":resources/RKnock.ico");
    this->setWindowIcon(ico);

    // Find the config file, does it exist?
#ifdef Q_WS_WIN
    QString fSection;
    QString mSection;
    QString lSection = "Settings.xml";

    if (QSysInfo::windowsVersion() < QSysInfo::WV_2000)
    {
        // All Versions before win2000
        fSection = QDir::currentPath(); // Where we are :)
        mSection = "";
    }
    else if (QSysInfo::windowsVersion() < QSysInfo::WV_VISTA)
    {
        fSection = QDir::homePath();
        mSection = QString("Application Data/%1/%2").arg(app->organizationName(), app->applicationName());
    }
    else
    {
        fSection = QDir::homePath();
        mSection = QString("AppData/Roaming/%1/%2").arg(app->organizationName(), app->applicationName());
    }

    if (mSection.size() == 0)
        this->cfgFileLocation = QString("%1/%2").arg(fSection, lSection);
    else
        this->cfgFileLocation = QString("%1/%2/%3").arg(fSection, mSection, lSection);

    //this->cfgFileLocation = QtDir::homePath().append("\\").append("
#else
    QString path = QString("%1/.%2/%3").arg(QDir::homePath(), app->organizationName(), app->applicationName());
    QString file = QString("%1/Settings.xml").arg(path);

    this->cfgFileLocation = file;
#endif

    if (QFile(this->cfgFileLocation).exists())
        this->loadSettings();

    this->tray = new QSystemTrayIcon(this);
    this->trayMenu = new QMenu(this);
    this->trayServersMenu = new QMenu("Servers", this->trayMenu);

    this->tray->setContextMenu(this->trayMenu);
    this->tray->setIcon(ico);
    this->tray->setVisible(true);

    QAction *subaction = 0;
    QMenu *submenu = 0;

    // Open Dialog
    subaction = this->trayMenu->addAction("Open Configuration Dialog...");
    connect(subaction, SIGNAL(triggered()), this, SLOT(show()));

    subaction = this->trayMenu->addAction("About RKnock...");
    connect(subaction, SIGNAL(triggered()), this, SLOT(showAbout()));

    this->trayMenu->addMenu(trayServersMenu);

    this->trayMenu->addSeparator();
    subaction = this->trayMenu->addAction("Exit...");
    connect(subaction, SIGNAL(triggered()), app, SLOT(quit()));

    connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(activateMenu(QSystemTrayIcon::ActivationReason)));

    this->rebuildActions();
}