float Grid::snapDown(float f, bool skip) const { if (!snap()) return f; unsigned int actSize = actualSize(); float s = actSize * std::floor(f / actSize); if (skip && s == f) s -= actualSize(); return s; }
float Grid::snapUp(float f, bool skip) const { if (!snap()) return f; unsigned int actSize = actualSize(); float s = actSize * std::ceil(f / actSize); if (skip && s == f) s += actualSize(); return s; }
//------------------------------------------------------------------------------ //! void ComboBox::onClick( const Event& ev ) { // Set minimum width of menu to the current combobox. Vec2f nsize = Vec2f( CGM::max( actualSize().x - 2.0f*_offset.x, _menu->actualBaseSize().x ), _menu->size().y ); _menu->size( nsize ); Vec2f pos = _menuAbove ? Vec2f( 0.0f, actualSize().y ) : -Vec2f( 0.0f, _menu->actualBaseSize().y ); Core::desktop()->popup( _menu, globalPosition() + pos + _offset, nullptr ); Widget::onClick( ev ); }
bool Texture::create(unsigned int width, unsigned int height) { // Check if texture parameters are valid before creating it if ((width == 0) || (height == 0)) { err() << "Failed to create texture, invalid size (" << width << "x" << height << ")" << std::endl; return false; } // Compute the internal texture dimensions depending on NPOT textures support Vector2u actualSize(getValidSize(width), getValidSize(height)); // Check the maximum texture size unsigned int maxSize = getMaximumSize(); if ((actualSize.x > maxSize) || (actualSize.y > maxSize)) { err() << "Failed to create texture, its internal size is too high " << "(" << actualSize.x << "x" << actualSize.y << ", " << "maximum is " << maxSize << "x" << maxSize << ")" << std::endl; return false; } // All the validity checks passed, we can store the new texture settings m_size.x = width; m_size.y = height; m_actualSize = actualSize; m_pixelsFlipped = false; // Create the OpenGL texture if it doesn't exist yet if (!m_texture) { GLuint texture; glCheck(glGenTextures(1, &texture)); m_texture = static_cast<unsigned int>(texture); } // Make sure that the current texture binding will be preserved priv::TextureSaver save; // Initialize the texture glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); glCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_actualSize.x, m_actualSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL)); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : GL_CLAMP)); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT :GL_CLAMP)); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); m_cacheId = getUniqueId(); return true; }
UpperMatrix<T>::UpperMatrix(const UpperMatrix<T>& matrix) { m_rowSize = matrix.rowSize(); m_numRows = matrix.numRows(); m_dataPtr = new T[m_numRows*m_rowSize]; for(int i = 0; i < actualSize(); i++) m_dataPtr[i] = matrix[i]; }
bool ImageItem::reload() { // destroy the old image instance clearPage(); //qDebug("Begin Load Image %s!\n", name().toStdString().c_str()); // Reconstruct the image by key if (name() == EMPTY_BACKGROUND) { data_.reset(new QImage(EMPTY_BACKGROUND_WIDTH, EMPTY_BACKGROUND_HEIGHT, QImage::Format_ARGB32)); QColor white(255, 255, 255); data_->fill(white.rgba()); } else { data_.reset(new QImage(name())); } //qDebug("End Load Image! %s\n", name().toStdString().c_str()); if (data_->isNull()) { // if the image is broken, display the warning map data_->load(":/images/invalid.png"); } private_info_.reset(); dirty_ = false; actualSize() = data_->size(); // reset the render setting // TODO. Use default rotation value RenderSetting setting; setting.setContentArea(QRect(0, 0, actualSize().width(), actualSize().height())); setting.setRotation(ROTATE_0_DEGREE); setRenderSetting(setting); return true; }
QPixmap CaMifIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) { Q_UNUSED(mode); Q_UNUSED(state); QPixmap pixmap; actualSize(size, mode, state); QString key = pmcKey(size); if (mCache.contains(key)) { pixmap = *mCache[key]; } return pixmap; }
bool SurfFaceDetection::DetectSingleScale(const Mat &_grayImg, float _scale, float _stepFactor, Size _winSize, vector<Rect> &_faceList) { if(!CalculateSurfSumImg(_grayImg)) return false; int height = (int)(_scale * _winSize.height + 0.5); int width = (int)(_scale * _winSize.width + 0.5); Size actualSize(width,height); int step = cv::min((int)(actualSize.height * _stepFactor + 0.5), (int)(actualSize.width * _stepFactor + 0.5)); DetectSingleScale(actualSize, _scale, step, _faceList); groupRectangles(_faceList, 2); return true; }
bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator, name ) ) return false; m_messageBitmap = bitmap; m_messageBitmapOriginal = bitmap; Widget parentWidget = (Widget) parent->GetClientWidget(); m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("staticBitmap", #if wxUSE_GADGETS xmLabelGadgetClass, parentWidget, #else xmLabelWidgetClass, parentWidget, #endif XmNalignment, XmALIGNMENT_BEGINNING, NULL); ChangeBackgroundColour (); DoSetBitmap(); ChangeFont(false); wxSize actualSize(size); // work around the cases where the bitmap is a wxNull(Icon/Bitmap) if (actualSize.x == -1) actualSize.x = bitmap.Ok() ? bitmap.GetWidth() : 1; if (actualSize.y == -1) actualSize.y = bitmap.Ok() ? bitmap.GetHeight() : 1; AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, actualSize.x, actualSize.y); return true; }
void TopLevel::setupMenuBar() { // File menu KStdAction::open( this, SLOT( faxOpen() ), actionCollection() ); actRecent = KStdAction::openRecent( this, SLOT( faxOpen( const KURL & ) ), actionCollection() ); actSave = KStdAction::save( this, SLOT( faxSave() ), actionCollection() ); actSaveAs = KStdAction::saveAs( this, SLOT( faxSaveAs() ), actionCollection() ); actPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); KStdAction::quit( this, SLOT( close() ), actionCollection() ); actAdd = new KAction( i18n( "A&dd..." ), "filenew", KShortcut(), this, SLOT( faxAdd() ), actionCollection(), "file_add_fax" ); actRecent->setMaxItems( 5 ); // View Menu actSize = KStdAction::actualSize( this, SLOT( actualSize() ), actionCollection() ); actZoomIn = KStdAction::zoomIn( this, SLOT( zoomin() ), actionCollection() ); actZoomOut = KStdAction::zoomOut( this, SLOT( zoomout() ), actionCollection() ); actRotate = new KAction( i18n( "&Rotate Page" ), "rotate", KShortcut(), this, SLOT( rotatePage() ), actionCollection(), "view_rotate" ); actMirror = new KAction( i18n( "Mirror Page" ), KShortcut(), this, SLOT( mirrorPage() ), actionCollection(), "view_mirror" ); actFlip = new KAction( i18n( "&Flip Page" ), KShortcut(), this, SLOT( flipPage() ), actionCollection(), "view_flip" ); // Go menu actNext = KStdAction::next( this, SLOT( nextPage() ), actionCollection() ); actPrev = KStdAction::prior( this, SLOT( prevPage() ), actionCollection() ); actFirst = KStdAction::firstPage( this, SLOT( firstPage() ), actionCollection() ); actLast = KStdAction::lastPage( this, SLOT( lastPage() ), actionCollection() ); // Settings menu KStdAction::preferences( this, SLOT( faxoptions() ), actionCollection() ); }
bool SurfFaceDetection::DetectMultiScale(const Mat &_grayImg, float _scaleFactor, float _stepFactor, Size _winSize, vector<Rect> &_faceList, bool _isScore, vector<double> *_scoreList) { if(!CalculateSurfSumImg(_grayImg)) return false; Size actualSize(_winSize); //Size imgSize = _grayImg.size(); float scale = 1.0; int step = cv::min((int)(actualSize.height * _stepFactor + 0.5), (int)(actualSize.width * _stepFactor + 0.5)); while( actualSize.width <= imgSize.width && actualSize.height <= imgSize.height ) { DetectSingleScale(actualSize, scale, step, _faceList,_scoreList); scale = scale * _scaleFactor; int height = (int)(scale * _winSize.height + 0.5); int width = (int)(scale * _winSize.width + 0.5); actualSize = Size(width, height); step = cv::min((int)(actualSize.height * _stepFactor + 0.5), (int)(actualSize.width * _stepFactor + 0.5)); } vector<int> weights(_faceList.size(),2); //groupRectangles(_faceList,1,0.2,&weights,_scoreList); groupRectangles(_faceList,weights, *_scoreList,1); if( srcScale != 1.0 ) { for(int idx=0; idx<_faceList.size(); idx++) { _faceList[idx].x = (int)(_faceList[idx].x * srcScale + 0.5); _faceList[idx].y = (int)(_faceList[idx].y * srcScale + 0.5); _faceList[idx].width = (int)(_faceList[idx].width * srcScale + 0.5); _faceList[idx].height = (int)(_faceList[idx].height * srcScale + 0.5); } } return true; }
bool XDebugComThread::DoReadReply(std::string& reply, clSocketBase::Ptr_t client) { if(!client) { return false; } try { // Read the data length wxString length; while(true) { char c = 0; size_t count = 0; client->Read(&c, 1, count); if(c == 0) { break; } length << c; } long dataLengh(0); if(!length.ToCLong(&dataLengh)) { // session terminated! return false; } // Read the actual buffer ++dataLengh; // +1 for NULL char* buffer = new char[dataLengh]; memset(buffer, 0, dataLengh); size_t actualSize(0); client->Read(buffer, dataLengh, actualSize); std::string content(buffer, dataLengh); reply.swap(content); wxDELETEA(buffer); } catch(clSocketException& e) { wxUnusedVar(e); return false; } return true; }
void MainWindow::createActions() { connect(ui->btnZoomIn, SIGNAL(clicked()), this, SLOT(zoomIn())); connect(ui->btnZoomOut, SIGNAL(clicked()), this, SLOT(zoomOut())); connect(ui->btnZoomNormal, SIGNAL(clicked()), this, SLOT(actualSize())); connect(ui->checkBoxFitToWindow, SIGNAL(stateChanged(int)), SLOT(updateZoomControls())); connect(ui->btnOpen, SIGNAL(clicked()), this, SLOT(open())); connect(ui->btnSave, SIGNAL(clicked()), this, SLOT(save())); connect(ui->btnAbout, SIGNAL(clicked()), this, SLOT(help())); connect(ui->sliderRadius, SIGNAL(valueChanged(int)), this, SLOT(radiusChanged())); connect(ui->sliderKernelFeather, SIGNAL(valueChanged(int)), this, SLOT(kernelFeatherChanged())); connect(ui->sliderKernelStrength, SIGNAL(valueChanged(int)), this, SLOT(kernelStrengthChanged())); connect(ui->sliderMotionLength, SIGNAL(valueChanged(int)), this, SLOT(motionLengthChanged())); connect(ui->sliderMotionAngle, SIGNAL(valueChanged(int)), this, SLOT(motionAngleChanged())); connect(ui->sliderPSNR, SIGNAL(valueChanged(int)), this, SLOT(PSNRChanged())); connect(ui->sliderRadius, SIGNAL(sliderReleased()), this, SLOT(updateFullDeconvolution())); connect(ui->sliderKernelFeather, SIGNAL(sliderReleased()), this, SLOT(updateFullDeconvolution())); connect(ui->sliderKernelStrength, SIGNAL(sliderReleased()), this, SLOT(updateFullDeconvolution())); connect(ui->sliderPSNR, SIGNAL(sliderReleased()), this, SLOT(updateFullDeconvolution())); connect(ui->sliderMotionLength, SIGNAL(sliderReleased()), this, SLOT(updateFullDeconvolution())); connect(ui->sliderMotionAngle, SIGNAL(sliderReleased()), this, SLOT(updateFullDeconvolution())); connect(ui->btnShowOriginal, SIGNAL(pressed()), this, SLOT(showOriginalPressed())); connect(ui->btnShowOriginal, SIGNAL(released()), this, SLOT(showOriginalReleased())); connect(ui->comboBoxType, SIGNAL(currentIndexChanged(int)), this, SLOT(defectTypeChanged(int))); //connect(ui->, SIGNAL()) connect(workerThread, SIGNAL(deconvolutionFinished(int)), SLOT(updatePreviewImage(int))); connect(workerThread->getDeconvolutionTool(), SIGNAL(progressEvent(int, QString)), this, SLOT(updateProgress(int, QString))); connect(ui->imageSizeLimitSpinBox, SIGNAL(valueChanged(int)), SLOT(imageSizeLimitChanged(int))); connect(ui->tvIterationsCountSpinBox, SIGNAL(valueChanged(int)), SLOT(tvIterationsCountChanged(int))); connect(ui->previewMethodComboBox, SIGNAL(currentIndexChanged(int)), SLOT(previewMethodChanged(int))); }
float Grid::intersectWithRay(const Rayf& ray, unsigned int skip) const { Vec3f planeAnchor; for (size_t i = 0; i < 3; i++) planeAnchor[i] = ray.direction[i] > 0.0f ? snapUp(ray.origin[i], true) + skip * actualSize() : snapDown(ray.origin[i], true) - skip * actualSize(); Planef plane(Vec3f::PosX, planeAnchor); float distX = plane.intersectWithRay(ray); plane = Planef(Vec3f::PosY, planeAnchor); float distY = plane.intersectWithRay(ray); plane = Planef(Vec3f::PosZ, planeAnchor); float distZ = plane.intersectWithRay(ray); float dist = distX; if (!Math<float>::isnan(distY) && (Math<float>::isnan(dist) || std::abs(distY) < std::abs(dist))) dist = distY; if (!Math<float>::isnan(distZ) && (Math<float>::isnan(dist) || std::abs(distZ) < std::abs(dist))) dist = distZ; return dist; }
ImageStatus ImageItem::renderThumbnail(const QRect &bounding_rect, QRect &display_area, shared_ptr<ImageThumbnail> thumbnail, ImageModel *model) { // check the previous thumbnail image if (thumbnail->image() != 0) { if (thumbnail->size() != display_area.size()) { thumbnail->clearPage(); } else { return IMAGE_STATUS_DONE; } } // if there is no data being loaded, reload the image scoped_ptr<QImage> cur_data; if (data_ == 0) { reload(); } cur_data.reset(new QImage(*data_)); if (!display_area.isValid()) { getThumbnailRectangle(bounding_rect, cur_data->size(), &display_area); } if (model->getThumbsMgr().makeEnoughMemory(tryCalcImageLength( display_area.width(), display_area.height(), QImage::Format_Indexed8), name(), model->renderPolicy())) { int width = display_area.width(); int height = display_area.height(); int cur_area_size = cur_data->width() * cur_data->height(); int scaled_area_size = width * height; bool dithered = false; if (cur_area_size < scaled_area_size) { // pre-dither dithering_strategy_->dither(cur_data.get()); dithered = true; } if (cur_data->size() != display_area.size()) { cur_data.reset(scaled(display_area.size(), cur_data.get())); } if (!dithered && ImageGlobalSettings::instance().needDither()) { // post-dither dithering_strategy_->dither(cur_data.get()); } thumbnail->setImage(cur_data.release()); thumbnail->setOriginSize(actualSize()); return IMAGE_STATUS_DONE; } return IMAGE_STATUS_FAIL; }
float Grid::intersectWithRay(const Ray& ray, unsigned int skip) const { Vec3f planeAnchor; planeAnchor.x = ray.direction.x > 0 ? snapUp(ray.origin.x, true) + skip * actualSize() : snapDown(ray.origin.x, true) - skip * actualSize(); planeAnchor.y = ray.direction.y > 0 ? snapUp(ray.origin.y, true) + skip * actualSize() : snapDown(ray.origin.y, true) - skip * actualSize(); planeAnchor.z = ray.direction.z > 0 ? snapUp(ray.origin.z, true) + skip * actualSize() : snapDown(ray.origin.z, true) - skip * actualSize(); Plane plane(Vec3f::PosX, planeAnchor); float distX = plane.intersectWithRay(ray); plane = Plane(Vec3f::PosY, planeAnchor); float distY = plane.intersectWithRay(ray); plane = Plane(Vec3f::PosZ, planeAnchor); float distZ = plane.intersectWithRay(ray); float dist = distX; if (!Math::isnan(distY) && (Math::isnan(dist) || std::abs(distY) < std::abs(dist))) dist = distY; if (!Math::isnan(distZ) && (Math::isnan(dist) || std::abs(distZ) < std::abs(dist))) dist = distZ; return dist; }
bool Texture::create(unsigned int width, unsigned int height) { // Check if texture parameters are valid before creating it if ((width == 0) || (height == 0)) { err() << "Failed to create texture, invalid size (" << width << "x" << height << ")" << std::endl; return false; } // Compute the internal texture dimensions depending on NPOT textures support Vector2u actualSize(getValidSize(width), getValidSize(height)); // Check the maximum texture size unsigned int maxSize = getMaximumSize(); if ((actualSize.x > maxSize) || (actualSize.y > maxSize)) { err() << "Failed to create texture, its internal size is too high " << "(" << actualSize.x << "x" << actualSize.y << ", " << "maximum is " << maxSize << "x" << maxSize << ")" << std::endl; return false; } // All the validity checks passed, we can store the new texture settings m_size.x = width; m_size.y = height; m_actualSize = actualSize; m_pixelsFlipped = false; m_fboAttachment = false; TransientContextLock lock; // Create the OpenGL texture if it doesn't exist yet if (!m_texture) { GLuint texture; glCheck(glGenTextures(1, &texture)); m_texture = static_cast<unsigned int>(texture); } // Make sure that extensions are initialized priv::ensureExtensionsInit(); // Make sure that the current texture binding will be preserved priv::TextureSaver save; static bool textureEdgeClamp = GLEXT_texture_edge_clamp || GLEXT_EXT_texture_edge_clamp; if (!m_isRepeated && !textureEdgeClamp) { static bool warned = false; if (!warned) { err() << "OpenGL extension SGIS_texture_edge_clamp unavailable" << std::endl; err() << "Artifacts may occur along texture edges" << std::endl; err() << "Ensure that hardware acceleration is enabled if available" << std::endl; warned = true; } } static bool textureSrgb = GLEXT_texture_sRGB; if (m_sRgb && !textureSrgb) { static bool warned = false; if (!warned) { #ifndef SFML_OPENGL_ES err() << "OpenGL extension EXT_texture_sRGB unavailable" << std::endl; #else err() << "OpenGL ES extension EXT_sRGB unavailable" << std::endl; #endif err() << "Automatic sRGB to linear conversion disabled" << std::endl; warned = true; } m_sRgb = false; } // Initialize the texture glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); glCheck(glTexImage2D(GL_TEXTURE_2D, 0, (m_sRgb ? GLEXT_GL_SRGB8_ALPHA8 : GL_RGBA), m_actualSize.x, m_actualSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL)); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : (textureEdgeClamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : (textureEdgeClamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); m_cacheId = getUniqueId(); m_hasMipmap = false; return true; }
/* * Menüpunkte erstellen */ void ProtoWindow::createActions() { openAct = new QAction(trUtf8("Ö&ffnen..."), this); openAct->setShortcut(trUtf8("Ctrl+O")); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); // TODO bei Speichern über STRG-S vermutlich nicht mehr nachfragen saveAct = new QAction(trUtf8("&Speichern"), this); saveAct->setShortcut(trUtf8("Ctrl+S")); saveAct->setEnabled(false); connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); saveAsAct = new QAction(trUtf8("Speichern unter..."), this); saveAsAct->setEnabled(false); connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); //printAct = new QAction(trUtf8("&Drucken..."), this); //printAct->setShortcut(trUtf8("Ctrl+P")); //printAct->setEnabled(false); //connect(printAct, SIGNAL(triggered()), this, SLOT(print())); exitAct = new QAction(trUtf8("&Beenden"), this); exitAct->setShortcut(trUtf8("Ctrl+Q")); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); zoomInAct = new QAction(trUtf8("ver&größern (25%)"), this); zoomInAct->setShortcut(trUtf8("Ctrl++")); zoomInAct->setEnabled(false); connect(zoomInAct, SIGNAL(triggered()), this, SLOT(zoomIn())); zoomOutAct = new QAction(trUtf8("ver&kleinern (25%)"), this); zoomOutAct->setShortcut(trUtf8("Ctrl+-")); zoomOutAct->setEnabled(false); connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(zoomOut())); normalSizeAct = new QAction(trUtf8("&Normale Größe"), this); normalSizeAct->setShortcut(trUtf8("Ctrl+N")); normalSizeAct->setEnabled(false); connect(normalSizeAct, SIGNAL(triggered()), this, SLOT(normalSize())); autoNormalSizeAct = new QAction(trUtf8("immer auf normale Größe einpassen"), this); autoNormalSizeAct->setCheckable(true); autoNormalSizeAct->setChecked(true); connect(autoNormalSizeAct, SIGNAL(triggered()), this, SLOT(autoNormalSize())); actualSizeAct = new QAction(trUtf8("&Tatsächliche Größe"), this); actualSizeAct->setShortcut(trUtf8("Ctrl+T")); actualSizeAct->setEnabled(false); connect(actualSizeAct, SIGNAL(triggered()), this, SLOT(actualSize())); invertImageAct = new QAction(trUtf8("Farben &invertieren"), this); invertImageAct->setEnabled(false); invertImageAct->setShortcut(trUtf8("I")); connect(invertImageAct, SIGNAL(triggered()), this, SLOT(invertImage())); rotateLeftAct = new QAction(trUtf8("90°-Drehung links"), this); rotateLeftAct->setEnabled(false); rotateLeftAct->setShortcut(trUtf8("Ctrl+Left")); connect(rotateLeftAct, SIGNAL(triggered()), this, SLOT(rotateLeft())); rotateRightAct = new QAction(trUtf8("90°-Drehung rechts"), this); rotateRightAct->setEnabled(false); rotateRightAct->setShortcut(trUtf8("Ctrl+Right")); connect(rotateRightAct, SIGNAL(triggered()), this, SLOT(rotateRight())); aboutAct = new QAction(trUtf8("&Über..."), this); connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); aboutQtAct = new QAction(trUtf8("Über &Qt"), this); connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); }
/*! Returns the actual size of the icon for the requested \a size, \a mode, and \a state. The result might be smaller than requested, but never larger. The returned size is in device-independent pixels (This is relevant for high-dpi pixmaps.) \sa pixmap(), paint() */ QSize QIcon::actualSize(const QSize &size, Mode mode, State state) const { if (!d) return QSize(); return actualSize(0, size, mode, state); }
float Grid::snap(float f) const { if (!snap()) return f; unsigned int actSize = actualSize(); return actSize * Math<float>::round(f / actSize); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); createStatusBar(); // Recent files for (int i = 0; i < MaxRecentFiles; ++i) { recentFileActions[i] = new QAction(this); recentFileActions[i]->setVisible(false); connect(recentFileActions[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); ui->menuFile->insertAction(ui->actionExit, recentFileActions[i]); } recentFilesSeparator = ui->menuFile->insertSeparator(ui->actionExit); printer = new QPrinter; printer->setFullPage(true); printer->setPaperSize(QPrinter::Letter); printer->setPageMargins(.5, .5, .5, .5, QPrinter::Inch); report = new Report(printer, this); view = new ReportView(report, this); preview = new QPrintPreviewWidget(printer, this); setCentralWidget(preview); preview->fitToWidth(); QFontComboBox* fontComboBox = new QFontComboBox; fontComboBox->setFontFilters(QFontComboBox::MonospacedFonts | QFontComboBox::ScalableFonts); fontComboBox->setCurrentFont(report->font().family()); ui->fontToolBar->insertWidget(ui->actionBold, fontComboBox); connect(fontComboBox, SIGNAL(currentFontChanged(QFont)), report, SLOT(setFont(QFont))); pageNumberComboBox = new QComboBox; ui->viewToolBar->insertWidget(ui->actionNextPage, pageNumberComboBox); connect(pageNumberComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(currentPageChanged(int))); const qreal zoomFactors[] = { 12.5, 25, 50, 100, 125, 150, 200, 400, 800 }; zoomComboBox = new QComboBox; for (unsigned int i = 0; i < sizeof(zoomFactors) / sizeof(*zoomFactors); ++i) { zoomComboBox->addItem(QString("%1%").arg(zoomFactors[i])); } zoomComboBox->setCurrentIndex(-1); ui->viewToolBar->insertWidget(ui->actionZoomOut, zoomComboBox); connect(zoomComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(zoomChanged(QString))); QActionGroup* orientationGroup = new QActionGroup(this); orientationGroup->addAction(ui->actionPortrait); orientationGroup->addAction(ui->actionLandscape); orientationChanged(report->orientation()); QActionGroup* heightGroup = new QActionGroup(this); heightGroup->addAction(ui->action6LPI); heightGroup->addAction(ui->action8LPI); heightGroup->addAction(ui->action9LPI); heightGroup->setDisabled(ui->actionStretchFont->isEnabled()); connect(ui->actionStretchFont, SIGNAL(toggled(bool)), heightGroup, SLOT(setDisabled(bool))); QActionGroup* widthGroup = new QActionGroup(this); widthGroup->addAction(ui->actionDefaultWidth); widthGroup->addAction(ui->action10CPI); widthGroup->addAction(ui->action12CPI); widthGroup->addAction(ui->action17CPI); widthGroup->setDisabled(ui->actionStretchFont->isEnabled()); connect(ui->actionStretchFont, SIGNAL(toggled(bool)), widthGroup, SLOT(setDisabled(bool))); QActionGroup* pageGroup = new QActionGroup(this); pageGroup->addAction(ui->actionSinglePage); pageGroup->addAction(ui->actionFacingPages); pageGroup->addAction(ui->actionAllPages); ui->actionSinglePage->setChecked(preview->viewMode() == QPrintPreviewWidget::SinglePageView); ui->actionFacingPages->setChecked(preview->viewMode() == QPrintPreviewWidget::FacingPagesView); ui->actionAllPages->setChecked(preview->viewMode() == QPrintPreviewWidget::AllPagesView); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about())); connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(open())); connect(ui->actionOpenURL, SIGNAL(triggered()), this, SLOT(openUrl())); connect(ui->actionReload, SIGNAL(triggered()), this, SLOT(reload())); connect(ui->actionSaveAsPDF, SIGNAL(triggered()), this, SLOT(saveAsPdf())); connect(ui->actionPrint, SIGNAL(triggered()), this, SLOT(print())); connect(ui->actionPageSetup, SIGNAL(triggered()), this, SLOT(pageSetup())); connect(ui->actionEmail, SIGNAL(triggered()), this, SLOT(email())); connect(ui->actionCopy, SIGNAL(triggered()), this, SLOT(copy())); connect(ui->actionStretchFont, SIGNAL(toggled(bool)), report, SLOT(setStretchFont(bool))); connect(report, SIGNAL(stretchFontChanged(bool)), ui->actionStretchFont, SLOT(setChecked(bool))); connect(ui->actionBold, SIGNAL(toggled(bool)), report, SLOT(setBold(bool))); connect(ui->actionStripes, SIGNAL(toggled(bool)), report, SLOT(setStripes(bool))); connect(ui->actionStripeColor, SIGNAL(triggered()), this, SLOT(stripeColor())); connect(ui->actionColor, SIGNAL(triggered()), this, SLOT(fontColor())); connect(ui->action6LPI, SIGNAL(triggered()), this, SLOT(height6Lpi())); connect(ui->action8LPI, SIGNAL(triggered()), this, SLOT(height8Lpi())); connect(ui->action9LPI, SIGNAL(triggered()), this, SLOT(height9Lpi())); connect(ui->actionDefaultWidth, SIGNAL(toggled(bool)), this, SLOT(widthDefault())); connect(ui->action10CPI, SIGNAL(triggered()), this, SLOT(width10Cpi())); connect(ui->action12CPI, SIGNAL(triggered()), this, SLOT(width12Cpi())); connect(ui->action17CPI, SIGNAL(triggered()), this, SLOT(width17Cpi())); connect(ui->actionFirstPage, SIGNAL(triggered()), this, SLOT(firstPage())); connect(ui->actionPreviousPage, SIGNAL(triggered()), this, SLOT(previousPage())); connect(ui->actionNextPage, SIGNAL(triggered()), this, SLOT(nextPage())); connect(ui->actionLastPage, SIGNAL(triggered()), this, SLOT(lastPage())); connect(ui->actionFitWidth, SIGNAL(triggered()), preview, SLOT(fitToWidth())); connect(ui->actionFitHeight, SIGNAL(triggered()), preview, SLOT(fitInView())); connect(ui->actionPortrait, SIGNAL(triggered()), preview, SLOT(setPortraitOrientation())); connect(ui->actionLandscape, SIGNAL(triggered()), preview, SLOT(setLandscapeOrientation())); connect(ui->actionActualSize, SIGNAL(triggered()), this, SLOT(actualSize())); connect(ui->actionZoomIn, SIGNAL(triggered()), preview, SLOT(zoomIn())); connect(ui->actionZoomOut, SIGNAL(triggered()), preview, SLOT(zoomOut())); connect(ui->actionSinglePage, SIGNAL(triggered()), preview, SLOT(setSinglePageViewMode())); connect(ui->actionFacingPages, SIGNAL(triggered()), preview, SLOT(setFacingPagesViewMode())); connect(ui->actionAllPages, SIGNAL(triggered()), preview, SLOT(setAllPagesViewMode())); connect(ui->actionMainToolbar, SIGNAL(triggered(bool)), this, SLOT(toggleMainToolbar(bool))); connect(ui->actionViewToolbar, SIGNAL(triggered(bool)), this, SLOT(toggleViewToolbar(bool))); connect(ui->actionFontToolbar, SIGNAL(triggered(bool)), this, SLOT(toggleFontToolbar(bool))); connect(ui->actionStatusBar, SIGNAL(triggered(bool)), this, SLOT(toggleStatusBar(bool))); connect(ui->menuToolbars, SIGNAL(aboutToShow()), this, SLOT(updateToolbarMenu())); connect(ui->menuView, SIGNAL(aboutToShow()), this, SLOT(updateToolbarMenu())); connect(preview, SIGNAL(previewChanged()), this, SLOT(previewChanged())); connect(preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paint(QPrinter*))); connect(report, SIGNAL(loaded()), preview, SLOT(updatePreview())); connect(report, SIGNAL(changed()), preview, SLOT(updatePreview())); connect(report, SIGNAL(loaded()), this, SLOT(documentLoaded())); connect(report, SIGNAL(orientationChanged(QPrinter::Orientation)), this, SLOT(orientationChanged(QPrinter::Orientation))); connect(report, SIGNAL(lpiChanged(int)), this, SLOT(lpiChanged(int))); connect(report, SIGNAL(cpiChanged(int)), this, SLOT(cpiChanged(int))); connect(report, SIGNAL(boldChanged(bool)), ui->actionBold, SLOT(setChecked(bool))); connect(report, SIGNAL(fontChanged(QFont)), fontComboBox, SLOT(setCurrentFont(QFont))); QSettings settings; restoreGeometry(settings.value("geometry").toByteArray()); restoreState(settings.value("state").toByteArray()); recentFiles = settings.value("recentFiles").toStringList(); currentFolder = settings.value("currentFolder").toString(); ui->statusBar->setVisible(settings.value("statusBar", true).toBool()); updateRecentFileActions(); zoomTimer = new QTimer(this); connect(zoomTimer, SIGNAL(timeout()), this, SLOT(updateZoom())); connect(preview, SIGNAL(previewChanged()), this, SLOT(updateZoom())); zoomTimer->start(1000); }
//BEGIN class ItemView ItemView::ItemView(ItemDocument * itemDocument, ViewContainer *viewContainer, uint viewAreaId, const char *name) : View(itemDocument, viewContainer, viewAreaId, name) { KActionCollection * ac = actionCollection(); KStdAction::selectAll(itemDocument, SLOT(selectAll()), ac); KStdAction::zoomIn(this, SLOT(zoomIn()), ac); KStdAction::zoomOut(this, SLOT(zoomOut()), ac); KStdAction::actualSize(this, SLOT(actualSize()), ac)->setEnabled(false); KAccel *pAccel = new KAccel(this); pAccel->insert("Cancel", i18n("Cancel"), i18n("Cancel the current operation"), Qt::Key_Escape, itemDocument, SLOT(cancelCurrentOperation())); pAccel->readSettings(); new KAction(i18n("Delete"), "editdelete", Qt::Key_Delete, itemDocument, SLOT(deleteSelection()), ac, "edit_delete"); new KAction(i18n("Export as Image..."), 0, 0, itemDocument, SLOT(exportToImage()), ac, "file_export_image"); //BEGIN Item Alignment actions new KAction(i18n("Align Horizontally"), 0, 0, itemDocument, SLOT(alignHorizontally()), ac, "align_horizontally"); new KAction(i18n("Align Vertically"), 0, 0, itemDocument, SLOT(alignVertically()), ac, "align_vertically"); new KAction(i18n("Distribute Horizontally"), 0, 0, itemDocument, SLOT(distributeHorizontally()), ac, "distribute_horizontally"); new KAction(i18n("Distribute Vertically"), 0, 0, itemDocument, SLOT(distributeVertically()), ac, "distribute_vertically"); //END Item Alignment actions //BEGIN Draw actions KToolBarPopupAction * pa = new KToolBarPopupAction(i18n("Draw"), "paintbrush", 0, 0, 0, ac, "edit_draw"); pa->setDelayed(false); KPopupMenu * m = pa->popupMenu(); m->insertTitle(i18n("Draw")); m->insertItem(KGlobal::iconLoader()->loadIcon("tool_text", KIcon::Small), i18n("Text"), DrawPart::da_text); m->insertItem(KGlobal::iconLoader()->loadIcon("tool_line", KIcon::Small), i18n("Line"), DrawPart::da_line); m->insertItem(KGlobal::iconLoader()->loadIcon("tool_arrow", KIcon::Small), i18n("Arrow"), DrawPart::da_arrow); m->insertItem(KGlobal::iconLoader()->loadIcon("tool_ellipse", KIcon::Small), i18n("Ellipse"), DrawPart::da_ellipse); m->insertItem(KGlobal::iconLoader()->loadIcon("tool_rectangle", KIcon::Small), i18n("Rectangle"), DrawPart::da_rectangle); m->insertItem(KGlobal::iconLoader()->loadIcon("imagegallery", KIcon::Small), i18n("Image"), DrawPart::da_image); connect(m, SIGNAL(activated(int)), itemDocument, SLOT(slotSetDrawAction(int))); //END Draw actions //BEGIN Item Control actions new KAction(i18n("Raise Selection"), "bring_forward", Qt::Key_PageUp, itemDocument, SLOT(raiseZ()), ac, "edit_raise"); new KAction(i18n("Lower Selection"), "send_backward", Qt::Key_PageDown, itemDocument, SLOT(lowerZ()), ac, "edit_lower"); //END Item Control actions KAction * na = new KAction("", 0, 0, 0, 0, ac, "null_action"); na->setEnabled(false); setXMLFile("ktechlabitemviewui.rc"); m_pUpdateStatusTmr = new QTimer(this); connect(m_pUpdateStatusTmr, SIGNAL(timeout()), this, SLOT(updateStatus())); connect(this, SIGNAL(unfocused()), this, SLOT(stopUpdatingStatus())); m_pDragItem = 0l; p_itemDocument = itemDocument; m_zoomLevel = 1.; m_CVBEditor = new CVBEditor(p_itemDocument->canvas(), this, "cvbEditor"); m_CVBEditor->setLineWidth(1); connect(m_CVBEditor, SIGNAL(horizontalSliderReleased()), itemDocument, SLOT(requestCanvasResize())); connect(m_CVBEditor, SIGNAL(verticalSliderReleased()), itemDocument, SLOT(requestCanvasResize())); m_layout->insertWidget(0, m_CVBEditor); setAcceptDrops(true); setFocusWidget(m_CVBEditor->viewport()); }