3 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief appendActionShortcut
5 /// \param action アクションオブジェクト
6 /// \param ks キーシーケンス文字列
8 /// アクションにショートカットキーを追加します。
10 void appendActionShortcut(QAction *action, const QString &ks)
12 QList<QKeySequence> shortcuts = action->shortcuts();
13 shortcuts << QKeySequence(ks);
14 action->setShortcuts(shortcuts);
17 ///////////////////////////////////////////////////////////////////////////////
20 /// \return エンコード文字列を返します。
22 std::string detectCode(const QByteArray &bytes)
24 const quint8 bEscape = 0x1B;
25 const quint8 bAt = 0x40;
26 const quint8 bDollar = 0x24;
27 const quint8 bAnd = 0x26;
28 const quint8 bOpen = 0x28; //'('
29 const quint8 bB = 0x42;
30 const quint8 bD = 0x44;
31 const quint8 bJ = 0x4A;
32 const quint8 bI = 0x49;
34 int len = bytes.size();
35 quint8 b1, b2, b3, b4;
37 for (int i = 0; i < len; i++) {
39 if (b1 <= 0x06 || b1 == 0x7F || b1 == 0xFF) {
45 bool notJapanese = true;
46 for (int i = 0; i < len; i++) {
48 if (b1 == bEscape || 0x80 <= b1) {
57 for (int i = 0; i < len - 2; i++) {
63 if ((b2 == bDollar && b3 == bAt) ||
64 (b2 == bDollar && b3 == bB) ||
65 (b2 == bOpen && (b3 == bB || b3 == bJ)) ||
66 (b2 == bOpen && b3 == bI))
72 if (b2 == bDollar && b3 == bOpen && b4 == bD) {
76 b2 == bAnd && b3 == bAt && b4 == bEscape &&
77 bytes[i + 4] == bDollar && bytes[i + 5] == bB)
88 for (int i = 0; i < len - 1; i++) {
91 if (((0x81 <= b1 && b1 <= 0x9F) || (0xE0 <= b1 && b1 <= 0xFC)) &&
92 ((0x40 <= b2 && b2 <= 0x7E) || (0x80 <= b2 && b2 <= 0xFC)))
98 for (int i = 0; i < len - 1; i++) {
101 if (((0xA1 <= b1 && b1 <= 0xFE) && (0xA1 <= b2 && b2 <= 0xFE)) ||
102 (b1 == 0x8E && (0xA1 <= b2 && b2 <= 0xDF)))
107 else if (i < len - 2) {
109 if (b1 == 0x8F && (0xA1 <= b2 && b2 <= 0xFE) &&
110 (0xA1 <= b3 && b3 <= 0xFE))
117 for (int i = 0; i < len - 1; i++) {
120 if ((0xC0 <= b1 && b1 <= 0xDF) && (0x80 <= b2 && b2 <= 0xBF)) {
124 else if (i < len - 2) {
126 if ((0xE0 <= b1 && b1 <= 0xEF) && (0x80 <= b2 && b2 <= 0xBF) &&
127 (0x80 <= b3 && b3 <= 0xBF))
135 if (euc > sjis && euc > utf8) {
138 else if (sjis > euc && sjis > utf8) {
141 else if (utf8 > euc && utf8 > sjis) {
153 ///////////////////////////////////////////////////////////////////////////////
154 /// \brief fileSizeToString
156 /// \return サイズの文字列表記を返します。
158 QString fileSizeToString(qint64 size)
160 if (size >= 1024 * 1024 * 1024) {
161 return QString("%1GB").arg(int(10 * size / (1024 * 1024 * 1024)) / 10);
163 if (size >= 1024 * 1024) {
164 return QString("%1MB").arg(int(10 * size / (1024 * 1024)) / 10);
167 return QString("%1KB").arg(int(10 * size / (1024)) / 10);
169 return QString("%1B").arg(size);
172 ///////////////////////////////////////////////////////////////////////////////
173 /// \brief reconnectAction
174 /// \param sender 送信元アクション
175 /// \param signal シグナル
176 /// \param reciever 送信先オブジェクト
179 /// シグナルにスロットを再接続します。
181 void reconnectAction(QAction *sender, const char *signal, QObject *reciever, const char *slot)
183 sender->setEnabled(true);
184 sender->disconnect();
185 QObject::connect(sender, signal, reciever, slot);