Ejemplo n.º 1
0
void KeyContainer::registerKeys()
{
	keys[QChar(27)] = new Key(this, 3, 5, QList<QChar>() << 'E' << 'S' << 'C');
	keys["Qt::Key_F1"] = new Key(this, 8, 5, QList<QChar>() << 'F' << '1');
	keys["Qt::Key_F2"] = new Key(this, 11, 5, QList<QChar>() << 'F' << '2');
	keys["Qt::Key_F3"] = new Key(this, 14, 5, QList<QChar>() << 'F' << '3');
	keys["Qt::Key_F4"] = new Key(this, 17, 5, QList<QChar>() << 'F' << '4');
	keys["Qt::Key_F5"] = new Key(this, 21, 5, QList<QChar>() << 'F' << '5');
	keys["Qt::Key_F6"] = new Key(this, 24, 5, QList<QChar>() << 'F' << '6');
	keys["Qt::Key_F7"] = new Key(this, 27, 5, QList<QChar>() << 'F' << '7');
	keys["Qt::Key_F8"] = new Key(this, 30, 5, QList<QChar>() << 'F' << '8');
	keys["Qt::Key_F9"] = new Key(this, 35, 5, QList<QChar>() << 'F' << '9');
	keys["Qt::Key_F10"] = new Key(this, 38, 5, QList<QChar>() << 'F' << '1' << '0');
	keys["Qt::Key_F11"] = new Key(this, 42, 5, QList<QChar>() << 'F' << '1' << '1');
	keys["Qt::Key_F12"] = new Key(this, 46, 5, QList<QChar>() << 'F' << '1' << '2');
	keys.insertMulti("NONE", new Key(this, 52, 5, QList<QChar>() << 'P' << 'R' << 'N'));
	keys.insertMulti("NONE", new Key(this, 56, 5, QList<QChar>() << 'S' << 'C' << 'R'));
	keys.insertMulti("NONE", new Key(this, 60, 5, QList<QChar>() << 'B' << 'R' << 'K'));
	keys.insertMulti("LED", new Key(this, 68, 5, QList<QChar>() << '-'));
	keys.insertMulti("LED", new Key(this, 72, 5, QList<QChar>() << '-'));
	keys.insertMulti("LED", new Key(this, 76, 5, QList<QChar>() << '-'));

	keys["`"] = new Key(this, 3, 8, QList<QChar>() << '`');
	keys["~"] = new Key(this, 3, 8, QList<QChar>() << '~', true);
	keys["1"] = new Key(this, 6, 8, QList<QChar>() << '1');
	keys["!"] = new Key(this, 6, 8, QList<QChar>() << '!', true);
	keys["2"] = new Key(this, 9, 8, QList<QChar>() << '2');
	keys["@"] = new Key(this, 9, 8, QList<QChar>() << '@', true);
	keys["3"] = new Key(this, 12, 8, QList<QChar>() << '3');
	keys["#"] = new Key(this, 12, 8, QList<QChar>() << '#', true);
	keys["4"] = new Key(this, 15, 8, QList<QChar>() << '4');
	keys["$"] = new Key(this, 15, 8, QList<QChar>() << '$', true);
	keys["5"] = new Key(this, 18, 8, QList<QChar>() << '5');
	keys["%"] = new Key(this, 18, 8, QList<QChar>() << '%', true);
	keys["6"] = new Key(this, 21, 8, QList<QChar>() << '6');
	keys["^"] = new Key(this, 21, 8, QList<QChar>() << '^', true);
	keys["7"] = new Key(this, 24, 8, QList<QChar>() << '7');
	keys["&"] = new Key(this, 24, 8, QList<QChar>() << '&', true);
	keys["8"] = new Key(this, 27, 8, QList<QChar>() << '8');
	keys["*"] = new Key(this, 27, 8, QList<QChar>() << '*', true);
	keys["9"] = new Key(this, 30, 8, QList<QChar>() << '9');
	keys["("] = new Key(this, 30, 8, QList<QChar>() << '(', true);
	keys["0"] = new Key(this, 33, 8, QList<QChar>() << '0');
	keys[")"] = new Key(this, 33, 8, QList<QChar>() << ')', true);
	keys["-"] = new Key(this, 36, 8, QList<QChar>() << '-');
	keys["_"] = new Key(this, 36, 8, QList<QChar>() << '_', true);
	keys["="] = new Key(this, 39, 8, QList<QChar>() << '=');
	keys["+"] = new Key(this, 39, 8, QList<QChar>() << '+', true);
	keys["\\"] = new Key(this, 42, 8, QList<QChar>() << '\\');
	keys["|"] = new Key(this, 42, 8, QList<QChar>() << '|', true);
	keys[QChar(8)] = new Key(this, 46, 8, QList<QChar>() << 0x2190 << 0x2500 << 0x2500);
	keys["Qt::Key_Insert"] = new Key(this, 52, 8, QList<QChar>() << 'I' << 'N' << 'S');
	keys["Qt::Key_Home"] = new Key(this, 56, 8, QList<QChar>() << 'H' << 'O' << 'M');
	keys["Qt::Key_PageUp"] = new Key(this, 60, 8, QList<QChar>() << 'P' << 'G' << 'U');
	keys.insertMulti("NONE", new Key(this, 67, 8, QList<QChar>() << 'N'));//Numlock
	keys.insertMulti("/", new Key(this, 70, 8, QList<QChar>() << '/'));
	keys.insertMulti("*", new Key(this, 73, 8, QList<QChar>() << '*'));
	keys.insertMulti("-", new Key(this, 76, 8, QList<QChar>() << '-'));

	keys[QChar(9)] = new Key(this, 3, 10, QList<QChar>() << 'T' << 'A' << 'B');
	keys["q"] = new Key(this, 8, 10, QList<QChar>() << 'q');
	keys["Q"] = new Key(this, 8, 10, QList<QChar>() << 'Q', true);
	keys["w"] = new Key(this, 11, 10, QList<QChar>() << 'w');
	keys["W"] = new Key(this, 11, 10, QList<QChar>() << 'W', true);
	keys["e"] = new Key(this, 14, 10, QList<QChar>() << 'e');
	keys["E"] = new Key(this, 14, 10, QList<QChar>() << 'E', true);
	keys["r"] = new Key(this, 17, 10, QList<QChar>() << 'r');
	keys["R"] = new Key(this, 17, 10, QList<QChar>() << 'R', true);
	keys["t"] = new Key(this, 20, 10, QList<QChar>() << 't');
	keys["T"] = new Key(this, 20, 10, QList<QChar>() << 'T', true);
	keys["y"] = new Key(this, 23, 10, QList<QChar>() << 'y');
	keys["Y"] = new Key(this, 23, 10, QList<QChar>() << 'Y', true);
	keys["u"] = new Key(this, 26, 10, QList<QChar>() << 'u');
	keys["U"] = new Key(this, 26, 10, QList<QChar>() << 'U', true);
	keys["i"] = new Key(this, 29, 10, QList<QChar>() << 'i');
	keys["I"] = new Key(this, 29, 10, QList<QChar>() << 'I', true);
	keys["o"] = new Key(this, 32, 10, QList<QChar>() << 'o');
	keys["O"] = new Key(this, 32, 10, QList<QChar>() << 'O', true);
	keys["p"] = new Key(this, 35, 10, QList<QChar>() << 'p');
	keys["P"] = new Key(this, 35, 10, QList<QChar>() << 'P', true);
	keys["["] = new Key(this, 38, 10, QList<QChar>() << '[');
	keys["{"] = new Key(this, 38, 10, QList<QChar>() << '{', true);
	keys["]"] = new Key(this, 41, 10, QList<QChar>() << ']');
	keys["}"] = new Key(this, 41, 10, QList<QChar>() << '}', true);
	keys.insertMulti(QChar(13), new Key(this, 45, 10,
		QList<QChar>() << 0x2591 << 0x2591 << 0x2591 << 0x2591
		<< 0x2591 << 0x2591 << 0x21B5 << 0x2591
		<< 0x2591 << 0x2591 << 0x2591 << 0x2591,
		false, 4));
	keys.insertMulti(QChar(13), new Key(this, 43, 12, QList<QChar>() << 0x2591 << 0x2591, false, 2));
	keys[QChar(0xFFF2)] = new Key(this, 52, 10, QList<QChar>() << 'D' << 'E' << 'L');
	keys["Qt::Key_End"] = new Key(this, 56, 10, QList<QChar>() << 'E' << 'N' << 'D');
	keys["Qt::Key_PageDown"] = new Key(this, 60, 10, QList<QChar>() << 'P' << 'G' << 'D');
	keys.insertMulti("7", new Key(this, 67, 10, QList<QChar>() << '7'));
	keys.insertMulti("8", new Key(this, 70, 10, QList<QChar>() << '8'));
	keys.insertMulti("9", new Key(this, 73, 10, QList<QChar>() << '9'));
	keys.insertMulti("+", new Key(this, 76, 10, QList<QChar>() << ' ' << '+' << ' ', false, 1));

	keys.insertMulti("NONE", new Key(this, 3, 12, QList<QChar>() << 'C' << 'A' << 'P' << 'S'));
	keys["a"] = new Key(this, 9, 12, QList<QChar>() << 'a');
	keys["A"] = new Key(this, 9, 12, QList<QChar>() << 'A', true);
	keys["s"] = new Key(this, 12, 12, QList<QChar>() << 's');
	keys["S"] = new Key(this, 12, 12, QList<QChar>() << 'S', true);
	keys["d"] = new Key(this, 15, 12, QList<QChar>() << 'd');
	keys["D"] = new Key(this, 15, 12, QList<QChar>() << 'D', true);
	keys["f"] = new Key(this, 18, 12, QList<QChar>() << 'f');
	keys["F"] = new Key(this, 18, 12, QList<QChar>() << 'F', true);
	keys["g"] = new Key(this, 21, 12, QList<QChar>() << 'g');
	keys["G"] = new Key(this, 21, 12, QList<QChar>() << 'G', true);
	keys["h"] = new Key(this, 24, 12, QList<QChar>() << 'h');
	keys["H"] = new Key(this, 24, 12, QList<QChar>() << 'H', true);
	keys["j"] = new Key(this, 27, 12, QList<QChar>() << 'j');
	keys["J"] = new Key(this, 27, 12, QList<QChar>() << 'J', true);
	keys["k"] = new Key(this, 30, 12, QList<QChar>() << 'k');
	keys["K"] = new Key(this, 30, 12, QList<QChar>() << 'K', true);
	keys["l"] = new Key(this, 33, 12, QList<QChar>() << 'l');
	keys["L"] = new Key(this, 33, 12, QList<QChar>() << 'L', true);
	keys[";"] = new Key(this, 36, 12, QList<QChar>() << ';');
	keys[":"] = new Key(this, 36, 12, QList<QChar>() << ':', true);
	keys["'"] = new Key(this, 39, 12, QList<QChar>() << '\'');
	keys["\""] = new Key(this, 39, 12, QList<QChar>() << '"', true);
	keys.insertMulti("4", new Key(this, 67, 12, QList<QChar>() << '4'));
	keys.insertMulti("5", new Key(this, 70, 12, QList<QChar>() << '5'));
	keys.insertMulti("6", new Key(this, 73, 12, QList<QChar>() << '6'));

	keys.insertMulti("SHIFT", new Key(this, 3, 14, QList<QChar>() << 'S' << 'H' << 'I' << 'F' << 'T'));
	keys["z"] = new Key(this, 11, 14, QList<QChar>() << 'z');
	keys["Z"] = new Key(this, 11, 14, QList<QChar>() << 'Z', true);
	keys["x"] = new Key(this, 14, 14, QList<QChar>() << 'x');
	keys["X"] = new Key(this, 14, 14, QList<QChar>() << 'X', true);
	keys["c"] = new Key(this, 17, 14, QList<QChar>() << 'c');
	keys["C"] = new Key(this, 17, 14, QList<QChar>() << 'C', true);
	keys["v"] = new Key(this, 20, 14, QList<QChar>() << 'v');
	keys["V"] = new Key(this, 20, 14, QList<QChar>() << 'V', true);
	keys["b"] = new Key(this, 23, 14, QList<QChar>() << 'b');
	keys["B"] = new Key(this, 23, 14, QList<QChar>() << 'B', true);
	keys["n"] = new Key(this, 26, 14, QList<QChar>() << 'n');
	keys["N"] = new Key(this, 26, 14, QList<QChar>() << 'N', true);
	keys["m"] = new Key(this, 29, 14, QList<QChar>() << 'm');
	keys["M"] = new Key(this, 29, 14, QList<QChar>() << 'M', true);
	keys[","] = new Key(this, 32, 14, QList<QChar>() << ',');
	keys["<"] = new Key(this, 32, 14, QList<QChar>() << '<', true);
	keys["."] = new Key(this, 35, 14, QList<QChar>() << '.');
	keys[">"] = new Key(this, 35, 14, QList<QChar>() << '>', true);
	keys.insertMulti("/", new Key(this, 38, 14, QList<QChar>() << '/'));
	keys["?"] = new Key(this, 38, 14, QList<QChar>() << '?', true);
	keys.insertMulti("SHIFT", new Key(this, 44, 14, QList<QChar>() << 'S' << 'H' << 'I' << 'F' << 'T'));
	keys["Qt::Key_Up"] = new Key(this, 56, 14, QList<QChar>() << '(' << 0x2191 << ')');
	keys.insertMulti("1", new Key(this, 67, 14, QList<QChar>() << '1'));
	keys.insertMulti("2", new Key(this, 70, 14, QList<QChar>() << '2'));
	keys.insertMulti("3", new Key(this, 73, 14, QList<QChar>() << '3'));
	keys.insertMulti(QChar(13), new Key(this, 76, 14, QList<QChar>() << 0x2591 << 0x2591 << 0x2591, false, 1));

	keys.insertMulti("CTRL", new Key(this, 3, 16, QList<QChar>() << 'C' << 'T' << 'R' << 'L'));
	keys.insertMulti("NONE", new Key(this, 8, 16, QList<QChar>() << 'W' << 'I' << 'N'));
	keys.insertMulti("ALT", new Key(this, 12, 16, QList<QChar>() << 'A' << 'L' << 'T'));
	keys[" "] = new Key(this, 16, 16, QList<QChar>()
		<< ' ' << ' ' << ' ' << ' ' << ' '
		<< 'S' << 'P' << 'A' << 'C' << 'E'
		<< ' ' << ' ' << ' ' << ' ' << ' ' );
	keys.insertMulti("ALT", new Key(this, 32, 16, QList<QChar>() << 'A' << 'L' << 'T'));
	keys.insertMulti("NONE", new Key(this, 36, 16, QList<QChar>() << 'W' << 'I' << 'N'));
	keys.insertMulti("NONE", new Key(this, 40, 16, QList<QChar>() << 'P' << 'R' << 'O' << 'P'));
	keys.insertMulti("CTRL", new Key(this, 45, 16, QList<QChar>() << 'C' << 'T' << 'R' << 'L'));
	keys["Qt::Key_Left"] = new Key(this, 52, 16, QList<QChar>() << '(' << 0x2190 << ')');
	keys["Qt::Key_Down"] = new Key(this, 56, 16, QList<QChar>() << '(' << 0x2193 << ')');
	keys["Qt::Key_Right"] = new Key(this, 60, 16, QList<QChar>() << '(' << 0x2192 << ')');
	keys.insertMulti("0", new Key(this, 67, 16, QList<QChar>() << ' ' << '0' << ' ' << ' '));
	keys.insertMulti(".", new Key(this, 73, 16, QList<QChar>() << '.'));
}
Ejemplo n.º 2
0
int WpaGui::openCtrlConnection(const char *ifname)
{
	char *cfile;
	int flen;
	char buf[2048], *pos, *pos2;
	size_t len;

	if (ifname) {
		if (ifname != ctrl_iface) {
			free(ctrl_iface);
			ctrl_iface = strdup(ifname);
		}
	} else {
#ifdef CONFIG_CTRL_IFACE_UDP
		free(ctrl_iface);
		ctrl_iface = strdup("udp");
#endif /* CONFIG_CTRL_IFACE_UDP */
#ifdef CONFIG_CTRL_IFACE_UNIX
		struct dirent *dent;
		DIR *dir = opendir(ctrl_iface_dir);
		free(ctrl_iface);
		ctrl_iface = NULL;
		if (dir) {
			while ((dent = readdir(dir))) {
#ifdef _DIRENT_HAVE_D_TYPE
				/* Skip the file if it is not a socket.
				 * Also accept DT_UNKNOWN (0) in case
				 * the C library or underlying file
				 * system does not support d_type. */
				if (dent->d_type != DT_SOCK &&
				    dent->d_type != DT_UNKNOWN)
					continue;
#endif /* _DIRENT_HAVE_D_TYPE */

				if (strcmp(dent->d_name, ".") == 0 ||
				    strcmp(dent->d_name, "..") == 0)
					continue;
				printf("Selected interface '%s'\n",
				       dent->d_name);
				ctrl_iface = strdup(dent->d_name);
				break;
			}
			closedir(dir);
		}
#endif /* CONFIG_CTRL_IFACE_UNIX */
#ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
		struct wpa_ctrl *ctrl;
		int ret;

		free(ctrl_iface);
		ctrl_iface = NULL;

		ctrl = wpa_ctrl_open(NULL);
		if (ctrl) {
			len = sizeof(buf) - 1;
			ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf,
					       &len, NULL);
			if (ret >= 0) {
				connectedToService = true;
				buf[len] = '\0';
				pos = strchr(buf, '\n');
				if (pos)
					*pos = '\0';
				ctrl_iface = strdup(buf);
			}
			wpa_ctrl_close(ctrl);
		}
#endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
	}

	if (ctrl_iface == NULL) {
#ifdef CONFIG_NATIVE_WINDOWS
		static bool first = true;
		if (first && !serviceRunning()) {
			first = false;
			if (QMessageBox::warning(
				    this, qAppName(),
				    tr("wpa_supplicant service is not "
				       "running.\n"
				       "Do you want to start it?"),
				    QMessageBox::Yes | QMessageBox::No) ==
			    QMessageBox::Yes)
				startService();
		}
#endif /* CONFIG_NATIVE_WINDOWS */
		return -1;
	}

#ifdef CONFIG_CTRL_IFACE_UNIX
	flen = strlen(ctrl_iface_dir) + strlen(ctrl_iface) + 2;
	cfile = (char *) malloc(flen);
	if (cfile == NULL)
		return -1;
	snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ctrl_iface);
#else /* CONFIG_CTRL_IFACE_UNIX */
	flen = strlen(ctrl_iface) + 1;
	cfile = (char *) malloc(flen);
	if (cfile == NULL)
		return -1;
	snprintf(cfile, flen, "%s", ctrl_iface);
#endif /* CONFIG_CTRL_IFACE_UNIX */

	if (ctrl_conn) {
		wpa_ctrl_close(ctrl_conn);
		ctrl_conn = NULL;
	}

	if (monitor_conn) {
		delete msgNotifier;
		msgNotifier = NULL;
		wpa_ctrl_detach(monitor_conn);
		wpa_ctrl_close(monitor_conn);
		monitor_conn = NULL;
	}

	printf("Trying to connect to '%s'\n", cfile);
	ctrl_conn = wpa_ctrl_open(cfile);
	if (ctrl_conn == NULL) {
		free(cfile);
		return -1;
	}
	monitor_conn = wpa_ctrl_open(cfile);
	free(cfile);
	if (monitor_conn == NULL) {
		wpa_ctrl_close(ctrl_conn);
		return -1;
	}
	if (wpa_ctrl_attach(monitor_conn)) {
		printf("Failed to attach to wpa_supplicant\n");
		wpa_ctrl_close(monitor_conn);
		monitor_conn = NULL;
		wpa_ctrl_close(ctrl_conn);
		ctrl_conn = NULL;
		return -1;
	}

#if defined(CONFIG_CTRL_IFACE_UNIX) || defined(CONFIG_CTRL_IFACE_UDP)
	msgNotifier = new QSocketNotifier(wpa_ctrl_get_fd(monitor_conn),
					  QSocketNotifier::Read, this);
	connect(msgNotifier, SIGNAL(activated(int)), SLOT(receiveMsgs()));
#endif

	adapterSelect->clear();
	adapterSelect->addItem(ctrl_iface);
	adapterSelect->setCurrentIndex(0);

	len = sizeof(buf) - 1;
	if (wpa_ctrl_request(ctrl_conn, "INTERFACES", 10, buf, &len, NULL) >=
	    0) {
		buf[len] = '\0';
		pos = buf;
		while (*pos) {
			pos2 = strchr(pos, '\n');
			if (pos2)
				*pos2 = '\0';
			if (strcmp(pos, ctrl_iface) != 0)
				adapterSelect->addItem(pos);
			if (pos2)
				pos = pos2 + 1;
			else
				break;
		}
	}

	len = sizeof(buf) - 1;
	if (wpa_ctrl_request(ctrl_conn, "GET_CAPABILITY eap", 18, buf, &len,
			     NULL) >= 0) {
		buf[len] = '\0';

		QString res(buf);
		QStringList types = res.split(QChar(' '));
		bool wps = types.contains("WSC");
		actionWPS->setEnabled(wps);
		wpsTab->setEnabled(wps);
		wpaguiTab->setTabEnabled(wpaguiTab->indexOf(wpsTab), wps);
	}

	return 0;
}
Ejemplo n.º 3
0
void Database_Terrain::on_leName_textChanged(QString text)
{
	if (!ignoreEvents)
	{
		int currentRow = twTerrainList->currentRow();
		ignoreEvents = true;
		twTerrainList->item(currentRow, 0)->setText(QString("%1: %2").arg(currentRow, 4, 10, QChar('0')).arg(text));
		ProjectData::terrainNames[currentRow] = text;
		(*terrainRef)->setName(text);
		ignoreEvents = false;
	}
}
Ejemplo n.º 4
0
void SpectrumAnalyser::calculate(const QByteArray &buffer,
                         const QAudioFormat &format)
{
    // QThread::currentThread is marked 'for internal use only', but
    // we're only using it for debug output here, so it's probably OK :)
    SPECTRUMANALYSER_DEBUG << "SpectrumAnalyser::calculate"
                           << QThread::currentThread()
                           << "state" << m_state;

    if (isReady()) {
        Q_ASSERT(isPCMS16LE(format));

        const int bytesPerSample = format.sampleSize() * format.channelCount() / 8;

#ifdef DUMP_SPECTRUMANALYSER
        m_count++;
        const QString pcmFileName = m_outputDir.filePath(QString("spectrum_%1.pcm").arg(m_count, 4, 10, QChar('0')));
        QFile pcmFile(pcmFileName);
        pcmFile.open(QIODevice::WriteOnly);
        const int bufferLength = m_numSamples * bytesPerSample;
        pcmFile.write(buffer, bufferLength);

        m_textStream << "TimeDomain " << m_count << "\n";
        const qint16* input = reinterpret_cast<const qint16*>(buffer);
        for (int i=0; i<m_numSamples; ++i) {
            m_textStream << i << "\t" << *input << "\n";
            input += format.channels();
        }
#endif

        m_state = Busy;

        // Invoke SpectrumAnalyserThread::calculateSpectrum using QMetaObject.  If
        // m_thread is in a different thread from the current thread, the
        // calculation will be done in the child thread.
        // Once the calculation is finished, a calculationChanged signal will be
        // emitted by m_thread.
        const bool b = QMetaObject::invokeMethod(m_thread, "calculateSpectrum",
                                  Qt::AutoConnection,
                                  Q_ARG(QByteArray, buffer),
                                  Q_ARG(int, format.sampleRate()),
                                  Q_ARG(int, bytesPerSample));
        Q_ASSERT(b);
        Q_UNUSED(b) // suppress warnings in release builds

#ifdef DUMP_SPECTRUMANALYSER
        m_textStream << "FrequencySpectrum " << m_count << "\n";
        FrequencySpectrum::const_iterator x = m_spectrum.begin();
        for (int i=0; i<m_numSamples; ++i, ++x)
            m_textStream << i << "\t"
                         << x->frequency << "\t"
                         << x->amplitude<< "\t"
                         << x->phase << "\n";
#endif
    }
}
Ejemplo n.º 5
0
bool ScriptModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
	if(!index.isValid())
		return false;

	if(role == ActionIdRole)
	{
		mScript->setAction(index.row(), mActionFactory->newActionInstance(value.toString()));

		emit dataChanged(index, index);
		emit scriptEdited();

		return true;
	}

	ActionTools::ActionInstance *actionInstance = mScript->actionAt(index.row());
	if(!actionInstance)
		return false;

	if(role == ActionDataRole)
	{
		actionInstance->copyActionDataFrom(value.value<ActionTools::ActionInstance>());

		emit dataChanged(index, index);
		emit scriptEdited();

		return true;
	}

	if(index.column() == ColumnLabel)
	{
		switch(role)
		{
		case Qt::CheckStateRole:
			mUndoStack->push(new ChangeEnabledCommand(QList<int>() << index.row(), value.toBool(), this));

			emit scriptEdited();
			return true;
		case Qt::EditRole:
			QString lineNumber(QString("%1").arg(index.row() + 1, 3, 10, QChar('0')));
			QString labelString(value.toString());
			QString finalValue;

			if(!labelString.isEmpty() && lineNumber != labelString)
			{
				int labelLine = mScript->labelLine(labelString);
				if(labelLine == -1 || labelLine == index.row())
					finalValue = labelString;
			}

			if(labelString == actionInstance->label() || labelString == lineNumber)
				return true;

			mUndoStack->push(new ChangeLabelCommand(finalValue, index.row(), this));

			emit scriptEdited();
			return true;
		}
	}
	else if(index.column() == ColumnComment)
	{
		if(value.toString() == actionInstance->comment())
			return true;

		mUndoStack->push(new ChangeCommentCommand(value.toString(), index.row(), this));

		emit scriptEdited();
		return true;
	}

	return false;
}
Ejemplo n.º 6
0
QVariant ScriptModel::data(const QModelIndex &index, int role) const
{
	if(!index.isValid())
		return QVariant();

	ActionTools::ActionInstance *actionInstance = mScript->actionAt(index.row());
	if(!actionInstance)
		return QVariant();

	switch(role)
	{
	case ActionDataRole:
		return QVariant::fromValue(*actionInstance);
	case ActionIdRole:
		return actionInstance->definition()->id();
	case Qt::BackgroundRole:
		{
			const QColor &color = actionInstance->color();

			if(color.isValid())
				return QBrush(color);

			return QBrush();
		}
	case Qt::FontRole:
		{
			if(!actionInstance->definition()->worksUnderThisOS())
			{
				QFont font = QApplication::font();

				font.setItalic(true);

				return font;
			}

			return QFont();
		}
	case Qt::ForegroundRole:
		{
			const QColor &color = actionInstance->color();
			if(color.isValid())
			{
				if(color.lightness() < 128)
					return QBrush(Qt::white);
				else
					return QBrush(Qt::black);
			}
			else
			{
				const QPalette &palette = QApplication::palette();

				if(!actionInstance->isEnabled())
					return QBrush(palette.color(QPalette::Disabled, QPalette::WindowText));

				return QBrush();
			}
		}
	}

	switch(index.column())
	{
	case ColumnLabel:
		switch(role)
		{
			case Qt::CheckStateRole:
				return QVariant(actionInstance->isEnabled() ? Qt::Checked : Qt::Unchecked);
			case Qt::DisplayRole:
			{
				QString labelString = actionInstance->label();
				if(!labelString.isNull() && !labelString.isEmpty())
					return labelString;

				return QString("%1").arg(index.row() + 1, 3, 10, QChar('0'));
			}
			case Qt::EditRole:
				return actionInstance->label();
		}
		break;
	case ColumnActionName:
		switch(role)
		{
			case Qt::ToolTipRole:
				return tr("Double-clic to edit the action");
			case Qt::DisplayRole:
				return actionInstance->definition()->name();
			case Qt::DecorationRole:
				return QIcon(actionInstance->definition()->icon());
			case Qt::TextAlignmentRole:
				return Qt::AlignCenter;
		}
		break;
	case ColumnComment:
		switch(role)
		{
			case Qt::DisplayRole:
			case Qt::EditRole:
				return actionInstance->comment();
		}
		break;
	}

	return QVariant();
}
Ejemplo n.º 7
0
void addFont(void) {
    QStringList list;
    list << "Roboto-Thin.ttf" << "Roboto-Regular.ttf" << "Roboto-Medium.ttf" << "Roboto-Light.ttf" << "Roboto-Bold.ttf";
    int fontID(-1);
    bool fontWarningShown(false);
    for (QStringList::const_iterator constIterator = list.constBegin(); constIterator != list.constEnd(); ++constIterator) {
        QFile res(":/fonts/" + *constIterator);
        if (res.open(QIODevice::ReadOnly) == false) {
            if (fontWarningShown == false) {
                QMessageBox::warning(0, "Application", (QString)"Impossible d'ouvrir la police " + QChar(0x00AB) + " Roboto " + QChar(0x00BB) + ".");
                fontWarningShown = true;
            }
        } else {
            fontID = QFontDatabase::addApplicationFontFromData(res.readAll());
            if (fontID == -1 && fontWarningShown == false) {
                QMessageBox::warning(0, "Application", (QString)"Impossible d'ouvrir la police " + QChar(0x00AB) + " Roboto " + QChar(0x00BB) + ".");
                fontWarningShown = true;
            }
        }
    }
}