void AnimationFrame::import() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), QString(), tr("Image Files (*.png *.jpg *.bmp"), 0, QFileDialog::DontUseNativeDialog); QImage img = QImage(fileName); if (!img.isNull()) { if(mModel->getCurrentSize() != img.size() && !mModel->getSprite()->isNull()) { QString error = QString("Image dimensions must match\n") + "Source: " + QString::number(img.size().rwidth()) + "x" + QString::number(img.size().rheight()) +"\n" + "Target: " + QString::number(mModel->getCurrentSize().rwidth()) + "x" + QString::number(mModel->getCurrentSize().rheight()); QMessageBox::critical(this, tr("Error"), error, QMessageBox::Ok); return; } int pos = animator->getCursor(); if (pos == -1) pos = mModel->getSprite()->count(); insertImage(); QModelIndex idx = mModel->index(pos, 0, QModelIndex()); mModel->setData(idx, img, Qt::DecorationRole); } }
void KTextCursor::insertImage( const QString &name, const QString &key ) { QTextImageFormat imageFormat; imageFormat.setName(name); imageFormat.setProperty(KImageKey, key); insertImage(name, imageFormat); }
void KTextCursor::insertImage( const QString & name ) { QTextImageFormat format; format.setName(name); format.setProperty(KImageKey, name); insertImage(name, format); }
bool ImageHandler::insertImage(double x, double y) { XOJ_CHECK_TYPE(ImageHandler); GFile * file = ImageOpenDlg::show((GtkWindow*) *control->getWindow(), control->getSettings()); if(file == NULL) { return false; } return insertImage(file, x, y); }
void RefImage::imageFromFile() { QFile file(imagePath()); if (file.exists()) { QFileInfo fileinfo(imagePath()); QPixmap pixmap; pixmap.load(imagePath(),NULL,Qt::AutoColor); insertImage(pixmap,fileinfo.fileName()); } }
void RefImage::imageFromReply() { if (checkReply(imageReply())) { QPixmap pixmap; pixmap.loadFromData(imageReply()->readAll()); insertImage(pixmap,nameFromUrl(imageReply()->url())); imageReply()->deleteLater(); m_imageReply = NULL; thumbItem()->stopDownload(true); } }
/*! * Insert an object. * * At the moment, we only handle images. All other objects are ignored. */ UT_Error IE_Imp_Psion::insertObject(const psiconv_in_line_layout in_line) { // Not yet implemented: object_display_section, object_icon_section, // Not yet implemented: object width and height // We only accept Sketch objects (pictures) for now. if (!in_line || !in_line->object || !in_line->object->object || (in_line->object->object->type != psiconv_sketch_file)) { UT_DEBUGMSG(("PSION: Unsupported object (ignored)\n")); return UT_OK; } return insertImage(in_line); }
void KTextCursor::insertImage( const QString &name, const QString &key, const QString &linkValue, const QString &linkKey ) { QTextImageFormat imageFormat; imageFormat.setAnchor(true); imageFormat.setAnchorHref(linkValue); imageFormat.setName(name); imageFormat.setProperty(KImageKey, key); if(!linkKey.isEmpty()) { imageFormat.setProperty( KLinkKey, linkKey ); } insertImage(name, imageFormat); }
HTMLChatEditFrame::HTMLChatEditFrame(QWidget* parent, const QString& iconPath) : QWidget(parent) { QPushButton * linkBtn = new QPushButton("link", this); toolBar = new QToolBar(this); toolBar->setIconSize(QSize(16, 16)); linkBtn->move(450, 40); editor = new HTMLChatEdit(this, toolBar, iconPath); editor->setGeometry(0, 30, 400, 150); this->setGeometry(0, 0, 600, 400); this->show(); QObject::connect(linkBtn, SIGNAL(clicked()), editor, SLOT(insertAnchor())); QObject::connect(linkBtn, SIGNAL(clicked()), editor, SLOT(insertImage())); }
bool RtfReader::parseDocument() { enum { READ_NORMAL_DATA, READ_BINARY_DATA, READ_HEX_SYMBOL, READ_KEYWORD, READ_KEYWORD_PARAMETER } parserState = READ_NORMAL_DATA; std::string keyword; std::string parameterString; std::string hexString; int imageStartOffset = -1; while (!myIsInterrupted) { const char *ptr = myStreamBuffer; const char *end = myStreamBuffer + myStream->read(myStreamBuffer, rtfStreamBufferSize); if (ptr == end) { break; } const char *dataStart = ptr; bool readNextChar = true; while (ptr != end) { switch (parserState) { case READ_BINARY_DATA: // TODO: optimize processCharData(ptr, 1); --myBinaryDataSize; if (myBinaryDataSize == 0) { parserState = READ_NORMAL_DATA; } break; case READ_NORMAL_DATA: switch (*ptr) { case '{': if (ptr > dataStart) { processCharData(dataStart, ptr - dataStart); } dataStart = ptr + 1; myStateStack.push(myState); myState.ReadDataAsHex = false; break; case '}': { if (ptr > dataStart) { processCharData(dataStart, ptr - dataStart); } dataStart = ptr + 1; if (imageStartOffset >= 0) { int imageSize = myStream->offset() + (ptr - end) - imageStartOffset; insertImage(myNextImageMimeType, myFileName, imageStartOffset, imageSize); imageStartOffset = -1; } if (myStateStack.empty()) { return false; } if (myState.Destination != myStateStack.top().Destination) { switchDestination(myState.Destination, false); switchDestination(myStateStack.top().Destination, true); } bool oldItalic = myState.Italic; bool oldBold = myState.Bold; bool oldUnderlined = myState.Underlined; ZLTextAlignmentType oldAlignment = myState.Alignment; myState = myStateStack.top(); myStateStack.pop(); if (myState.Italic != oldItalic) { setFontProperty(RtfReader::FONT_ITALIC); } if (myState.Bold != oldBold) { setFontProperty(RtfReader::FONT_BOLD); } if (myState.Underlined != oldUnderlined) { setFontProperty(RtfReader::FONT_UNDERLINED); } if (myState.Alignment != oldAlignment) { setAlignment(); } break; } case '\\': if (ptr > dataStart) { processCharData(dataStart, ptr - dataStart); } dataStart = ptr + 1; keyword.erase(); parserState = READ_KEYWORD; break; case 0x0d: case 0x0a: // cr and lf are noise characters... if (ptr > dataStart) { processCharData(dataStart, ptr - dataStart); } dataStart = ptr + 1; break; default: if (myState.ReadDataAsHex) { if (imageStartOffset == -1) { imageStartOffset = myStream->offset() + (ptr - end); } } break; } break; case READ_HEX_SYMBOL: hexString += *ptr; if (hexString.size() == 2) { char ch = strtol(hexString.c_str(), 0, 16); hexString.erase(); processCharData(&ch, 1); parserState = READ_NORMAL_DATA; dataStart = ptr + 1; } break; case READ_KEYWORD: if (!isalpha(*ptr)) { if ((ptr == dataStart) && (keyword.empty())) { if (*ptr == '\'') { parserState = READ_HEX_SYMBOL; } else { keyword = *ptr; processKeyword(keyword); parserState = READ_NORMAL_DATA; } dataStart = ptr + 1; } else { keyword.append(dataStart, ptr - dataStart); if ((*ptr == '-') || isdigit(*ptr)) { dataStart = ptr; parserState = READ_KEYWORD_PARAMETER; } else { readNextChar = *ptr == ' '; processKeyword(keyword); parserState = READ_NORMAL_DATA; dataStart = readNextChar ? ptr + 1 : ptr; } } } break; case READ_KEYWORD_PARAMETER: if (!isdigit(*ptr)) { parameterString.append(dataStart, ptr - dataStart); int parameter = atoi(parameterString.c_str()); parameterString.erase(); readNextChar = *ptr == ' '; if ((keyword == "bin") && (parameter > 0)) { myBinaryDataSize = parameter; parserState = READ_BINARY_DATA; } else { processKeyword(keyword, ¶meter); parserState = READ_NORMAL_DATA; } dataStart = readNextChar ? ptr + 1 : ptr; } break; } if (readNextChar) { ++ptr; } else { readNextChar = true; } } if (dataStart < end) { switch (parserState) { case READ_NORMAL_DATA: processCharData(dataStart, end - dataStart); case READ_KEYWORD: keyword.append(dataStart, end - dataStart); break; case READ_KEYWORD_PARAMETER: parameterString.append(dataStart, end - dataStart); break; default: break; } } } return myIsInterrupted || myStateStack.empty(); }
void TextEdit::setupEditActions() { QToolBar *tb = new QToolBar(this); tb->setWindowTitle(tr("Edit Actions")); addToolBar(tb); QMenu *menu = new QMenu(tr("&Edit"), this); menuBar()->addMenu(menu); QAction *a; a = actionUndo = new QAction(QIcon::fromTheme("edit-undo", QIcon(rsrcPath + "/editundo.png")), tr("&Undo"), this); a->setShortcut(QKeySequence::Undo); tb->addAction(a); menu->addAction(a); a = actionRedo = new QAction(QIcon::fromTheme("edit-redo", QIcon(rsrcPath + "/editredo.png")), tr("&Redo"), this); a->setPriority(QAction::LowPriority); a->setShortcut(QKeySequence::Redo); tb->addAction(a); menu->addAction(a); menu->addSeparator(); a = actionCut = new QAction(QIcon::fromTheme("edit-cut", QIcon(rsrcPath + "/editcut.png")), tr("Cu&t"), this); a->setPriority(QAction::LowPriority); a->setShortcut(QKeySequence::Cut); tb->addAction(a); menu->addAction(a); a = actionCopy = new QAction(QIcon::fromTheme("edit-copy", QIcon(rsrcPath + "/editcopy.png")), tr("&Copy"), this); a->setPriority(QAction::LowPriority); a->setShortcut(QKeySequence::Copy); tb->addAction(a); menu->addAction(a); a = actionPaste = new QAction(QIcon::fromTheme("edit-paste", QIcon(rsrcPath + "/editpaste.png")), tr("&Paste"), this); a->setPriority(QAction::LowPriority); a->setShortcut(QKeySequence::Paste); tb->addAction(a); menu->addAction(a); a = actionInsertimage = new QAction(QIcon::fromTheme("edit-insertImage", QIcon(rsrcPath + "/image.png")), tr("&Insert Image"), this); a->setPriority(QAction::LowPriority); // a->setShortcut(QKeySequence::Paste); connect(a, SIGNAL(triggered()), this, SLOT(insertImage())); tb->addAction(a); menu->addAction(a); a = actionInsertUrl = new QAction(QIcon::fromTheme("edit-insertUrl", QIcon(rsrcPath + "/link.png")), tr("&Insert Hyperlink"), this); a->setPriority(QAction::LowPriority); // a->setShortcut(QKeySequence::Paste); connect(a, SIGNAL(triggered()), this, SLOT(insertUrl())); tb->addAction(a); menu->addAction(a); #ifndef QT_NO_CLIPBOARD if (const QMimeData *md = QApplication::clipboard()->mimeData()) actionPaste->setEnabled(md->hasText()); #endif }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { installEventFilter(this); QPixmap *pixmap = NULL; pixmap = new QPixmap(200, 150); pixmap->load(":/f"); QIcon *icon = new QIcon(*pixmap); chatPicture = new QPushButton(*icon, tr("P"), this); chatPicture->setIconSize(QSize(190, 150)); chatPicture->setFixedSize(25, 25); // chatPicture->setStyleSheet("background:white"); //设置背景色 QPixmap *pixmap1 = NULL; pixmap1 = new QPixmap(200, 150); pixmap1->load(":/e"); QIcon *icon1 = new QIcon(*pixmap1); chatEmotion1 = new QPushButton(*icon1, tr("E"), this); chatEmotion1->setIconSize(QSize(190, 150)); chatEmotion1->setFixedSize(24, 24); // chatEmotion1->setStyleSheet("background:white"); QPixmap *pixmap2 = NULL; pixmap2 = new QPixmap(200, 150); pixmap2->load(":/c.png"); QIcon *icon2 = new QIcon(*pixmap2); chatSend = new QPushButton(*icon2, tr("发送(S)"), this); chatSend->setIconSize(QSize(190, 150)); chatSend->setFixedSize(60, 25); // chatSend->setStyleSheet("background:white"); chatSend->setFocus(); //设置默认焦点 //chatSend->setDefault(true); //设置默认按钮,设置了这个属性,当用户按下回车的时候,就会按下该按钮 chatSend->setShortcut(QKeySequence::InsertParagraphSeparator); tein = new TextEdit; // tein->setFocus(); QGridLayout *layout = new QGridLayout; // layout->addWidget(pArea, 0, 0, 13, 9); layout->addWidget(chatEmotion1, 0, 0, 1, 1); layout->addWidget(chatPicture, 0, 1, 1, 1); layout->addWidget(chatSend, 0, 2, 1, 1); layout->addWidget(tein, 1, 0, 1, 11); pArea= new QScrollArea(this); teout = new QWidget(pArea);//需要滚动的是一个Qwidget,而如果是在设计器里面拖入控件,会自动添加一个 pArea->setWidget(teout);//这里设置滚动窗口qw, // pArea->setWidgetResizable(false); QGridLayout *layout1 = new QGridLayout; layout1->addWidget(pArea); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(layout1, 5); mainLayout->addLayout(layout, 2); QWidget *mainWidget = new QWidget; mainWidget->setMinimumSize(400, 550); mainWidget->setLayout(mainLayout); setCentralWidget(mainWidget); // QVBoxLayout* mainLayout1 = new QVBoxLayout; // mainLayout1->addWidget(mainWidget); // setLayout(mainLayout1); teout->setWindowFlags(Qt::FramelessWindowHint);//隐藏边框 pArea->setWindowFlags(Qt::FramelessWindowHint);//隐藏边框 this->setGeometry(0, 0, 400, 400); teout->setGeometry(0, 0, this->size().width() - 37, 1000000); qDebug() << mainWidget->width(); connect(chatEmotion1, &QPushButton::clicked, this, &MainWindow::Emotion); //插入表情 connect(chatPicture, SIGNAL(clicked()), this, SLOT(insertImage()));//插入图片 connect(chatSend, &QPushButton::clicked, this, &MainWindow::sendfun);//发送消息 }
HtmlEditor::HtmlEditor(QWidget *parent) : QMainWindow(parent) , ui(new Ui_MainWindow) , sourceDirty(true) , highlighter(0) , ui_dialog(0) , insertHtmlDialog(0) { ui->setupUi(this); ui->tabWidget->setTabText(0, "Normal View"); ui->tabWidget->setTabText(1, "HTML Source"); connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(changeTab(int))); resize(600, 600); highlighter = new Highlighter(ui->plainTextEdit->document()); QWidget *spacer = new QWidget(this); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); ui->standardToolBar->insertWidget(ui->actionZoomOut, spacer); zoomLabel = new QLabel; ui->standardToolBar->insertWidget(ui->actionZoomOut, zoomLabel); zoomSlider = new QSlider(this); zoomSlider->setOrientation(Qt::Horizontal); zoomSlider->setMaximumWidth(150); zoomSlider->setRange(25, 400); zoomSlider->setSingleStep(25); zoomSlider->setPageStep(100); connect(zoomSlider, SIGNAL(valueChanged(int)), SLOT(changeZoom(int))); ui->standardToolBar->insertWidget(ui->actionZoomIn, zoomSlider); connect(ui->actionFileNew, SIGNAL(triggered()), SLOT(fileNew())); connect(ui->actionFileOpen, SIGNAL(triggered()), SLOT(fileOpen())); connect(ui->actionFileSave, SIGNAL(triggered()), SLOT(fileSave())); connect(ui->actionFileSaveAs, SIGNAL(triggered()), SLOT(fileSaveAs())); connect(ui->actionExit, SIGNAL(triggered()), SLOT(close())); connect(ui->actionInsertImage, SIGNAL(triggered()), SLOT(insertImage())); connect(ui->actionCreateLink, SIGNAL(triggered()), SLOT(createLink())); connect(ui->actionInsertHtml, SIGNAL(triggered()), SLOT(insertHtml())); connect(ui->actionZoomOut, SIGNAL(triggered()), SLOT(zoomOut())); connect(ui->actionZoomIn, SIGNAL(triggered()), SLOT(zoomIn())); // these are forward to internal QWebView FORWARD_ACTION(ui->actionEditUndo, QWebPage::Undo); FORWARD_ACTION(ui->actionEditRedo, QWebPage::Redo); FORWARD_ACTION(ui->actionEditCut, QWebPage::Cut); FORWARD_ACTION(ui->actionEditCopy, QWebPage::Copy); FORWARD_ACTION(ui->actionEditPaste, QWebPage::Paste); FORWARD_ACTION(ui->actionFormatBold, QWebPage::ToggleBold); FORWARD_ACTION(ui->actionFormatItalic, QWebPage::ToggleItalic); FORWARD_ACTION(ui->actionFormatUnderline, QWebPage::ToggleUnderline); // Qt 4.5.0 has a bug: always returns 0 for QWebPage::SelectAll connect(ui->actionEditSelectAll, SIGNAL(triggered()), SLOT(editSelectAll())); connect(ui->actionStyleParagraph, SIGNAL(triggered()), SLOT(styleParagraph())); connect(ui->actionStyleHeading1, SIGNAL(triggered()), SLOT(styleHeading1())); connect(ui->actionStyleHeading2, SIGNAL(triggered()), SLOT(styleHeading2())); connect(ui->actionStyleHeading3, SIGNAL(triggered()), SLOT(styleHeading3())); connect(ui->actionStyleHeading4, SIGNAL(triggered()), SLOT(styleHeading4())); connect(ui->actionStyleHeading5, SIGNAL(triggered()), SLOT(styleHeading5())); connect(ui->actionStyleHeading6, SIGNAL(triggered()), SLOT(styleHeading6())); connect(ui->actionStylePreformatted, SIGNAL(triggered()), SLOT(stylePreformatted())); connect(ui->actionStyleAddress, SIGNAL(triggered()), SLOT(styleAddress())); connect(ui->actionFormatFontName, SIGNAL(triggered()), SLOT(formatFontName())); connect(ui->actionFormatFontSize, SIGNAL(triggered()), SLOT(formatFontSize())); connect(ui->actionFormatTextColor, SIGNAL(triggered()), SLOT(formatTextColor())); connect(ui->actionFormatBackgroundColor, SIGNAL(triggered()), SLOT(formatBackgroundColor())); // no page action exists yet for these, so use execCommand trick connect(ui->actionFormatStrikethrough, SIGNAL(triggered()), SLOT(formatStrikeThrough())); connect(ui->actionFormatAlignLeft, SIGNAL(triggered()), SLOT(formatAlignLeft())); connect(ui->actionFormatAlignCenter, SIGNAL(triggered()), SLOT(formatAlignCenter())); connect(ui->actionFormatAlignRight, SIGNAL(triggered()), SLOT(formatAlignRight())); connect(ui->actionFormatAlignJustify, SIGNAL(triggered()), SLOT(formatAlignJustify())); connect(ui->actionFormatDecreaseIndent, SIGNAL(triggered()), SLOT(formatDecreaseIndent())); connect(ui->actionFormatIncreaseIndent, SIGNAL(triggered()), SLOT(formatIncreaseIndent())); connect(ui->actionFormatNumberedList, SIGNAL(triggered()), SLOT(formatNumberedList())); connect(ui->actionFormatBulletedList, SIGNAL(triggered()), SLOT(formatBulletedList())); // necessary to sync our actions connect(ui->webView->page(), SIGNAL(selectionChanged()), SLOT(adjustActions())); connect(ui->webView->page(), SIGNAL(contentsChanged()), SLOT(adjustSource())); ui->webView->setFocus(); setCurrentFileName(QString()); QString initialFile = ":/example.html"; const QStringList args = QCoreApplication::arguments(); if (args.count() == 2) initialFile = args.at(1); if (!load(initialFile)) fileNew(); adjustActions(); adjustSource(); setWindowModified(false); changeZoom(100); }
MRichTextEdit::MRichTextEdit(QWidget *parent) : QWidget(parent) { setupUi(this); m_lastBlockList = 0; f_textedit->setTabStopWidth(40); connect(f_textedit, SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(slotCurrentCharFormatChanged(QTextCharFormat))); connect(f_textedit, SIGNAL(cursorPositionChanged()), this, SLOT(slotCursorPositionChanged())); m_fontsize_h1 = 18; m_fontsize_h2 = 16; m_fontsize_h3 = 14; m_fontsize_h4 = 12; fontChanged(f_textedit->font()); bgColorChanged(f_textedit->textColor()); // paragraph formatting m_paragraphItems << tr("Standard") << tr("Heading 1") << tr("Heading 2") << tr("Heading 3") << tr("Heading 4") << tr("Monospace"); f_paragraph->addItems(m_paragraphItems); connect(f_paragraph, SIGNAL(activated(int)), this, SLOT(textStyle(int))); // undo & redo f_undo->setShortcut(QKeySequence::Undo); f_redo->setShortcut(QKeySequence::Redo); connect(f_textedit->document(), SIGNAL(undoAvailable(bool)), f_undo, SLOT(setEnabled(bool))); connect(f_textedit->document(), SIGNAL(redoAvailable(bool)), f_redo, SLOT(setEnabled(bool))); f_undo->setEnabled(f_textedit->document()->isUndoAvailable()); f_redo->setEnabled(f_textedit->document()->isRedoAvailable()); connect(f_undo, SIGNAL(clicked()), f_textedit, SLOT(undo())); connect(f_redo, SIGNAL(clicked()), f_textedit, SLOT(redo())); // cut, copy & paste f_cut->setShortcut(QKeySequence::Cut); f_copy->setShortcut(QKeySequence::Copy); f_paste->setShortcut(QKeySequence::Paste); f_cut->setEnabled(false); f_copy->setEnabled(false); connect(f_cut, SIGNAL(clicked()), f_textedit, SLOT(cut())); connect(f_copy, SIGNAL(clicked()), f_textedit, SLOT(copy())); connect(f_paste, SIGNAL(clicked()), f_textedit, SLOT(paste())); connect(f_textedit, SIGNAL(copyAvailable(bool)), f_cut, SLOT(setEnabled(bool))); connect(f_textedit, SIGNAL(copyAvailable(bool)), f_copy, SLOT(setEnabled(bool))); #ifndef QT_NO_CLIPBOARD connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slotClipboardDataChanged())); #endif // link f_link->setShortcut(Qt::CTRL + Qt::Key_L); connect(f_link, SIGNAL(clicked(bool)), this, SLOT(textLink(bool))); // bold, italic & underline f_bold->setShortcut(Qt::CTRL + Qt::Key_B); f_italic->setShortcut(Qt::CTRL + Qt::Key_I); f_underline->setShortcut(Qt::CTRL + Qt::Key_U); connect(f_bold, SIGNAL(clicked()), this, SLOT(textBold())); connect(f_italic, SIGNAL(clicked()), this, SLOT(textItalic())); connect(f_underline, SIGNAL(clicked()), this, SLOT(textUnderline())); connect(f_strikeout, SIGNAL(clicked()), this, SLOT(textStrikeout())); // lists f_list_bullet->setShortcut(Qt::CTRL + Qt::Key_Minus); f_list_ordered->setShortcut(Qt::CTRL + Qt::Key_Equal); connect(f_list_bullet, SIGNAL(clicked(bool)), this, SLOT(listBullet(bool))); connect(f_list_ordered, SIGNAL(clicked(bool)), this, SLOT(listOrdered(bool))); // indentation f_indent_dec->setShortcut(Qt::CTRL + Qt::Key_Comma); f_indent_inc->setShortcut(Qt::CTRL + Qt::Key_Period); connect(f_indent_inc, SIGNAL(clicked()), this, SLOT(increaseIndentation())); connect(f_indent_dec, SIGNAL(clicked()), this, SLOT(decreaseIndentation())); // font size QFontDatabase db; foreach(int size, db.standardSizes()) { f_fontsize->addItem(QString::number(size)); } connect(f_fontsize, SIGNAL(activated(QString)), this, SLOT(textSize(QString))); f_fontsize->setCurrentIndex(f_fontsize->findText(QString::number(QApplication::font().pointSize()))); // text background color QPixmap pix(16, 16); pix.fill(QApplication::palette().background().color()); f_bgcolor->setIcon(pix); connect(f_bgcolor, SIGNAL(clicked()), this, SLOT(textBgColor())); // images connect(f_image, SIGNAL(clicked()), this, SLOT(insertImage())); }
TextRoom::TextRoom(QWidget *parent, Qt::WFlags f) : QWidget(parent, f), sentenceTally(0) { setupUi(this); setObjectName("textroom"); // Set the default values for variables. numChanges = 0; prevLength = 0; wordcount = 0; alarm = 0; parasold = 0; isHighlighted = false; #ifdef Q_OS_MACX // Find the path for the app path QDir tmpDir = QDir(QCoreApplication::applicationDirPath()); // go into Resources folder tmpDir.cdUp(); tmpDir.cd("Resources"); // get the full path for the resources resourcesDir = tmpDir.path(); #endif // Create the dialog windows. optionsDialog = new OptionsDialog(this); helpDialog = new HelpDialog(this); selectFont = new SelectFont(this); aboutDialog = new AboutDialog(this); scratchDialog = new ScratchDialog(this); miniFlo = new MiniFlo(this); getAWord = new GetAWord(this); musicRoom = new MusicRoom(this); googleDocsDialog = new GoogleDocsDialog(this); // Read settings saved by Options Dialog. #ifdef Q_OS_WIN32 settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::applicationName()); #else settings = new QSettings(); #endif readSettings(); // Sound adjustments. int audio_rate = 11025; Uint16 audio_format = AUDIO_S16SYS; int audio_channels = 2; int audio_buffers = 1024; if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) { printf("Unable to initialize audio: %s\n", Mix_GetError()); exit(1); } // Load sounds. #ifdef Q_OS_WIN32 soundenter = Mix_LoadWAV("keyenter.wav"); #elif defined(Q_OS_MACX) QString tmp = resourcesDir; tmp.append("/sounds/keyenter.wav"); soundenter = Mix_LoadWAV(tmp.toAscii()); #else soundenter = Mix_LoadWAV("/usr/share/sounds/keyenter.wav"); #endif if(soundenter == NULL) { printf("Unable to load WAV file: %s\n", Mix_GetError()); } #ifdef Q_OS_WIN32 soundany = Mix_LoadWAV("keyany.wav"); #elif defined(Q_OS_MACX) tmp = resourcesDir; tmp.append("/sounds/keyany.wav"); soundany = Mix_LoadWAV(tmp.toAscii()); #else soundany = Mix_LoadWAV("/usr/share/sounds/keyany.wav"); #endif if(soundany == NULL) { printf("Unable to load WAV file: %s\n", Mix_GetError()); } // Create the keyboard shortcuts. new QShortcut ( QKeySequence(QKeySequence::New), this, SLOT( newFile() ) ); new QShortcut ( QKeySequence(QKeySequence::Open), this, SLOT( open() ) ); new QShortcut ( QKeySequence(QKeySequence::Save), this, SLOT( save() ) ); new QShortcut ( QKeySequence(QKeySequence::HelpContents), this, SLOT( help() ) ); #ifdef Q_OS_MACX new QShortcut ( QKeySequence(tr("F1", "Help")), this, SLOT( help() ) ); #endif new QShortcut ( QKeySequence(tr("F2", "Options")), this, SLOT( options() ) ); new QShortcut ( QKeySequence(tr("F3", "About")), this, SLOT( about() ) ); new QShortcut ( QKeySequence(tr("F5", "Spell Check")), this, SLOT( spellCheck() ) ); new QShortcut ( QKeySequence(tr("F6", "Scratch Pad")), this, SLOT( showScratchPad() ) ); new QShortcut ( QKeySequence(tr("Ctrl+P", "Print")), this, SLOT( print() ) ); new QShortcut ( QKeySequence(tr("Shift+Ctrl+S", "Save As")), this, SLOT( saveAs() ) ); new QShortcut ( QKeySequence(tr("Ctrl+D", "Insert Date")), this, SLOT( insertDate() ) ); new QShortcut ( QKeySequence(tr("Ctrl+T", "Insert Time")), this, SLOT( insertTime() ) ); new QShortcut ( QKeySequence(tr("Ctrl+Q", "Quit Application")) , this, SLOT( close() ) ); new QShortcut ( QKeySequence(tr("Alt+F4", "Quit Application")) , this, SLOT( close() ) ); new QShortcut ( QKeySequence(tr("Ctrl+F", "Find Text")) , this, SLOT( find() ) ); new QShortcut ( QKeySequence(tr("F11", "Toggle Fullscreen")) , this, SLOT( toggleFullScreen() ) ); new QShortcut ( QKeySequence(tr("Esc", "Toggle Fullscreen")) , this, SLOT( toggleEscape() ) ); new QShortcut ( QKeySequence(tr("Ctrl+M", "Minimize TextRoom")) , this, SLOT( showMinimized() ) ); new QShortcut ( QKeySequence(tr("F4", "Find Next")) , this, SLOT( find_next() ) ); new QShortcut ( QKeySequence(tr("Ctrl+F4", "Find Previous")) , this, SLOT( find_previous() ) ); new QShortcut ( QKeySequence(tr("Ctrl+B", "Bold")) , this, SLOT( textBold() ) ); new QShortcut ( QKeySequence(tr("Ctrl+I", "Italic")) , this, SLOT( textItalic() ) ); new QShortcut ( QKeySequence(tr("Ctrl+Up", "Increase Text Size")) , this, SLOT( textSizeUp() ) ); new QShortcut ( QKeySequence(tr("Ctrl+Down", "Decrease Text Size")) , this, SLOT( textSizeDown() ) ); new QShortcut ( QKeySequence(tr("Ctrl+W", "Select Font")) , this, SLOT( changeFont() ) ); new QShortcut ( QKeySequence(tr("Ctrl+R", "Align Right")) , this, SLOT( alignRight() ) ); new QShortcut ( QKeySequence(tr("Ctrl+L", "Align Left")) , this, SLOT( alignLeft() ) ); new QShortcut ( QKeySequence(tr("Ctrl+J", "Align Justify")) , this, SLOT( alignJustify() ) ); new QShortcut ( QKeySequence(tr("Ctrl+E", "Align Center")) , this, SLOT( alignCenter() ) ); new QShortcut ( QKeySequence(tr("Ctrl+Alt+I", "Insert Image")) , this, SLOT( insertImage() ) ); new QShortcut ( QKeySequence(tr("F7", "Show MiniFlo")) , this, SLOT( showMiniFlo() ) ); new QShortcut ( QKeySequence(tr("F8", "Get A Word")) , this, SLOT( showGetAWord() ) ); new QShortcut ( QKeySequence(tr("F9", "MusicRoom")) , this, SLOT( showMusicRoom() ) ); new QShortcut ( QKeySequence(tr("F10", "Google Docs")) , this, SLOT( exportToGoogle() ) ); // Service: show cursor new QShortcut ( QKeySequence(tr("Shift+F4", "Show Cursor")) , this, SLOT( sCursor() ) ); //fw = new QFileSystemWatcher(this); //fw->addPath( settings->fileName() ); // If file is changed, read the settings-> //connect(fw, SIGNAL(fileChanged(const QString)), // this, SLOT(readSettings())); // If the document is changed, do some stuff. connect(textEdit->document(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified())); // If position is changed, scroll. connect(textEdit->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(vPositionChanged())); // If horizontal scrollar is changed, scroll. connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(hSliderPositionChanged())); connect(textEdit, SIGNAL(anchorClicked(QUrl)), this, SLOT(showScratchPad())); // check if we need to open some file at startup const QStringList args = QCoreApplication::arguments(); if (args.count() == 2) { QFile file( args.at(1) ); if ( file.exists() ) curFile = args.at(1); } if (!curFile.isEmpty()) loadFile(curFile); else newFile(); // set cursor position if ( isSaveCursor ) { textEdit->textCursor().setPosition(cPosition); } writeSettings(); // Refresh the file status every second. QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(getFileStatus())); timer->start(1000); }